Reputation: 4732
What is the best way to implement a faceted search/filter UI using Postgres as the backend and Ruby on Rails as the front end? Example of this is below:
Upvotes: 0
Views: 1949
Reputation: 1
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
Upvotes: 0
Reputation: 3031
Use ThinkingSphinx or Apache Solr - both have built-in faceting. 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.
Upvotes: 2
Reputation: 4400
I think Rails is powerful enough to implement simple form filters like shown above.
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.
Upvotes: 0