[Xapian-discuss] Combined search in multiple fields help

Tom tom at lemurconsulting.com
Sun Dec 13 10:41:34 GMT 2009


Hi Don,

Probably the simplest way to do this (if I understand your
requirements correctly) is to use QueryParser::add_prefix()
(http://shrunk.net/63b17360 ).  If you provide an empty field name,
any prefixes you set will be added to 'bare' terms. So if you want to
search prefixes XA and XB by default:

qp = QueryParser();
...
qp.add_prefix("", "XA");
qp.add_prefix("", "XB");
...

If you make this dependent on the dropdown value the user has
selected, I think it will do what you want.

Tom


2009/12/13 Do. <do1 at yandex.ru>:
> Hello,
>
> I want to let user specify by drop down list to what fields his query will be searched. For example "Full-text" or "Title+Author", then user enters search query as usual (without using prefixes). But how to modify query so it cover two fields in a right way?
>
> For a starter how I think about modifying query to limit it just to single globally selected field:
> 1. after user enters free-text query I parse it as usual via parse_query(),
> 2. then I iterate through resulting Xapian::Query by get_terms and apend A or S prefix to evey term (after Z if Z is present, and not appending where other prefix is already applied (for example H)).
> (Btw, is this optimal strategy?)
>
> What I think about multiple fields and where it fail:
> There is two situation depending on default_op().
> 'or') I just duplicate parsed query as whole and add different prefix to each of them, then combine these big queries with 'or'.
> 'and') hard part begin, probably I should duplicate each term, add one prefix to original and other to clone and combine it with OR with existing term. Right? Will this be possible? Any suggestions?
>
> Don.
>
>
>
> _______________________________________________
> Xapian-discuss mailing list
> Xapian-discuss at lists.xapian.org
> http://lists.xapian.org/mailman/listinfo/xapian-discuss
>



More information about the Xapian-discuss mailing list