Quest
Very naive full text search implementation for ActiveRecord based on naive-search by Tomas Jogin (github.com/tjogin). 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.
Installation
gem install quest_search
Usage
Run the migration generator on your model, like so:
rails generate quest_search:migration Person
Run it. Then use as follows:
class Person < ActiveRecord::Base
quest_search_on :name, :surname, :description
end
This makes the specified fields searchable like so:
Person.quest_search_for 'my query'
Optionally, you can specify the order and limit of results to return from the database:
class Person < ActiveRecord::Base
quest_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.
License
This project uses MIT-LICENSE.