[Xapian-discuss] query within value range
Richard Boulton
richard at lemurconsulting.com
Tue Jun 5 15:21:24 BST 2007
Mark Clarkson wrote:
> Hi,
> I'm also having problems finding out how to do this. If I put the query
> 'date:20060501..20070503' through QueryParser I get
> 'D20060501..20070503' for a boolean prefix query, but I don't see how to
> connect this with a particular value index, assuming I had the date
> stored as a value.
>
> So just a couple questions:
>
> Do range queries work for boolean terms or values?
> How do I make it work in C++?
>
> I feel like I'm missing something obvious as this is such a major new
> feature the docs must be somewhere, it should be simple, and I'm surely
> just being dumb!
Sadly, no: there is, as yet, no decent documentation for the new value
range processing feature. There's also a problem with the numerical
value range processing which needs a work-around for now.
Bug #155 (http://www.xapian.org/cgi-bin/bugzilla/show_bug.cgi?id=155) is
tracking this - it's marked as a blocker for the 1.0.1 release, so this
should be fixed shortly.
Briefly, my understanding of the way the feature is intended to be used is:
1) index your data storing the value you wish to sort by in a value (ie,
not as a term). Sorting is only possible in string order, so if you
want to store a number to sort by, this needs to be marshalled into a
form in which numerical sort order is the same as string sort order: for
integers in a known range (eg, dates), the easiest way to do this is to
pad with leading zeros so that all the values are the same length.
2) assuming you're using the query parser, add a value-range processor
to the parser using "add_valuerangeprocessor()". Supposing you're using
a DateValueRangeProcessor, you'd might do something like:
qp.add_valuerangeprocessor(Xapian::DateValueRangeProcessor(1))
Then, a query like "20060501..20070503" will become a ValueRange query,
returning only those documents for which the value in slot 1 is in the
range 20060501 to 20070503.
Note that value range processors don't use prefixes, so you don't need
to specify "date:" in the query - the ".." is picked up as indicating a
range.
3) If you're not using the query parser, you can build the value range
query directly, using the OP_VALUE_RANGE operator (and an associated
constructor).
--
Richard
More information about the Xapian-discuss
mailing list