dartora

Search

The Search class coordinates parsing a user query, comparing it against a collection of Searchable items and sorting the results by relevance. It encapsulates a compiled SearchQuery and provides convenience methods for comparing individual items or executing the full search.

Construction

Search.from(String query, {QueryEngine engine = QueryEngine.defaultEngine})

Search({ required SearchQuery query, bool Function(SearchItem)? itemCheck })

Fields

Methods

compare(Searchable item)

Compares a single Searchable against the query and returns a SearchQueryComparison. It concatenates the title, description and tag text of the item into a unified string. For each field it calls query.compare(...) and then combines the comparisons with +, which merges points and flags. This method does not enforce hasRequired or containsNotAllowed; it simply measures how well the item matches.

getItem(Searchable item)

Wraps a Searchable and its comparison into a SearchItem. This is convenient when you want both the item and its score.

validityCheck(SearchItem item)

Determines whether a SearchItem is acceptable. It returns false if:

If the built‑in checks pass, it calls the user‑provided itemCheck (if any) to allow custom filtering.

search({ required List<Searchable> held })

Executes the search over the provided list of items. It iterates through each item, computes its SearchQueryComparison, wraps it into a SearchItem, checks validity and inserts it into a results list in descending order of total points. The insertion uses a simple linear scan: for each new item, find the index where its score is greater than or equal to the score of the item at that index and insert it there. If the item has zero points, it is appended at the end.

The returned list contains all matching items sorted by relevance.

Notes