Moving from Lucene to Solr
Support for the Lucene search engine is no longer included in Sitecore 9.3, and later. You can use the Solr search engine. Solr is installed and configured by default in a Sitecore installation.
This topic describes some of the differences you will see when you move from Lucene to Solr.
The LINQ API
Some queries with the LINQ API give slightly different results in Lucene and Solr.
StartsWith
The Solr implementation of the StartsWith LINQ method matches values at the beginning of each word, while Lucene matches the whole field value.
LINQ query |
Solr results |
Lucene result |
---|---|---|
|
world world is great hello world |
world world is great |
EndsWith
The Solr implementation of the EndsWith LINQ method matches values at the end of each word, while Lucene matches the whole field value.
LINQ query |
Solr results |
Lucene results |
---|---|---|
|
world hello world world is great |
world hello world |
Case-sensitive string comparison
When Solr searches plain text field types (for example string or text), it usually is case-sensitive. The exception is some system fields, for example _fullpath
or _name
).
LINQ query |
Solr results |
Lucene results |
---|---|---|
|
Does not return items based on “Sample Item” template |
Returns items based on “Sample Item” template |
Item level boosting
Item level boosting is not supported by the Solr search provider (starting from Sitecore 9.1.0). The Solr release notes state that index time boosting is no longer supported for Solr 7, and later. See details at https://lucene.apache.org/solr/guide/7_2/major-changes-in-solr-7.html. This means that for Sitecore 9.1.0 or higher, index-time boosting is not supported for either item or field boosting.
See also the Sitecore Solr compatibility table.
Configuration differences
There are some differences in the way you configure the Solr search provider and the Lucene search provider. The transition is effortless for the built-in Sitecore fields, but you must be aware of the differences if you add your own fields to the configuration.
Field types
Solr supports more field types than Lucene. In Lucene, a field is either string or numeric, but while Solr supports more specific types such as solr.DatePointField, solr.FloatPointField, and solr.TextField.
For example, if you have a checkbox field and you do not have a Boolean converter (the bool.ToString() is the value that is sent to the index) and if you use this field in a facet query, you get 0
and 1
as category names in Lucene, while in Solr you get false
and true
.
The official Solr documentation has more information.
Solr schema
In Lucene you can control field configurations when you add them to the index, but Solr requires that you provide the schema before you start adding any documents.
Sitecore has the Populate Solr managed schema tool in the control panel that lets you upload the schema required by Sitecore to run with Solr. You must use this tool at least one time before you start indexing. If you use the Sitecore Installation Framework, the scheme is populated during deployment.
Therefore, all schema related configurations have been removed from the field map configuration. You no longer need to set values in field map for every field or field type. Instead you match your field/field type in the field map to one of the fields/dynamic fields in the Solr schema.
Set the returnType attribute in your field/field type configuration in the field map to one of the typeMatch nodes defined in Solr field map:
There is a walk-through with more information about setting up Solr.
Field name translation in Solr
Every typeMatch node corresponds to one of the dynamic fields defined in the Solr schema by using a pattern applied to the field name. The fieldNameFormat attribute sets this pattern. At indexing, the field name is formatted according to the pattern. For example, in the example above, the title
field is formatted as title_s
and the created
field is formatted as created_tdt
, based on the values of fieldNamFormat attributes.
When indexing. Solr matches field names against field defined in the schema. If if finds a match, Solr applies the configuration of that field. If it does not find a math, Solr then matches the field name against the dynamic fields pattern:
In the example here, the dynamic fields match. As these fields are of the string and pdate type, respectively, Solr applies the configuration of these types to the added fields:
Normally, the dynamic fields that the Populate Solr managed schema tool provides are all the field configurations that you need. However, in very rare situations, you might need to add a field or a dynamic field in the schema with a different configuration than the existing one. One way you can do this is to modify the schema directly in Solr, but be aware that you lose changes if you run the schema populate tool later. Instead, we recommend that you modify the contentSearch.PopulateSolrSchema pipeline by injecting a new processor that does the Solr schema customization.
Using Solr field name resolution has more information.
Our general recommendation is that you only change the schema if the typeMatch configuration is not flexible enough.