[Xapian-discuss] How to search documents with certain values

Abhinay Mehta abhinay.mehta at gmail.com
Mon May 24 10:06:17 BST 2010

Thanks Olly.
I was wrong about how I was storing the date in the document value. I am
storing it as the string: YYYYMMDD

I've tested it and can use Xapian::DateValueRangeProcessor by appending the
range string: YYYYMMDD..YYYYMMDD to the user query myself.
Not sure if that's too much of a cow-boy way of doing it.

Will test out the Xapian::Query::OP_VALUE_GE method later today.

Also would anyone know about the performance difference between the two
different methods?

Abhinay Mehta

On 24 May 2010 05:34, Olly Betts <olly at survex.com> wrote:

> 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