[![Build Status](https://travis-ci.org/elevatorup/solidus_searchkick.svg?branch=master)](https://travis-ci.org/elevatorup/solidus_searchkick) [![Code Climate](https://codeclimate.com/github/elevatorup/solidus_searchkick/badges/gpa.svg)](https://codeclimate.com/github/elevatorup/solidus_searchkick) [![Test Coverage](https://codeclimate.com/github/elevatorup/solidus_searchkick/badges/coverage.svg)](https://codeclimate.com/github/elevatorup/solidus_searchkick/coverage) Solidus + Searchkick =============== Add [Elasticsearch](http://elastic.co) goodies to Solidus, powered by [searchkick](http://searchkick.org). Features -------- * Full search (keyword, in_taxon) * Taxons Aggregations (aggs) * Search Autocomplete ([Typeahead](https://twitter.github.io/typeahead.js/)) Installation ------------ Add searchkick and solidus_searchkick to your Gemfile: ```ruby gem 'searchkick' gem 'solidus_searchkick' ``` Bundle your dependencies and run the installation generator: ```shell bundle bundle exec rails g solidus_searchkick:install ``` Installing solidus_searchkick will copy over a new `spree/shared/_filters.html.erb` template. This includes a few minor changes to the default template, mainly changing a few `search` params to `filter` params to work nicely with solidus_searchkick and elasticsearch. [Install elasticsearch](https://www.elastic.co/downloads/elasticsearch) Implementation ------------- Initially, you are started with a very basic filtering system which includes a price filter in order to show how the filtering works within elasticsearch. In order to add more filtering or change the price filtering, the following steps will need to be taken. 1. Copy the `Spree::Core::SearchkickFilters` file from this gem and place it in `lib/spree/core/` 2. Add it to the config load path, or require it in an initializer, e.g... ``` # config/initializers/spree.rb require 'spree/core/searchkick_filters' ``` 3. Modify SearchKickFilters as needed. The `conds` for `SearchkickFilters` are similar to the `ProductFilters` in the default version of spree. Although the first parameters of each is still the label, the second item is the ElasticSerach DSL that will be used for that filter, eg... `{ range: { price: { lt: 1 } } }` Autocomplete ------------- SolidusSearchkick provides autocomplete for the `name` field of your products. In order to get this working, all you need to do is add the following lines to the corresponding files: application.js ``` //= require spree/frontend/typeahead.bundle //= require spree/frontend/solidus_searchkick ``` application.css ``` *= require spree/frontend/solidus_searchkick ``` After that, automplete should now be working in the search box. Advanced Autocomplete ------------- Documentation Coming Soon Options ------------- Order Fields (example of overriding fields) Documentation ------------- By default, only the `Spree::Product` class is indexed. The following items are indexed by default: * name * description * available? (indexed as `active`) * price (needed in order to return products that have price != nil) * currency * sku * orders.complete.count (indexed as `conversions`) * taxon_ids * taxon_names In order to control what data is indexed, override `Spree::Product#search_data` method. Call `Spree::Product.reindex` after changing this method. Testing ------- First bundle your dependencies, then run `rake`. `rake` will default to building the dummy app if it does not exist, then it will run specs. The dummy app can be regenerated by using `rake test_app`. ```shell bundle bundle exec rake ``` When testing your applications integration with this extension you may use it's factories. Simply add this require statement to your spec_helper: ```ruby require 'solidus_searchkick/factories' ``` Copyright (c) 2016 Jim Smith, released under the New BSD License TODO: Add in information about sorting (maybe even add in default sorting, and sorting template, along with sorting javascript)