Over a million developers have joined DZone.

Quick look: Solr Frange Queries

· Java Zone

What every Java engineer should know about microservices: Reactive Microservices Architecture.  Brought to you in partnership with Lightbend.

In Solr 1.4 there was a new type of query presented: the frange queries. This new type of query lets you search for a range of values. According to the Solr developers, these 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:


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  


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:

Percent of terms coveredFaster implementationRange query execution timeFrange query execution time
100%frangeaverage 240msaverage 15ms
50%frangeaverage 105msaverage 12ms
10%frangeaverage 50msaverage 8ms
5%frangeaverage 12msaverage 12ms
1%rangeaverage 10msaverage 12ms

As you can see a standard range query is faster only for queries that cover a small number of terms from the given field.  The performance gain using the frange queries 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 when using frange queries, we can expect an increase in performance for queries that need to search for a range of values.

Microservices for Java, explained. Revitalize your legacy systems (and your career) with Reactive Microservices Architecture, a free O'Reilly book. Brought to you in partnership with Lightbend.


Published at DZone with permission of Rafał Kuć, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}