Syntax help
You can use special query syntax to modify your search query.
Phrase search: "..."
It is possible to do a phrase search by putting the terms in "..."
. That way
the exact order of the terms will be taken into account. A query for "Paul Baum"
would return all records on the artist Paul Baum. While Paul Baum
(without quotation
marks) would find both terms regardless of order. E.g., it would also find Paul Klee,
Baum im Garten
.
Wildcard search: *
and ?
It is possible to mask parts of a word with *
or ?
. This will include
all possible extensions of the word. The wildcard character can be placed at any position in the
word. A query for Sun*
would find Sun
, Sunflower
,
Sundown
etc., sun*e
would find sunrise
and sunshine
,
and *rise
would find sunrise
and enterprise
.
While the *
can stand for an arbitrary number of characters (including zero), the
?
replaces exactly one character. This is particularly useful if you're uncertain
about one of the letters in your query term. For instance, you're searching for records of van
Gogh, but aren't sure about the spelling of his first name. Just enter Vin?ent van Gogh
and the question mark will match the missing c
.
Fuzzy search: ~
It is possible to flag a word with ~
to include similar words in the query. This is
particularly useful if you're unsure about the spelling of a term or name. The ~
character will be positioned at the end of the word you want to search fuzzily. Note that the
~
doesn't replace parts of the word like the *
does. E.g., a query for
Jaqueometti~
would find the artist Giacometti
, Gaugin~
would also return records for Gauguin
.
Boosting: ^n
It is possible to attach ^n
at the end of a word to influence ranking.
n is an arbitrary (positive) number and only affects the ranking of the results list,
not the number of the results returned. A query for gold OR silver^12
will prefer
(= rank higher) all records which include silver
, but nevertheless return those
that match gold
or gold and silver
.
Refer to the Ferret::QueryParser class documentation or the Apache Lucene - Query Parser Syntax documentation for the gory details. The Wikipedia article Levenshtein distance has more information on the similarity measure used in Fuzzy search.
Boolean operators
It is possible to combine search clauses using the Boolean operators AND
, OR
,
and AND NOT
. They have the following meaning:
AND
- Both search clauses must match.
OR
- One of the search clauses must match, but it is also possible that both of them match.
AND NOT
- The first search clause must match, but the second must not match.
For example, a query for artist = Picasso AND title = Stier
would find all records of Bull
images by Picasso
. Whereas artist = Picasso
AND NOT title = Stier
would find all images by Picasso
except his Bull
images. On the other hand, artist = Picasso OR title =
Stier
would find all images by Picasso
and
all Bull
images, regardless of the artist who painted them.
However, if you want to formulate a more sophisticated query that uses more than one operator you have to
consider in what order they will be applied. The general order of precedence is as follows:
OR
> AND NOT
> AND
That means, whenever you use a combination of them, OR
will be evaluated before AND NOT
which in turn will be evaluated before AND
. Examples:
artist = Picasso AND title = Stier AND title = Pferd
- Finds all images by
Picasso
that show bothBulls
andHorses
. artist = Picasso AND title = Stier OR title = Pferd
- Finds all images by
Picasso
that show eitherBulls
orHorses
, or both. artist = Picasso AND title = Stier AND NOT title = Pferd
- Finds all images by
Picasso
that showBulls
, but noHorses
. artist = Picasso OR artist = van Gogh AND title = Stier OR title = Kuh
- Finds all images by
Picasso
or byvan Gogh
that show eitherBulls
orCows
, or both.