Daniel Ménard
2006-Sep-13 11:30 UTC
[Xapian-discuss] QueryParser, mapping a single prefix to multiple fields ?
Hello, The doc for QueryParser::add_prefix and QueryParser::add_boolean_prefix says that "multiple fields can be mapped to the same prefix", which is very convenient to handle aliases. But I am in the opposite situation where I would like to map a same prefix to multiple fields: for example, a search for 'title:xapian' would look for 'XTITLEFRExapian' or 'XTITLEENGxapian'. What would be the best way to achieve this? (I'm using the PHP bindings) From what I see, this is not something which is currently supported. If I call multiple times add_boolean_prefix with the same 'field', only the first prefix is taken into account. A solution would be to 'duplicate' search terms, adding a prefix like 'XTITLE ENG AND FRE', but this is obviously a waste of resources. For now, the only solution I see is to pre-process the user request before giving it to the query parser (replace "title:something" with "titleeng:something OR titlefre:something" for each field I want to handle like this)... which is not very elegant. Perhaps it would be a useful feature to add to the query parser? It would not break the API (just call add_prefix / add_boolean_prefix several times with the same field and different prefixes) and I don't think it would break any existing code. Of course ;-) , I'm not fluent enough in C++ to code that myself, and I don't even know if I ask for a simple change or a big one! Please let me know... Best regards, Daniel
Olly Betts
2006-Sep-14 16:48 UTC
[Xapian-discuss] QueryParser, mapping a single prefix to multiple fields ?
On Wed, Sep 13, 2006 at 12:34:51PM +0200, Daniel M?nard wrote:> From what I see, this is not something which is currently supported. If > I call multiple times add_boolean_prefix with the same 'field', only the > first prefix is taken into account.That's a bug - calling add_boolean_prefix() a second time should change the prefix. But I failed to remember how std::map::insert() works in this case (we've had a previous bug because of this too sadly - I think I need to go and audit all calls to std::map::insert()).> Perhaps it would be a useful feature to add to the query parser? It > would not break the API (just call add_prefix / add_boolean_prefix > several times with the same field and different prefixes) and I don't > think it would break any existing code.It shouldn't break existing code (since add_prefix and add_boolean_prefix currently don't work as intended when called a second time) but it would make it impossible to change the registered prefixes, and having to start from a fresh QueryParser is a pain if you just want to change one setting. But it's not an unreasonable thing to want to do, and I think it should be possible to allow it. I'm in the middle of trying to sort out UTF-8 right now - can you file a wishlist bug so this doesn't get forgotten? Cheers, Olly