13.05.2014 Views

apache-solr-ref-guide-4.6.pdf

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Other Schema Elements<br />

This section describes several other important elements of schema.xml.<br />

Unique Key<br />

The uniqueKey element specifies which field is a unique identifier for documents. Although uniqueKey is not required, it is nearly always<br />

warranted by your application design. For example, uniqueKey should be used if you will ever update a document in the index.<br />

You can define the unique key field by naming it:<br />

id<br />

Starting with Solr 4, schema defaults and copyFields cannot be used to populate the uniqueKey field. You also can't use<br />

UUIDUpdateProcessorFactory to have uniqueKey values generated automatically.<br />

Further, the operation will fail if the uniqueKey field is used, but is multivalued (or inherits the multivalueness from the fieldtype). However,<br />

uniqueKey will continue to work, as long as the field is properly used.<br />

Default Search Field<br />

If you are using the Lucene query parser, queries that don't specify a field name will use the defaultSearchField. The DisMax and Extended<br />

DisMax query parsers do not use this value.<br />

Use of the defaultSearchField element is deprecated in Solr versions 3.6 and higher. Instead, you should use the df<br />

request parameter. At some point, the defaultSearchField element may be removed.<br />

For more information about query parsers, see the section on Query Syntax and Parsing.<br />

Query Parser Default Operator<br />

In queries with multiple terms, Solr can either return results where all conditions are met or where one or more conditions are met. The operator<br />

controls this behavior. An operator of AND means that all conditions must be fulfilled, while an operator of OR means that one or more conditions<br />

must be true.<br />

In schema.xml, the <strong>solr</strong>QueryParser element controls what operator is used if an operator is not specified in the query. The default operator<br />

setting only applies to the Lucene query parser, not the DisMax or Extended DisMax query parsers, which internally hard-code their operators to<br />

OR.<br />

The query parser default operator parameter has been deprecated in Solr versions 3.6 and higher. You are instead encouraged<br />

to specify the query parser q.op parameter in your request handler.<br />

Similarity<br />

Similarity is a Lucene class used to score a document in searching. This class can be changed in order to provide a more custom sorting. With<br />

Solr 4, you can configure a different similarity for each field, meaning that scoring a document will differ depending on what's in each field.<br />

However, you can still configure a global similarity is configured in the schema.xml file, where an implicit instance of<br />

DefaultSimilarityFactory is used.<br />

A global declaration can be used to specify a custom similarity implementation that you want Solr to use when dealing with your<br />

index. A similarity can be specified either by <strong>ref</strong>erring directly to the name of a class with a no-argument constructor:<br />

<br />

or by <strong>ref</strong>erencing a SimilarityFactory implementation, which may take optional initialization parameters:<br />

Apache Solr Reference Guide 4.6<br />

40

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!