-
Notifications
You must be signed in to change notification settings - Fork 79
Query language
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.
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 LIKE ‘Willem’ OR description LIKE ‘Willem’)
AND (name LIKE ‘Wes’ OR description LIKE ‘Wes’)
AND (name LIKE ‘scoped_search’ OR description LIKE ‘scoped_search’)
You can create phrases including spaces by using quotes. "Great plugin"
:
SELECT * FROM people
WHERE (name LIKE ‘Great plugin’ OR description LIKE ‘Great plugin’)
The query language supports the OR and NOT operator.