In Solr 1.4 there were a new type of queries presented the frange queries. This new type of queries let you search for a range of values. According to the Solr developers this queries should be much faster from normal range queries. I thought that I should make a simple test to see how much faster, the new range queries can be expected to be.
Querying Solr
To use the frange query syntax we will need to modify the query. So far, the range query of the data may look as follows:
fq=test_si:[0+TO+10000]
The same query made using the frange looks like this:
fq={!frange l=0 u=10000}test_si
Of course, it is also possible to send query for data types other than numbers, for example:
fq={!frange l=adam u=mariusz}name
Performance
The very logic of the test is pretty simple. The structure of the index contains two fields: id, a unique identifier and a field namestr (string), which contained the values for which I will ask. I generated about 100,000 distinct documents. In addition, in each of the documents the tems in the namestr field are unique so we will easily be able to determine the percentage of terms covered by a given query. Then I started to send queries to Solr that covered a certain percentage of terms in the index. Each of the queries were send multiple times and the execution time of the queries were summed and divided by the number of queries send. The following table shows the test result:
[table “6” not found /]As you can see a standard range query is faster only for queries that cover a small number of terms from the given field. As you can see, the performance gain using the frange queries is starts from about 5% of terms covered. Interestingly, we get a nice increase in query speed, which is encouraging for even faster searching.
To sum up
The results of my test are different in terms of performance to what Yonik Seeley wrote on his blog (my test data can be the cause of this), but what we can say is that using frange queries we can expect an increase in performance for queries that need to search for a range of values.