[Xapian-discuss] Newbie question: searching certain fields only

Olly Betts olly at survex.com
Sun Sep 26 12:49:46 BST 2010


On Sat, Sep 25, 2010 at 03:38:04PM +0100, Matt Goodall wrote:
> The best way is probably to add terms both with and without the field
> prefix for the 'Name' and 'Surname' fields, but only with the prefix
> for the 'Address' field. You then end up with an index containing
> something like the following keys:
> 
>     matt
>     XNAMEmatt
>     goodall
>     XSURNAMEgoodall
>     XADDRESS123
>     XADDRESSwiggly
>     XADDRESSroad

You can also omit the unprefixed terms (i.e. 'matt' and 'goodall' in this
case) and set the QueryParser to expand the empty prefix to term prefixes
XNAME and XSURNAME, so the prefix setup would be:

    qp.add_prefix("", "XNAME");
    qp.add_prefix("", "XSURNAME");
    qp.add_prefix("name", "XNAME");
    qp.add_prefix("surname", "XSURNAME");
    qp.add_prefix("address", "XADDRESS");

This results in fewer terms in the index, but searches without a prefix
need to look up two terms rather than just one, so it's not obvious which
is likely to be more efficient.

Cheers,
    Olly



More information about the Xapian-discuss mailing list