Sunspot is a Ruby library for expressive, powerful interaction with the Solr search engine. Sunspot is built on top of the RSolr library, which provides a low-level interface for Solr interaction; Sunspot provides a simple, intuitive, expressive DSL backed by powerful features for indexing objects and searching for them.
Here is an example to implement sunspot solr in rails applications.
Install Gem
Add these lines into your Gemfile
Now run bundle install
.
Generate a default configuration file:
Start sunspot solr
bundle exec rake sunspot:solr:start # or sunspot:solr:run to start in foreground
.
Making objects to search by solr
Solr makes indexes for objects to perform search. To do this follow these steps:
Add a searchable
block to the objects you wish to index.
Re-index solr
When you make any changes in the searchable
block then run the following command bundle exec rake sunspot:solr:reindex
Searching
Customizing search
You can modify search by these following steps:
- Add
with
into search block to apply some conditions. - Add
order_by
into search block to order searched results. - You can paginate search results by adding
paginate
into search block.
For more details please click here. Enjoy !!!