1

I'm trying to write a lucene query to filter some data in RavenDB. Some of the documents in this specific collection are assigned a sequential number, and the valid ranges are not continuous (for example, one range can be from 100-200 and another from 1000 to 1400). I want to query RavenDB using Raven Studio (v2.5, the Silverlight client) to retrieve all documents that have values outside of these user-defined ranges.

This is the overly simplified document structure:

{  
   ExternalId: something/1,
   SequentialNumber: 12345
}

To test, I added 3500 documents, all of which have a SequentialNumber that's inside one of the following two ranges: 123-312 and 9000-18000, except for one that has 100000123. The ExternalId field is a reference to the parent document, and for this test all the documents have the field set to something/1. This is the Lucene query I came up with:

ExternalId: something/1 AND NOT 
(SequentialNumber: [123 TO 321] OR SequentialNumber: [9000 TO 18000])

Running the query in RavenDB's Studio returns all the documents where SequentialNumber isn't in the 123-321 range. I would expect it to only return the document that has 100000123 as a SequentialNumber. I've been trying to Google for help, but so far I haven't found anything to steer me into the right direction.

What am I doing wrong?

enriquein
  • 1,048
  • 1
  • 12
  • 28

1 Answers1

1

RavenDB is indexing numbers in two ways, once as strings (which is what you see here) and once in numeric form. For range queries use:

SequentialNumber_Range: [Ix123 TO Ix321] OR SequentialNumber_Range: [Ix9000 TO Ix18000])

The Ix prefix means that you are using int32

Ayende Rahien
  • 22,925
  • 1
  • 36
  • 41
  • Thanks! That solved one problem. Since the field is marked in the index as Long (`Sort(x => x.SequentialNumber, SortOptions.Long)`) I had to change Ix to Lx. Now if I run the query without the `NOT` (`ExternalId: something/1 AND (SequentialNumber_Range: [Lx123 TO Lx321] OR SequentialNumber_Range: [LX9000 TO LX18000])`) I get the expected results: every doc except the one that is outside of the ranges. What I can't seem to pull off is getting Lucene to do the `NOT` so that it returns the documents outside the range. Is this a Lucene limitation outside of the scope of RavenDb? – enriquein Aug 20 '15 at 00:57
  • Nevermind, after a few minutes of fiddling around in Raven Studio it finally returned the expected result. Not sure what happened there, it must've been an UI thing. Thanks so much for the help! – enriquein Aug 20 '15 at 01:04