[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:


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

If you want the user to be able to specify date ranges in the query string,
see Xapian::DateValueRangeProcessor:



More information about the Xapian-discuss mailing list