[Xapian-discuss] Search for exact match on document

Olly Betts olly at survex.com
Mon May 19 11:02:55 BST 2014


On Sat, May 17, 2014 at 04:25:06PM +0200, Jorge Cardoso Leitão wrote:
> More generally, the question can be posed on the following terms: how can I
> query exact matches to fields?

I'd suggest indexing special terms to mark the start and end of fields
for which you want to do exact matching, such that the start term's
position is one before the first real position in that field, and the
end term's position is one after the last real position.

If you make these terms FNAME^ and FNAME$, then you can build a suitable
phrase query in Python like so:

     terms = ['FNAME^', 'FNAMEfoo', 'FNAMEbar', 'FNAME$']
     xapian.Query(xapian.Query.OP_PHRASE, terms)

You can also use these special terms to anchor a match to just the start
or just the end of a field.

Cheers,
    Olly



More information about the Xapian-discuss mailing list