[Xapian-discuss] Simulating Fields
Olly Betts
olly at survex.com
Mon May 4 03:51:44 BST 2009
On Sun, May 03, 2009 at 10:04:03PM -0400, Luis Alberto Zarrabeitia Gomez wrote:
>
> Quoting James Aylett <james-xapian at tartarus.org>:
>
> > You can use the QueryParser for this; set a term prefix before parsing
> > the query, for instance.
>
> I tried to do this (qp is a QueryParser instance, with the same stemmer)
>
> ===
> qp.set_stemming_strategy(xapian.QueryParser.STEM_SOME)
> qp.add_boolean_prefix("realtitle",'XTITLE')
> qp.add_prefix("title","XTITLE")
> ===
I'm not sure what you think "realtitle" is going to be useful for. It
doesn't generally make sense to have the same term prefix generated by
both boolean and probabilistic prefixes.
> but then... how do I construct the query?
>
> title:Sex and the City
>
> produces the query:
> Xapian::Query((XTITLEsex:(pos=1) OR Zand:(pos=2) OR Zthe:(pos=3) OR city:(pos=4)))
>
> (i.e, only "sex" in the title), while
>
> title:'Sex and the City'
If you want a phrase, the syntax is double quotes:
title:"Sex and the City"
If you want to apply the prefix to all terms in a subexpression, use
brackets:
title:(Sex and the City)
Note that the syntax supported by the QueryParser is described here:
http://xapian.org/docs/queryparser.html
> > Not that if you're matching on exact titles,
> > you probably want a phrase search (or, if you're not doing anything
> > else, possibly to construct the term as XTITLE<title> and match it as
> > a single (boolean) term, without using the QueryParser at all).
>
> I guess that'd mean that during the indexing, I would have to use the whole
> title as a single term? (just to be clear), instead of
> 'indexer.index_text(page.title,1,"XTITLE")'. What function should I call, then?
> Could you provide me an example?
document.add_term("XTITLE" + page.title)
I'm not sure I'd recommend this approach though - there's a limit of
about 240 bytes on the length of terms.
Cheers,
Olly
More information about the Xapian-discuss
mailing list