QueryParser
You’ve now been introduced to all the different types of queries
available in Ferret, and you’ve learned how to build different queries by
hand. Some of it probably seems like a lot of work and it’s certainly not
something you’d ask a user to do. Luckily, we can leave most of the work
to the Ferret QueryParser. You’ve
already seen many examples of the Ferret Query Language (FQL) in the
previous section (Building
Queries”),
and you’ll have noticed that most of the queries you can build in code can
be described much more easily in FQL. In this section, we’ll talk about
setting up the QueryParser, and then
we’ll go into more detail about FQL.
Setting Up the QueryParser
The QueryParser has a number of
parameters, as shown in Table 4-1.
Table 4-1. QueryParser parameters
| Parameter | Default | Short description |
|---|---|---|
:default_field
|
:*
| The default field to be searched; it can also be an array. |
:analyzer
|
StandardAnalyzer
| Analyzer used by the query parser to parse query terms. |
:wild_card_downcase
|
true
| Specifies whether wildcard queries should be downcased or not, since they are not analyzed by the parser. |
:fields
|
[]
| Lets the query parser know what fields are available for
searching, particularly when the :* is specified as the search
field. |
:validate_fields
|
false
| Set to true if you
want an exception to be raised if there is an attempt to search
a nonexistent field. |
:or_default
|
true
| Use OR as the default
Boolean operator. |
:default_slop
| 0 | Default slop to use in
PhraseQueries. |
:handle_parser_errors ... |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access