Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Quick look: Solr Frange Queries

DZone's Guide to

Quick look: Solr Frange Queries

· Java Zone
Free Resource

The single app analytics solutions to take your web and mobile apps to the next level.  Try today!  Brought to you in partnership with CA Technologies

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:

  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:

Percent of terms covered Faster implementation Range query execution time Frange query execution time
100% frange average 240ms average 15ms
50% frange average 105ms average 12ms
10% frange average 50ms average 8ms
5% frange average 12ms average 12ms
1% range average 10ms average 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.



CA App Experience Analytics, a whole new level of visibility. Learn more. Brought to you in partnership with CA Technologies.

Topics:

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

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

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

X

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

{{ parent.tldr }}

{{ parent.urlSource.name }}