Skip to content

javereec/spree_elasticsearch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

75 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spree Elasticsearch

This extension uses elasticsearch-ruby for integration of Elasticsearch with Spree. This is preconfigured for a certain use case, but by all means override where necessary.

To understand what is going on, you should first learn about Elasticsearch. Some great resources:

Installation

Add spree_elasticsearch to your Gemfile:

gem 'spree_elasticsearch', github: 'javereec/spree_elasticsearch', branch: '3-0-stable'

Bundle your dependencies and run the installation generator:

bundle
touch config/elasticsearch.yml # temporary install workaround
bundle exec rails g spree_elasticsearch:install

Edit the file in config/elasticsearch.yml to match your configuration.

Edit the spree initializer in config/initializers/spree.rb and use the elasticsearch searcher.

Spree.config do |config|
  config.searcher_class = Spree::Search::Elasticsearch
end

Create a decorator for Product model to implement callbacks and update the index. This gem doesn't implement a default method as there are several options. For sites with lots of products and changes to these products, the recommended way would be to use a sidekiq task. Check the elasticsearch-rails documentation for different options.

For example using the model callbacks

module Spree
  Product.class_eval do
    include Elasticsearch::Model::Callbacks
  end
end

Elasticsearch

Elasticsearch is very easy to install. Get and unzip elasticsearch 1.x.x: http://www.elasticsearch.org/download

Start:

bin/elasticsearch

Execute following to drop index (all) and have a fresh start:

curl -XDELETE 'http://localhost:9200'

Elasticsearch has a nifty plugin, called Marvel, you can install to view the status of the cluster, but which can also serve as a tool to debug the commands you're running against the cluser. This tool is free for development purposes, but requires a license for production environments. You can install it by executing the following.

bin/plugin -i elasticsearch/marvel/latest

Testing

Be sure to bundle your dependencies and then create a dummy test app for the specs to run against.

bundle
bundle exec rake test_app
bundle exec rspec spec

When testing your applications integration with this extension you may use it's factories. Simply add this require statement to your spec_helper:

require 'spree_elasticsearch/factories'

Please note that these test require an actual instance of Elasticsearch. ] A helper product decorator class is includes to update the index when saving a product.

Copyright (c) 2014-2015 Jan Vereecken, released under the New BSD License

About

Integration with Elasticsearch for the Spree framework.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published