index 385bcaecaa93cbbd9ddcd1f9f5ab54a7bfe01453..f071baa6923b38dcd21a8a33338cb5b9eb3dfdad 100644 (file)
# indexed so we know what we're matching when we get results
identifier = '%s:%s:%s'%identifier
- # see if the id is in the database
- enquire = xapian.Enquire(database)
- query = xapian.Query(xapian.Query.OP_AND, [identifier])
- enquire.set_query(query)
- matches = enquire.get_mset(0, 10)
- if len(matches):
- docid = matches[0].docid
- else:
- docid = None
-
# create the new document
doc = xapian.Document()
doc.set_data(identifier)
- doc.add_posting(identifier, 0)
+ doc.add_term(identifier, 0)
for match in re.finditer(r'\b\w{%d,%d}\b'
% (self.minlength, self.maxlength),
continue
term = stemmer(word)
doc.add_posting(term, match.start(0))
- if docid:
- database.replace_document(docid, doc)
- else:
- database.add_document(doc)
+
+ database.replace_document(identifier, doc)
def find(self, wordlist):
'''look up all the words in the wordlist.
enquire.set_query(query)
matches = enquire.get_mset(0, 10)
- return [tuple(m[xapian.MSET_DOCUMENT].get_data().split(':'))
+ return [tuple(m.document.get_data().split(':'))
for m in matches]