synonym expansion for boolean prefixes.

Olly Betts olly at survex.com
Tue Jan 5 05:44:36 GMT 2016


On Sun, Dec 27, 2015 at 11:24:36PM -0400, David Bremner wrote:
> I have an application for synonyms for tags in in notmuch, which means
> synonym expansion for a particular boolean prefix. I have a vague memory
> of Olly telling me this doesn't work, but I'm not sure about the
> details.

Yes, synonym expansion isn't done for boolean terms (only "probabilistic
terms", i.e. words in text).

Not sure if there's a reason why, or if it's just something we didn't
consider when synonyms were added.

> My higher level goal is to support a kind of indirection with tags,
> where query tag:foo can really generate tag:bar or tag:fub, depending on
> some kind of configuration.

A better option for this is probably a FieldProcessor - you set one for
a prefix and the it gets passed the value and returns a Query object
for it.  E.g. in lua (where you can just pass an anon function for the
FieldProcessor - we ought to support C++11 lambdas for such things):

    require "xapian"
    foo_tag_term = "Kbar"
    qp = xapian.QueryParser()
    qp:add_boolean_prefix("tag",
	    function (x)
		if x == "foo" then
		    return xapian.Query(foo_tag_term)
		end
		return xapian.Query("K" .. x)
	    end)
    print(qp:parse_query("tag:foo tag:x"))

Which parses to give:

    Query(0 * (Kbar OR Kx))

To achieve this with synonyms in a configurable way you'd need to
rewrite the synonyms in the database to match the current configuration,
so it's not as dynamic as the above.

FieldProcessor isn't in 1.2.x, but then support for synonyms for boolean
terms isn't in any version.

Cheers,
    Olly



More information about the Xapian-discuss mailing list