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

Matt Goodall matt.goodall at gmail.com
Sat Sep 25 15:38:04 BST 2010


On 25 September 2010 13:31, goran kent <gorankent at gmail.com> wrote:

> Given the following fields (values with prefixes):
>
> Name:  ....
> Surname:  ....
> Address: ....
> ...
>
> How can I (by default) search in Name and Surname only?  ie, I want to
> ignore the Address field during search, unless I explicitly search it (eg,
> by using "+address:..." in my query).
>
> I don't want to add "-address:..." to the query (even silently in the
> background) since this might inadvertently exclude desired results.

Hi,

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

(not my real address ;-))

A search for "matt" will match any terms from the 'Name' or 'Surname'
fields. An "address:...", "name:...", etc search will match only the
prefixed terms as before.

Hope that helps.

- Matt



More information about the Xapian-discuss mailing list