|Fig 1: Solr Query Architecture|
A user query for "climate change" will result in a scored relevancy match against this document.
The user query against the Solr server is very simple:
q=climate changeSolr will augment this query in two stages:
- The Request Handler will add additional meta-data about how the query should be executed. Notions of relevance, number of rows returned, if highlighting should be used, the fields to query and return, are all specified here.
- The query then becomes:
q=climate change&defType=xml&wt=xml&fl=id title text&qf=title^2 text&rows=10&pf=title^2 text&ps=5&echoParams=all&hl=true&hl.fl=title text&debug=true
- The Query Analyzer will perform a linguistic analysis of the user query. Tokenization, pattern filtering, stemming, synonyms, etc are all specified here.
- The query then becomes:
q=(+((DisjunctionMaxQuery((text:climate | title:climate^2.0 | speaker:climate)) DisjunctionMaxQuery((text:change | title:change^2.0 | speaker:change)))~2) DisjunctionMaxQuery((title:"(greenhouse ghg climate climate deforestation pollution greenhouse carbon co2 methane nitrous n2o hydroflurocarbons hfcs perfluorocarbons pfcs sulfur sf6) (gas change shift gasses dioxide oxide hexafluoride)"~5^2.0 | text:"(greenhouse ghg climate climate deforestation pollution greenhouse carbon co2 methane nitrous n2o hydroflurocarbons hfcs perfluorocarbons pfcs sulfur sf6) (gas change shift gasses dioxide oxide hexafluoride)"~5)))/no_coord&defType=xml&wt=xml&fl=id title text&qf=title^2 text&rows=10&pf=title^2 text&ps=5&echoParams=all&hl=true&hl.fl=title text&debug=true
This is a powerful design technique for abstracting complexity away from the user query while creating very complex and specific queries to find relevant documents.
The first augmentation stage is controlled by the request handler.
Request handlers are defined within solrconfig.xml:
This request handler creates the node entitled "Augmented User Query 1". So here's a major benefit to the configuration files already. The user (or the application) didn't have to append all this information to the query string. It's appended by default to each query.
The query is next augmented by each field that is being searched.
Within the schema.xml file, I have a field defined for text:
Note that in the configuration file above, there are two analyzers specified for the field called "text_doc". One analyzer is for the document text being indexed during the ingestion phase. The other analyzer is for the user query text that triggers the search (for the indexed text). In both cases, the configuration is largely identical, except for the use of synonyms.
This is an important concept to grasp. If the indexed content and the user query are both treated by (nearly) identical analyzers, it's going to be a lot easier to find relevant text. As a counter example, imagine having to design a tokenization pipeline for user queries against content indexed by multiple, unknown configurations. If you use aggresive stemming and wildcards to boost recall, this will come at the expense of precision.
- [YouTube, 5:54] Apache Solr: Complex Query Format