Search code examples
pythonzope

How can I make Zope TextIndex return similar documents?


Using zope's TextIndex, how can I search the index for document that is similar to the search string, but where the tokens of the search string are not all in the target document?

>>> from zope.index.text.textindex import TextIndex
>>> index = TextIndex()
>>> index.index_doc(1, "silver pearl splitter")
>>> index.apply("pearl silver") # this works
BTrees.IFBTree.IFBucket([(1, 0.8164966106414795)])
>>> index.apply("silver pearl splayer") # this doesn't
BTrees.IFBTree.IFBucket([])

Is there a reasonably easy way to have the index find "silver pearl splitter" if I search for "silver pearl splayer"?


Solution

  • Here's one way that I found.

    index.apply(" OR ".join("silver pearl splayer").split())