October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

What Does “machine learning”~2 Mean in Whoosh?

In Whoosh, "machine learning"~2 is a phrase query with slop—not a fuzzy-term query. Learn what the syntax means and what to check if it fails.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

In Whoosh’s default query language, "machine learning"~2 is a phrase query with a proximity-slop suffix. The ~2 sets phrase slop; it is not the fuzzy-edit-distance syntax used with a single unquoted term. Whether it works depends on the parser and the indexed field’s support for term positions.

How Whoosh interprets "machine learning"~2

Whoosh’s default phrase parser treats the text inside quotation marks as a phrase and tokenizes it into terms. The trailing positive integer ~N sets the phrase slop. Whoosh’s query-language guide illustrates this with "whoosh library"~5, which matches when “library” is within five words after “whoosh.”

As an Amazon Associate I earn from qualifying purchases.

So the query asks Whoosh to find the phrase terms in positional proximity, allowing slop of 2. Do not read that suffix as a synonym rule or as a general guarantee about every possible arrangement of intervening words. The documentation’s example establishes the intended proximity behavior, but does not spell out every boundary case for every tokenizer or parser configuration. If an exact edge case matters, verify it against the application’s installed Whoosh version and parser.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How this differs from a fuzzy term query

Quotation marks matter. "machine learning"~2 is a phrase query with slop. By contrast, a suffix on a single unquoted term, such as machine~2, can be interpreted by the parser’s fuzzy-term plugin as an edit-distance setting. The two forms use similar punctuation but express different query behavior.

What must be true for the phrase query to match

  • The parser must accept phrase syntax. Whoosh’s default PhrasePlugin handles quoted phrases. Parser plugins can be removed, replaced, or extended, so a customized parser may not accept the same syntax.
  • The field must store term positions. Phrase searching relies on positions in the indexed field. Whoosh’s schema guide says TEXT fields store positions by default, but a field type or configuration without positions cannot support phrase matching.
  • Indexing and query analysis must be compatible. The text in the index and the text in the query are analyzed into terms. If their analysis differs, the expected phrase may not be represented as the query assumes.

What to check if the query returns no matches

  1. Confirm the parser instance and plugins. Check that the application uses a parser with the default phrase handling, or another parser that supports the syntax. Whoosh’s parser guide describes SequencePlugin for more complex proximity queries.
  2. Check the target field’s schema. Confirm that the indexed field stores term positions. A field without positions cannot satisfy phrase queries.
  3. Compare the analyzers. Verify that indexing and query parsing produce compatible terms for the field, especially if the application uses custom analysis.
  4. Test the boundary behavior you need. Documentation examples explain the general slop syntax, but do not establish every tokenizer- and configuration-specific edge case. Run a focused test with the installed version and the real parser and schema.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Query-string syntax or programmatic query objects?

Approach Best suited to Considerations
Query string, such as "machine learning"~2 User-entered or compact query syntax Depends on the parser and its phrase-related plugins.
Programmatic query objects Queries assembled explicitly in application code The API provides Phrase and span-query types. For new code using near-span queries, the API reference recommends SpanNear2 rather than SpanNear.

Both approaches still require an index and field configuration that support positional matching. The relevant documentation identifies itself as Whoosh 2.7.4; these syntax notes should not be taken as a claim about current maintenance or the latest release.

Whoosh documentation

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.