concept default in category solr

appears as: default, default, defaults, The defaults, The default, defaults
Solr in Action

This is an excerpt from Manning's book Solr in Action.

Solr’s relevancy scores are based upon the Similarity class, which can be defined on a per-field basis in Solr’s schema.xml (discussed further in chapter 5). Similarity is a Java class that defines how a relevancy score is calculated based upon the results of a query. While you can choose from multiple Similarity classes, or even write your own, it is important to understand Solr’s default Similarity implementation and the theory behind why it works so well.

By default, Solr uses Lucene’s (appropriately named) DefaultSimilarity class, which uses a two-pass model to calculate similarity. First, it makes use of a Boolean model (described in section 3.1) to filter out any documents that do not match the customer’s query. Then it uses a vector space model for scoring and drawing the query as a vector, as well as an additional vector for each document. The similarity score for each document is based upon the cosine between the query vector and that document’s vector, as depicted in figure 3.6.

In this example, the query would be expanded to search for timothy and potter in the firstName and lastName fields, and for solr and in and action in the itemName and companyName fields. It would also search for the phrase "big data" in the default (text) field. Had the query attempted to search across any other fields except for the who and what aliased fields, however, the query would not have worked. For example, consider the following query:

q=+who:(timothy potter) +what:(solr in action) +firstName:timothy
!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":3},{\"line\":0,\"ch\":7}],[{\"line\":0,\"ch\":25},{\"line\":0,\"ch\":30}]]"}
!@%STYLE%@!

In this example, the query would not interpret firstName as a field, but would instead search for the full phrase in the default (text) field as a keyword. Thus, unless you have a document which matches the search text:"firstName:timothy", this query will return zero results, protecting your search engine from unauthorized field access. If you have this need to restrict the accessible fields in your search application, the eDisMax query parser should have you covered.

In listing 7.3, you will see two sections added to a search component: an invariants section and a defaults section. defaults are values that will be set if no overriding value is passed in on the Solr request URL. This can be useful when you want to enforce safe default settings (such as a q=*:* on the query search component so that you do not encounter an exception or receive no results on blank searches).

The invariants section works like the defaults section, except that invariant parameters can’t be overridden by the Solr request URL. This can be useful for enforcing some kind of security filter or, in the case of listing 7.3, ensuring that all requests are always for 25 results (rows=25) and that a default field for keyword searches is defined (df=content_field). You will see many request handlers and search components defining their configurations using defaults and invariants like this in solrconfig.xml.

Figure 8.8. By default, after filtering upon a facet, the facet values that are returned no longer include the documents that were filtered out. This is problematic if you want to allow your user to select multiple values to include in the search, as they’ll never be able to OR any additional facet filters for the values because they’re no longer visible as options.