searchTree()function
searchTree(scope: TreeElement, query: string, options?: SearchTreeOptions): TreeElement[]
| Param | Type | |
|---|---|---|
scope | TreeElement | The element whose descendants are searched. required |
.key | string | required readonly |
.type | `tree-${string}` | required readonly |
query | string | The search string — bare words plus "quoted phrases". required |
options | SearchTreeOptions | Options for searchTree(). |
.limit | number | Maximum number of results to return (defaults to 20). readonly |
.filter | Query | Optional Query narrowing the candidates by any prop before ranking — the same shape queryItems() takes.- e.g. { kind: "method" } to only rank methods, or { source: "…" } to constrain by source. readonly |
| Return | |
|---|---|
TreeElement[] | The matching descendants, best first, capped at limit. |
Search the descendants of a tree element and return the best-ranked matches.
- Walks every descendant of
scope(depth-first;scopeitself is not a candidate), optionally narrowed byoptions.filter. - Tokenises
querywithgetWords()so quoted phrases match literally:searchTree(root, '"hello world" foo')matches the phrasehello worldand the wordfoo. - Requires every token to match (AND, not OR): a candidate is only returned when each token matches at least one of its props. So
date utilreturns only elements matching bothdateandutil, not either alone. - Ranks each candidate (case-insensitive) per token, summing each token's best tier:
nameexact >namestarts-with >nameincludes >titleincludes >descriptionincludes >contentincludes. Anamematch always outranks a content-only match. - An empty
queryreturns the (filtered) candidates in tree order — useful for a filter-only or "show everything" listing.
Examples
searchTree(root, "store", { limit: 10, filter: { kind: "class" } }) // up to 10 classes ranked for "store"