[Xapian-tickets] [Xapian] #503: Add Python PostingSource example from Xappy to docs

Xapian nobody at xapian.org
Mon Aug 9 13:54:28 BST 2010


#503: Add Python PostingSource example from Xappy to docs
-------------------------+--------------------------------------------------
 Reporter:  jcassee      |       Owner:  olly
     Type:  enhancement  |      Status:  new 
 Priority:  normal       |   Milestone:      
Component:  Other        |     Version:      
 Severity:  normal       |   Blockedby:      
 Platform:  All          |    Blocking:      
-------------------------+--------------------------------------------------
 The Xappy source code contains a perfect example of a
 [http://code.google.com/p/xappy/source/browse/trunk/xappy/searchconnection.py?r=620#1591
 weight-only (non-filtering) !PostingSource written in Python]. This would
 be a good addition to the [source:trunk/xapian-
 core/docs/postingsource.rstpostingsource docs]. I have slightly edited the
 original.

 {{{
 class ExternalWeightPostingSource(xapian.PostingSource):
     """
     A Xapian posting source reading from an ExternalWeightSource.
     """
     def __init__(self, xapdb, wtsource):
         xapian.PostingSource.__init__(self)
         self.xapdb = xapdb
         self.wtsource = wtsource

     def init(self, xapdb):
         self.alldocs = xapdb.postlist('')

     def reset(self, xapdb):
         # backwards compatibility
         self.init(xapdb)

     def get_termfreq_min(self): return 0
     def get_termfreq_est(self): return self.xapdb.get_doccount()
     def get_termfreq_max(self): return self.xapdb.get_doccount()

     def next(self, minweight):
         try:
             self.current = self.alldocs.next()
         except StopIteration:
             self.current = None

     def skip_to(self, docid, minweight):
         try:
             self.current = self.alldocs.skip_to(docid)
         except StopIteration:
             self.current = None

     def at_end(self):
         return self.current is None

     def get_docid(self):
         return self.current.docid

     def get_maxweight(self):
         return self.wtsource.get_maxweight()

     def get_weight(self):
         xapdoc = self.xapdb.get_document(self.current.docid)
         doc = ProcessedDocument(self.conn._field_mappings, xapdoc)
         return self.wtsource.get_weight(doc)
 }}}

-- 
Ticket URL: <http://trac.xapian.org/ticket/503>
Xapian <http://xapian.org/>
Xapian



More information about the Xapian-tickets mailing list