macool / pig_search

A Rails engine that adds search functionality to the Pig CMS using Elasticsearch

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pig_search

pig_search is a Rails engine that adds search functionality to the Pig CMS.

Setup

Add pig_search to your Gemfile:

gem 'pig_search', git: 'https://github.com/yoomee/pig_search.git', tag: '0.0.1'

Mount the engine on a suitable path by adding it to your config/routes.rb file above where you mount the Pig engine:

mount PigSearch::Engine => "/search"

Create the elasticsearch index and add any existing Pig content packages with:

bundle exec rake elasticsearch:import:content_packages

Adding custom models to index

By default pig_search only indexes the Pig::ContentPackage models, and specifically only those that are published.

To make your model searchable you must include the PigSearch::Searchable concern and add result_title and result_path instance methods to your model. There is also an optional result_tags method you can add if your model has tags. For example:

include PigSearch::Searchable

private
# return a string of how your object will appear in search results
def result_title
  name
end

# return a path to your object that can be linked from search results
def result_path
  Pig::Engine.routes.url_helpers.content_package_path(self)
end

# return an array of strings
def result_tags
  taxonomy.collect(&:name)
end

By default the concern will only index models that respond true to calls to published?. For simplicity you might want to add this method and always return true, alternatively you can override perform_document_index and update_document_index with your own indexing logic.

Deploy

Ensure you have set the env variable ELASTICSEARCH_URL to the url of your elasticsearch installation.

On Heroku this url can be found on the settings page of the add-on you have chosen for Elasticsearch.

About

A Rails engine that adds search functionality to the Pig CMS using Elasticsearch

License:MIT License


Languages

Language:Ruby 73.0%Language:HTML 19.2%Language:CSS 4.2%Language:JavaScript 3.6%