What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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

Whoosh’s query language is configurable: its whoosh.qparser parser uses plugins to recognize and transform syntax, and you can add, remove, or replace those plugins to change what users can search for. The parser turns a submitted string into query objects from whoosh.query; the default language resembles Lucene’s, but it is not the only language your application has to expose.

What the parser does

A query parser translates a user’s text into a query object or tree that Whoosh can execute. For example, the guide shows rendering shading becoming an And query containing two Term objects. A QueryParser is configured with a default field and a schema. The default field gives unfielded terms somewhere to apply; the schema’s field types determine how input is analyzed before the parser builds query objects.

Whoosh’s parser is assembled from plugins. A plugin can provide taggers, which recognize pieces of syntax, and filters, which transform syntax nodes. In broad terms, the parser turns text into syntax nodes, applies plugin behavior, and produces the query tree. The API also allows a supplied plugins argument to override the default plugin list; WhitespacePlugin is included automatically. See the Whoosh 2.7.4 guide to parsing user queries and the qparser API reference.

The language guide covers terms and phrases, boolean operators, and fielded searches; Whoosh’s quick-start material also describes ranges, prefixes, and wildcards. Which of these users can enter depends on the parser configuration, not just on the fact that the application uses Whoosh.

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

Choose the behavior before exposing syntax

Changing parser plugins is a product decision as well as a code change. Consider what your users need to express, how predictable the resulting searches should be, and whether your index’s schema supports the behavior. For example, removing wildcard syntax can limit potentially costly searches, while adding fuzzy matching can improve tolerance for misspellings but increase work as edit distance rises.

  • User-facing power: Decide whether users need field names, boolean operators, wildcards, fuzzy terms, or complex expressions inside phrases.
  • Predictability: Broad wildcard searches and high-distance fuzzy searches can be expensive. Whoosh’s guide specifically warns that fuzzy distances above 2 can be very slow; it does not give a benchmark for a particular index.
  • Discoverability: Operator words may be English, localized, or symbolic. Choose forms that fit the people using the search box.
  • Schema fit and maintenance: Phrase searching depends on positional data, and custom syntax means code your team must maintain.

Remove syntax you do not want users to have

Disable fielded searches

If users should not choose fields with expressions such as title:term, the guide shows removing FieldsPlugin. The parser still needs a default field for terms that are not field-prefixed.

Disable wildcards, or allow prefixes only

Removing WildcardPlugin removes wildcard syntax. The documentation recommends this as one way to avoid potentially harmful query performance. If users only need terms that begin with a prefix, the API describes removing the wildcard plugin and adding PrefixPlugin instead.

from whoosh.qparser import QueryParser, WildcardPlugin, PrefixPlugin

parser = QueryParser("content", schema)
parser.remove_plugin_class(WildcardPlugin)
parser.add_plugin(PrefixPlugin())

This illustrates the documented configuration pattern: start with a parser for a default field and schema, then change its plugin set. Check the method names against the Whoosh version installed in your project.

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

Change how boolean operators are written

OperatorsPlugin controls patterns for AND, OR, ANDNOT, ANDMAYBE, and NOT. The guide demonstrates replacing English AND/OR with Spanish Y/O, as well as using symbolic operators. Its configuration values are patterns, so regex metacharacters used literally must be escaped.

To change operator spelling, replace the existing OperatorsPlugin with one configured for the tokens your application accepts. Be deliberate about which operators you expose: changing the visible words does not change the underlying boolean semantics, and accepting symbols may require escaping them in the configured patterns.

Rank #3
Sale
Deep Learning with Python
  • Care instruction: Keep away from fire
  • It can be used as a gift
  • It is made up of premium quality material.

Add fuzzy terms only when their cost is acceptable

FuzzyTermPlugin() enables syntax such as cat~ and cat~2. The guide describes the default edit distance as 1 and warns that distances greater than 2 can be very slow. That is qualitative guidance, not a performance guarantee or a measurement for every index. Fuzzy matching should therefore be an explicit choice about search usefulness and resource use, rather than an automatic feature to enable without considering workload.

Allow richer expressions inside sequences

For quoted or otherwise delimited sequences, the guide’s recipe for allowing complex queries inside the sequence is to remove PhrasePlugin and add SequencePlugin(). This changes what may appear within that syntax. The guide also shows slop syntax, which permits distance between terms in a sequence. Use this configuration when that extra expressiveness matches the intended meaning of a user’s query.

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

Define an operator for application-specific syntax

Whoosh’s guide outlines a recipe for a custom operator: choose whether it is prefix, postfix, or infix; create a GroupNode subclass that builds the corresponding query; define a regex for the syntax; create an OpTagger; then configure and install an OperatorsPlugin. This is more work than changing a token, but it lets an application translate its own notation into query objects.

Two details matter when designing the grammar. Infix operators are left-associative by default, and operator order affects binding strength. Decide and test the intended precedence rather than assuming that a newly added operator will bind as users expect.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Defaults and index constraints that affect results

Terms are grouped with AND by default

The default QueryParser grouping is AndGroup, so unqualified terms are required by default. The API allows another grouping, such as OrGroup, when the application wants a broader default. This setting changes how a multi-term query is combined, even if the user types no explicit operator.

Phrases need positions in the indexed field

A phrase query needs positional information in the field being searched. The language guide says phrase searching against a field without position data is impossible and raises QueryError by default. Enabling phrase syntax in the parser cannot supply positional data that the index did not store.

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

A parser without a schema is not a runnable search configuration

The guide distinguishes constructing a parser without a schema for inspecting parser output from processing query text: without a schema, the parser will not process the query text. For an application that must analyze and run user searches, configure the parser with the schema used for those fields. The default-language details, including grouping and phrase behavior, are in the Whoosh 2.7.4 query-language guide.

Version note

The linked documentation is for Whoosh 2.7.4. It establishes the documented parser behavior and examples for that version, but does not establish current release status, Python compatibility, or package maintenance. Before adopting code in a newer or different installation, verify the API and behavior against the Whoosh version your project actually uses.

Quick Recap

SaleBestseller No. 3
Deep Learning with Python
Deep Learning with Python
Care instruction: Keep away from fire; It can be used as a gift; It is made up of premium quality material.
$36.15

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.