Whoosh Library Supports Phrase and Proximity Search for Precise Text Queries
Whoosh, a pure-Python full-text search library, offers built-in phrase and proximity query support to help match terms based on word order and position. Standard bag-of-words scoring cannot capture a user's intent when they quote a phrase, so Whoosh uses term position data stored at index time to enable exact phrase matching. A quoted query like "machine learning" will only return documents where those words appear adjacently and in order, filtering out results where the terms are scattered across the text. Adding a slop value after the closing quote, such as ~2, allows a specified number of intervening words while still enforcing term order, broadening results in a controlled way. Developers can also construct Phrase queries directly in code using the Phrase class, which is useful when input comes from structured sources rather than user-typed strings.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.



Discussion (0)
Log in to join the discussion and vote.
Log in