[Xapian-discuss] How to search documents with certain values
Olly Betts
olly at survex.com
Mon May 24 05:34:57 BST 2010
On Sat, May 22, 2010 at 07:00:08PM +0100, Abhinay Mehta wrote:
> I am creating Xapian documents and adding a unix timestamp to each document
> as a value using the doc.add_value method.
>
> When I search my Xapian database, I want the option to only search documents
> with a timestamp within the last year.
>
> Is there a way to search across documents with a value greater than a
> specified value string? Or is there a better way of doing something like
> this?
Filter your query with OP_VALUE_GE:
http://xapian.org/docs/apidoc/html/classXapian_1_1Query.html#df6014fe7725e5427be7210771919f62609e2f1e1647ba549b10856e38c91c3e
In C++, augment your query like so:
Xapian::Query filter(Xapian::Query::OP_VALUE_GE, threshold_value);
query = Xapian::Query(Xapian::Query::OP_FILTER, query, filter);
Note that the ordering uses a string comparison, so you need to pad your
timestamps to a fixed width, or else encode them suitably (e.g. see
Xapian::sortable_serialise()).
If you want the user to be able to specify date ranges in the query string,
see Xapian::DateValueRangeProcessor:
http://xapian.org/docs/valueranges.html#datevaluerangeprocessor
Cheers,
Olly
More information about the Xapian-discuss
mailing list