[Xapian-discuss] Simulating Fields

Luis Alberto Zarrabeitia Gomez kyrie at uh.cu
Mon May 4 03:04:03 BST 2009


Quoting James Aylett <james-xapian at tartarus.org>:

> On Sat, May 02, 2009 at 05:19:56PM -0400, Luis Alberto Zarrabeitia Gomez
> wrote:
> 
> > delve shows the title terms indexed with the XTITLE prefix, but, how
> > do I write a query to search for those? How can I write a query to
> > retrieve a document given the title (but not those with similar
> > titles)?
> 
> 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")
===

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'

produces
  Xapian::Query((Ztitl:(pos=1) OR sex:(pos=2) OR Zand:(pos=3) OR Zthe:(pos=4) OR
city:(pos=5)))

Can you give me an example of how to build the query?

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

Thanks!

-- 
Luis Zarrabeitia
Facultad de Matemática y Computación, UH
http://profesores.matcom.uh.cu/~kyrie


-- 
Participe en Universidad 2010, del 8 al 12 de febrero de 2010
La Habana, Cuba 
http://www.universidad2010.cu




More information about the Xapian-discuss mailing list