dartora

SearchQuery

SearchQuery encapsulates a parsed user query and provides methods to compute how well a piece of text (or tags) matches that query. It holds lists of positive and negative words, required terms, optional terms and tags, and defines the scoring algorithm used to produce a SearchQueryComparison.

Fields

SearchQuery implements Iteration<PointedWord>, so it can be iterated over all pointed words across all buckets.

Parsing

Use SearchQuery.from(String query, {QueryEngine engine = QueryEngine.defaultEngine}) to parse a raw query string. The engine uses its configured PatternItems to recognise quotes, negation, wildcards, tags and escape sequences. The resulting SearchQuery categorises words into optional, required, forbidden and tag buckets and assigns each a point count based on whether it appears once or multiple times.

Scoring

compare(String text, {bool asTag = false}) → SearchQueryComparison

Compares the query against a given string (e.g. title or description). For each word in optional, require and cannot lists, it builds a regular expression taking into account wildcards (*) and escapes. It counts the number of matches (occurrences) and computes positive/negative points accordingly:

Validity helpers

These flags are OR‑combined when adding comparisons with + to aggregate results across multiple fields (e.g. title + description + tags).

Combining comparisons

When you compare a query against multiple fields, you can add the resulting SearchQueryComparison objects together using the + operator. The operator sums positive/negative points and modifiers and ORs the hasRequired/containsNotAllowed flags. This allows you to accumulate scores across different text sources and then evaluate them together.

Notes