Very naive full text search implementation for ActiveRecord. Orders results by relevance. Works like this:
The contents of all the specified fields are stored in a text field.
Every word in a search query is matched against that text field, in SQL using like.
The returned results are then re-ordered based on how well they match the query and the words the query is made up of.
It Doesn't Scale, much. For situations when more ambitious search solutions are overkill.
gem install naive-search
Run the migration generator on your model, like so:
rails generate naive_search:migration Person
Run it. Then use as follows:
class Person < ActiveRecord::Base naive_search_on :name, :surname, :description end
This makes the specified fields searchable like so:
Person.search_for 'my query'
Optionally, you can specify the order and limit of results to return from the database:
class Person < ActiveRecord::Base naive_search_on :name, :surname, :description, :order => "id desc", :limit => 20 end
Note that the search results will still be re-ordered based on fuzzy “relevance”, this simply specifies how many results to retrieve from the database, and in which order. Also note that small limits combined with broad searches yields terrible results.
This project uses MIT-LICENSE.