Skip to content
wvanbergen edited this page Aug 16, 2010 · 28 revisions

The query language is simple, but supports several constructs. The query language parser will split the search string into keywords. It will build a query that matches any record that has at least one occurrence of all of these keywords (using the SQL AND operator) in any of the search fields (using the SQL OR operator. The query language supports some operators to alter this behavior.

The searching is performed with the SQL LIKE operator, or ILIKE in PostgreSQL. Searching therefore is case insensitive, but this can be different in some DBMS configurations however.

Simple keywords search

In these example, the name and description field of the Person model are search by calling searchable_on :name, :description.

Single keyword. scoped_search:


SELECT * FROM people
WHERE (name LIKE ‘% scoped_search%’ OR description LIKE ‘% scoped_search%’)

Multiple keywords. Willem Wes scoped_search:


SELECT * FROM people
WHERE (name LIKEWillem’ OR description LIKEWillem’)
AND (name LIKEWes’ OR description LIKEWes’)
AND (name LIKEscoped_search’ OR description LIKEscoped_search’)

You can create phrases including spaces by using quotes. "Great plugin":


SELECT * FROM people
WHERE (name LIKEGreat plugin’ OR description LIKEGreat plugin’)

Operators

The query language supports the OR and NOT operator.

Date queries

Clone this wiki locally