Search

Apache Solr autoGeneratePhraseQueries and Schema

In the Solr schema file, the XML tag schema contains two attributes: name and version.

				
					<?xml version="1.0" encoding="UTF-8"?>
<schema name="my_schema" version="1.5">
	<field name="_version_" type="long" indexed="true" stored="true" />
	<field name="name" type="string" indexed="true" stored="false"/>
        . . . 
</schema>
				
			

You may think the schema version is an attribute useful for the admin to track the schema updates but you need to be aware that Solr adds some logic based on this value. Indeed, as you can see in the example below (GitHub link), the schema version is used to determine the default of the parameter autoGeneratePhraseQueries. Logic introduced with this Jira issue.

				
					if (schema.getVersion() > 1.3F) {
  autoGeneratePhraseQueries = false;
} else {
  autoGeneratePhraseQueries = true;
}
				
			

My experience

In a project I was using the attribute schema version, to keep track of the schema changes for development purposes and the latest version was the arbitrary value of 0.4.
I didn’t think this specific value would have consequences on internal Solr logic but actually does.
For a specific field, I needed to omit the term frequency and position so, for each query involving that field, I got an error because the phraseQuery was not possible without the position.
I was scratching my head as I was not running any explicit phrase query!
Something was going on under the hood and I realised the culprit was the implicit default, caused by the logic described above.
The issue was solved by explicitly defining the parameter autoGeneratePhraseQueries=false.
Problem solved!

Need Help With This Topic?​​

If you’re struggling with autoGeneratePhraseQueries, don’t worry – we’re here to help! Our team offers expert services and training to help you optimize your Solr search engine and get the most out of your system. Contact us today to learn more!

Need Help with this topic?​

If you're struggling with autoGeneratePhraseQueries, don't worry - we're here to help! Our team offers expert services and training to help you optimize your Solr search engine and get the most out of your system. Contact us today to learn more!

Other posts you may find useful

Sign up for our Newsletter

Did you like this post? Don’t forget to subscribe to our Newsletter to stay always updated in the Information Retrieval world!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.