[Xapian-discuss] query syntax?

Olly Betts olly at survex.com
Thu Nov 6 13:27:00 GMT 2008


On 06/11/2008, Torsten Foertsch <torsten.foertsch at gmx.net> wrote:
> On Thu 06 Nov 2008, Torsten Foertsch wrote:
> > I am a bit confused about query syntax if wildcard queries are
> > allowed. The code looks like:
> >
> >   my $query=$qp->parse_query( $qstring, FLAG_WILDCARD );
> >   printf "Parsed query '%s'\n", $query->get_description();
> >
> > $qstring is "besteigung AND muench"
> >
> > If the wildcard flag is set $qstring is parsed as:
> >
> >   Xapian::Query((Zbesteig:(pos=1) OR and:(pos=2) OR Zmuench:(pos=3)))
> >
> > without FLAG_WILDCARD I get this:
> >
> >   Xapian::Query((Zbesteig:(pos=1) AND Zmuench:(pos=2)))
> >
> > That means the wildcard flag turns "AND" from an operator into a
> > search word. Is that on purpose?
>
> Found it myself. The Search::Xapian perl module is the culprit.
> XS/QueryParser.xs reads:
>
> Query *
> QueryParser::parse_query(q, flags = 7)
>    string q
>    int flags
>    CODE:
>        try {
>            RETVAL = new Query(THIS->parse_query(q,flags));
>        } catch (const Error &error) {
>            croak( "Exception: %s", error.get_msg().c_str() );
>        }
>    OUTPUT:
>        RETVAL
>
> So, flags is 7 if not otherwise specified. If the queryparser is called
> as
>
>  my $query=$qp->parse_query( $qstring, 7|FLAG_WILDCARD );
>
> it works.
>
> Now I have to figure out what these 3 bits mean.

They mean:

    FLAG_PHRASE|FLAG_BOOLEAN|FLAG_LOVEHATE

I'm not sure why they are hardcoded as a numerifc constant in Search::Xapian -
that's not ideal, though we aren't likely to change the numeric values
arbitrarily.
I think I did once try changing it to the constant expression above,
but that didn't
work, perhaps due to XS limitations.

There really ought to be a "default flags" constant to make it easier
to add flags
to the default ones.

Cheers,
    Olly



More information about the Xapian-discuss mailing list