Let's assume we have Apache Solr deployment where we use range queries. Some of those are run against string fields, while others are run against numerical fields. We identified that our numerical range queries are executing slower than we would like them to run. The usual question arises—is there something that we can do? Of course there is, and this recipe will show you what.
schema.xml
file):<field name="price" type="float" indexed="true" stored="true"/>
float
field type (again, we add this to the schema.xml
file):<fieldType name="float" class="solr.TrieFloatField" precisionStep="8" />
q=*:*&fq=price:[10.0+TO+59.00]&facet=true&facet.field=price
precisionStep
attribute of the float
field type; for example, from 8
to 4
. Our field type definition will look as follows:<fieldType name="float" class="solr.TrieFloatField" precisionStep="4" positionIncrementGap="0"/>
After the preceding change, you will have to reindex your data and you will see that your numerical queries are running faster. How much faster—that depends on your setup. Now let's take a look at how it works.
As you can see in the preceding example, we use a simple float
based field to run numerical range queries. Before the changes, we set precisionStep
on our field type as 8
. This attribute (specified in bits) tells Lucene (which Solr is built on top of) how many tokens should be indexed for a single value in such a field. Smaller precisionStep
values (when precisionStep
is greater than 0
) will lead to more tokens generated by a single value and thus making range queries faster. Because of this, when we decreased our precisionStep
value from 8
to 4
, we saw the performance increase.
However, remember that decreasing the precisionStep
value will lead to slightly larger indices. Also setting the precisionStep
value to 0
turns off indexing of multiple tokens per value, so don't use that value if you want your range queries to perform faster.
3.146.221.149