For one of my pet project based on Ruby on Rails, I’ve decided to implement Apache Solr as full-text search engine.
You can find a lot of tutorials with 5 min install and run, but:
None from Google first page results worked for me, so I’ve decided to write my own tutorial.
I’m using Rails 5.2.0.rc1 at this tutorial.
So first problem was about specifying github at Gemfile, because otherwise installer script fails:
Let’s add another gems too:
Great, now let’s run installer. This creates sunspot.yml file and config directory.
Let’s modify this file:
Of course, you can run local solar instance with this command, like described in tutorials:
But I prefer isolate Solr installation from my development environment, and use Docker for that stuff.
You can find Solr Docker images here.
So, let’s install and run Apache Solr as a Docker container:
Excellent! Let’s move ahead and add new core
Now, you can open http://localhost:8983 in your browser, and control Apache Solr via Web UI:
Now let’s make our post model searchable:
Time to add some seeds:
Good, let’s reindex our data:
Now we can perform some search requests to our Solr instance:
Great, last step - add controller action, which get param from request and perform search:
Our posts page:
And search results page: