[Xapian-discuss] Simulating Fields

James Aylett james-xapian at tartarus.org
Mon May 4 14:35:33 BST 2009


On Sun, May 03, 2009 at 10:04:03PM -0400, Luis Alberto Zarrabeitia Gomez wrote:

>   title:'Sex and the City'
> 
> produces
>   Xapian::Query((Ztitl:(pos=1) OR sex:(pos=2) OR Zand:(pos=3) OR Zthe:(pos=4) OR
> city:(pos=5)))

If you use double quote marks:

>>> print qp.parse_query('title:"Sex and the City"')
Xapian::Query((XTITLEsex:(pos=1) PHRASE 4 XTITLEand:(pos=2) PHRASE 4
XTITLEthe:(pos=3) PHRASE 4 XTITLEcity:(pos=4)))

then you get what you want. (Note that XTITLE is perhaps overkill;
Omega uses S as a prefix for subject, which is probably semantically
the same for you. Not that it's going to make an enormous difference.)

> > 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?

Don't use the TermGenerator if you're creating your own terms, just
Document.add_term() / Document.add_posting() them instead. (In this
case you'll want add_term, since positional information in a term like
this isn't going to help you. Note that having the entire title in one
term feels strange to me, but without knowing your application I can't
comment.)

J

-- 
  James Aylett

  talktorex.co.uk - xapian.org - uncertaintydivision.org



More information about the Xapian-discuss mailing list