[Xapian-discuss] Q prefix / Unique ID not being found

James Aylett james-xapian at tartarus.org
Fri Mar 11 16:36:53 GMT 2005


On Fri, Mar 11, 2005 at 10:39:53AM -0500, Sig Lange wrote:

> -- the /bin/read (hacked down for brevity)--
> sys.stderr = sys.stdout
> FieldStore = cgi.FieldStorage()
> print "Content-Type: text/html"
> print
> xapdb = xapian.Database("..")
> 
> enquire = xapian.Enquire(xapdb)
> stemmer = xapian.Stem("english")
> 
> qp = xapian.QueryParser()
> # i do have other prefixes but only Q is important to my example
> qp.set_prefix("id", "Q")
> 
> id = FieldStore.getvalue("id", "")
> q = "id:" + id
> 
> query = qp.parse_query(q)
> 
> enquire.set_query(query)
> matches = enquire.get_mset(0, 1)
> 
> if  matches.get_matches_upper_bound() == 0:
>    print "ERROR: Oops, unable to find a message %s" % (id)
>    sys.exit(0)
> 
> match = iter(matches).next()
> 
> print "ID %i %i%% [%s]" % \
> (match[xapian.MSET_DID], match[xapian.MSET_PERCENT],
> match[xapian.MSET_DOCUMENT].get_data())
> 
> -- the /bin/read --

How about, instead of your QueryParser bit ...:

----------------------------------------------------------------------
id = FieldStore.getvalue("id", "")
query = xapian.Query(xapian.Query.OP_OR, ["Q%s" % str(id)])
enquire.set_query(query)
----------------------------------------------------------------------

since you really don't need to bother about the query parser for this
kind of work.

I'm pretty sure that if a document never got into the database, its
Q-term won't have done either. So if you're getting the id terms to
look for out of the Xapian database, you should be able to find the
documents as well.

You could try getting the posting list from the term, and print the
docid for each Q-term you find, then interrogate the database directly
for those documents, if you're worried there's an inconsistency
between the different tables.

J

-- 
/--------------------------------------------------------------------------\
  James Aylett                                                  xapian.org
  james at tartarus.org                               uncertaintydivision.org



More information about the Xapian-discuss mailing list