[英]Faceted filtering using Postgres & Rails
Use ThinkingSphinx or Apache Solr - both have built-in faceting. 使用ThinkingSphinx或Apache Solr-两者都有内置的构面。 You can roll your own (as shown in another fine answer) but my experience says that you're better off adding a real search engine and taking advantage of the faceting feature there, as well as the other search features. 您可以自己滚动(如另一个很好的答案所示),但我的经验表明,最好添加一个真正的搜索引擎,并利用那里的构面功能以及其他搜索功能。 I use Solr for all new development, but ThinkingSphinx is generally a little easier to set up and it has new features (main one being continuous indexing) that make it a good contender. 我将Solr用于所有新开发,但ThoughtSphinx通常更易于设置,并且具有新功能(主要功能是连续索引),使其成为一个有力的竞争者。
I think Rails is powerful enough to implement simple form filters like shown above. 我认为Rails足够强大,可以实现如上所述的简单表单过滤器。
You just need to have a good data model and then it will be easy as pie. 您只需要拥有一个良好的数据模型,便可以轻松实现。
Example: 例:
To simplify the form creation though you can use simple_form , but it is definitely optional. 为了简化表单创建,尽管可以使用simple_form ,但是它绝对是可选的。
select
(
select json_object_agg(COALESCE(brand_id, 'null'), cnt)
from (
select brand_id, COUNT(*) as cnt
from unnest(array_agg(brand_id)) as tmp(brand_id)
group by brand_id
) ttt
),
min(price) as price_min,
max(price) as price_max
from product
WHERE is_visible = true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.