Query parsers and local-params

A query parser parses a string into an internal Lucene query object, potentially considering request parameters and so-called local-params. Only a few parsers actually do real string parsing; some parsers—like those for geospatial—don't even use the query string. The default query parser is named lucene, and it has a special leading syntax to switch the parser to another and/or to specify parameters. Here's an example using the dismax parser along with two local-params and a query string of billy corgan:

{!dismax qf="a_name^2 a_alias" tie=0.1}billy corgan

Note

It's not common to see this syntax in the user query, q, since its parser is conveniently set via defType.

There are a few things to know about the local-params syntax:

  • The leading query parser name (for example, DisMax) is optional. Without it, the parser remains as lucene. Furthermore, this syntax is a shortcut to put the query parser name in the type local-param.
  • Usually, a query parser treats local-params as an override to request parameters in the URL.
  • A parameter value can refer to a request parameter via a leading $, for example, v=$qq. This is useful to decompose a larger query, and to define parts of the query in different places between the request and the request handler's configuration.
  • The special parameter v can be used to hold the query string as an alternative to it following }. The query() function query requires this approach. That will be shown later.
  • A parameter value doesn't have to be quoted if there are no spaces. There wasn't any for the tie parameter in the preceding example.

For an interesting example, see the subquery syntax later in the Subqueries section.

Solr includes quite a few different query parsers. In the next section, you'll learn all about lucene. To process user queries, you should typically use dismax or edismax (short for extended-DisMax), which are described afterwards. The other query parsers are for special things, such as geospatial search, also described at the end of this chapter. This book only explores the most useful parsers; for further information, see https://cwiki.apache.org/confluence/display/solr/Query+Syntax+and+Parsing.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.105.239