You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improve documentation search quality by incorporating where the query appears inside each searchable field, whether the full phrase matches, how close multiple tokens occur, and whether a match respects identifier boundaries or camel-case components.
This issue refines ranking and result snippets. It must not change the public search interaction or duplicate the Reference drawer UI work in #422.
Goals
Use first-match position as a secondary relevance signal.
Reward full-query phrase matches over separated token matches.
Reward close token proximity within the same field.
Distinguish identifier-boundary and camel-case component matches from arbitrary substrings.
Produce bounded snippets centered around the first useful documentation match.
Preserve physical source provenance and merge source-specific evidence correctly.
Keep name/alias/syntax field importance above prose position bonuses.
Keep ranking deterministic and bounded.
Position signals
For each available searchable field, compute the first case-insensitive match position of the full normalized query:
positionCaseInsensitiveUTF8(name, q) AS name_phrase_pos
positionCaseInsensitiveUTF8(alias_to, q) AS alias_phrase_pos
positionCaseInsensitiveUTF8(syntax, q) AS syntax_phrase_pos
positionCaseInsensitiveUTF8(categories, q) AS category_phrase_pos
positionCaseInsensitiveUTF8(description, q) AS description_phrase_pos
0 means no match; positive values are 1-based character positions.
Every UNION ALL branch must project compatible position columns. A branch lacking a field projects typed zero values.
Multi-token positions
For a normalized query with several tokens, return first positions per token for fields where proximity matters, at least:
The exact SQL representation may be arrays or fixed generated scalar columns. It must remain type-compatible across all union branches and bounded by the maximum normalized query length/token count.
Do not calculate textual proximity across different fields. A token in syntax and another in description receives field-coverage credit, not proximity credit.
Earlier-occurrence bonus
Earlier matches are generally more relevant, especially within full Markdown documentation bodies.
Suggested position bonus:
position 1–80 +80
position 81–240 +50
position 241–800 +25
position above 800 +10
Position bonuses are secondary. They must not allow an early prose occurrence to outrank exact, prefix, alias, or strong syntax matches.
The total prose-derived contribution must remain capped.
Phrase bonus
Reward the full normalized query appearing as a phrase.
Relative priority:
phrase in canonical name;
phrase in alias;
phrase in syntax;
phrase in category/type;
phrase in description.
A phrase match must outrank the same tokens scattered through the same field, while still respecting the baseline field weights from #421.
Token proximity
For matched token positions within one field, calculate the span:
Duplicate logical entities may carry different match evidence from different physical tables.
Do not collapse evidence prematurely.
For each contributing source retain enough data to determine:
which field matched;
phrase position;
token positions/proximity;
snippet quality;
source table.
Merged result policy:
retain all source provenance;
score each source row with the shared policy;
use the strongest source-specific evidence as the merged relevance score;
prefer structured snippets for concise descriptions when similarly relevant;
use broad system.documentation text when it contains the only or clearly stronger match;
smallest positive position may be used only within comparable fields; do not treat position 20 in a concise structured description as automatically equivalent to position 20 in a full Markdown document;
preserve deterministic selection when scores tie.
The full documentation entry source remains controlled by existing docEntry(target) policy.
Parent design: #420
Depends on: #421
Purpose
Improve documentation search quality by incorporating where the query appears inside each searchable field, whether the full phrase matches, how close multiple tokens occur, and whether a match respects identifier boundaries or camel-case components.
This issue refines ranking and result snippets. It must not change the public search interaction or duplicate the Reference drawer UI work in #422.
Goals
Position signals
For each available searchable field, compute the first case-insensitive match position of the full normalized query:
0means no match; positive values are 1-based character positions.Every
UNION ALLbranch must project compatible position columns. A branch lacking a field projects typed zero values.Multi-token positions
For a normalized query with several tokens, return first positions per token for fields where proximity matters, at least:
Conceptually:
The exact SQL representation may be arrays or fixed generated scalar columns. It must remain type-compatible across all union branches and bounded by the maximum normalized query length/token count.
Do not calculate textual proximity across different fields. A token in syntax and another in description receives field-coverage credit, not proximity credit.
Earlier-occurrence bonus
Earlier matches are generally more relevant, especially within full Markdown documentation bodies.
Suggested position bonus:
Position bonuses are secondary. They must not allow an early prose occurrence to outrank exact, prefix, alias, or strong syntax matches.
The total prose-derived contribution must remain capped.
Phrase bonus
Reward the full normalized query appearing as a phrase.
Relative priority:
A phrase match must outrank the same tokens scattered through the same field, while still respecting the baseline field weights from #421.
Token proximity
For matched token positions within one field, calculate the span:
Suggested proximity bonus:
Requirements:
Identifier-boundary and camel-case scoring
Substring retrieval should remain permissive, but JavaScript ranking should distinguish stronger lexical matches.
Identifier boundaries are characters outside
[A-Za-z0-9_]or the beginning/end of the string.Examples:
summatchingsumas a complete identifier word: strongest boundary bonus;arraymatching theArraycomponent ingroupArray: useful camel-case component bonus;summatching insidechecksum: no boundary/camel bonus;Implement locale-stable, deterministic matching suitable for ClickHouse identifiers. Do not depend on browser-specific segmentation APIs.
Suggested ordering:
These bonuses refine the field’s existing match score rather than replacing it.
Match-centered snippets
Search must continue to avoid returning complete documentation bodies for every candidate.
Calculate match positions against the full field, then return a bounded snippet around the first useful description match:
if( description_pos > 0, substringUTF8(description, greatest(1, description_pos - 100), 400), substringUTF8(description, 1, 400) ) AS descriptionExact SQL may vary with supported ClickHouse functions, but behavior must be:
The snippet model should indicate when leading/trailing content was omitted so the UI may render ellipses safely without guessing.
Suggested result fields:
Shared union projection
Extend the normalized search row with compatible evidence fields, for example:
Every included source branch must emit the same ordered types. Missing source fields use explicit typed zero/empty values.
The foundational physical
source_tablecolumn remains required.JavaScript scoring
Add pure helpers such as:
The exact weights may be tuned with fixtures, subject to these invariants:
Source-aware evidence merge
Duplicate logical entities may carry different match evidence from different physical tables.
Do not collapse evidence prematurely.
For each contributing source retain enough data to determine:
Merged result policy:
system.documentationtext when it contains the only or clearly stronger match;The full documentation entry source remains controlled by existing
docEntry(target)policy.Query and payload bounds
Suggested implementation boundary
src/core/doc-search.tsOwn pure logic for:
SQL branch builders
Extend capability-generated projections with match positions, token evidence, and bounded context snippets. Keep optional columns capability-safe.
SchemaCatalogServiceNo public API redesign should be necessary. It continues to execute one union, normalize, merge, rank, and cache the refined result model.
Reference drawer
No required interaction changes. #422 consumes the improved summaries/order through the existing
docSearch()response.Quality fixtures
Add realistic fixtures covering queries such as:
array aggregationarray joinmerge tree ttljson inputdate truncatesumgroup arrayFixtures should include competing rows where:
Expected ordering must be explicit and stable.
Tests
Position extraction/projection
Position scoring
0contributes nothing;Phrase and proximity
Lexical matching
suminsidechecksumdoes not receive boundary credit;Snippets
Source merge
Regression
UNION ALLrequest;Acceptance criteria
Non-goals