Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/noesya/faceted_search
https://github.com/noesya/faceted_search
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/noesya/faceted_search
- Owner: noesya
- License: mit
- Created: 2019-02-22T08:03:42.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-04-04T18:31:22.000Z (almost 2 years ago)
- Last Synced: 2024-11-18T12:09:34.822Z (2 months ago)
- Language: Ruby
- Size: 223 KB
- Stars: 5
- Watchers: 4
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: MIT-LICENSE
Awesome Lists containing this project
README
# FacetedSearch
All you need to create a faceted search, as simple as possible[![Maintainability](https://api.codeclimate.com/v1/badges/70579009d11cfa0d7cac/maintainability)](https://codeclimate.com/github/lespoupeesrusses/faceted_search/maintainability)
## Installation
Add this line to your application's Gemfile:```ruby
gem 'faceted_search'
```And then execute:
```bash
$ bundle
```Or install it yourself as:
```bash
$ gem install faceted_search
```## Getting started
Add Bootstrap and Font Awesome to your `app/assets/stylesheets/application.sass`
```
@import 'bootstrap'
@import 'font-awesome-sprockets'
@import 'font-awesome'
```Create a model defining your facets:
class Item::Facets < FacetedSearch::Facets
def initialize(params)
super
@model = Item.all
filter_with_text :title
filter_with_list :products, {
find_by: :title,
habtm: true
}
filter_with_list :kinds, {
habtm: true
}
filter_with_list :style, {
habtm: false
}
filter_with_tree :categories, {
habtm: true,
children_scope: Proc.new { |children|
children.order(:title)
}
}
filter_with_boolean :active
# Other tree option, shows all values
# filter_with_full_tree :categories, {
# habtm: true,
# children_scope: Proc.new { |children|
# children.order(:title)
# }
# }# Other option, with searchable (SEO) categories
filter_with_full_tree :categories, {
habtm: true,
searchable: true,
path_pattern: Proc.new { |category_id|
Rails.application.routes.url_helpers.category_path(category_id)
}
}# Filter with range input
filter_with_range :distance, {
min: 10,
max: 200,
step: 10,
default_value: 50,
hide_in_selected: true
}
end
endWarning: do not provide model with order, as it messes with the distinct used in the facet computations.
In your controller, use it:
@facets = Item::Facets.new params[:facets]
@items = @facets.results.order(:title).page params[:page]In your view, do something like that (with bootstrap):
<%= render 'faceted_search/facets', facets: @facets %>
<% @items.each do |item| %>
<%= item %>
Products: <%= item.products.join(', ') %>
Categories: <%= item.categories.join(', ') %>
Kinds: <%= item.kinds.join(', ') %>
<% end %>
If you need, you can add an anchor to the links:
<%= render 'faceted_search/facets', facets: @facets, anchor: "#identifier" %>
## Note about full tree
Tagging must be logical in order to use filter_with_full_tree.
With these categories:Blues
Chicago blues
Delta Blues
Memphis Blues
Jazz
Free jazz
Swing
Latin jazzIf something is tagged as "Delta blues", it MUST be tagged as "Blues" as well.
Otherwise, it creates very odd comportments (selecting "Blues" does not show the object, whereas it is "Delta blues").
There is no inference whatsoever, so the data MUST be clean.The HTML code is ready for [Nestable2](https://github.com/RamonSmit/Nestable2) implementation. If you want to use this library, add the [CSS](https://github.com/RamonSmit/Nestable2/blob/master/dist/jquery.nestable.min.css) & [JS](https://github.com/RamonSmit/Nestable2/blob/master/dist/jquery.nestable.min.js) in your `vendor` folder and import them in `application.sass` & `application.js`.
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).