Skip to content

fetchkit: refine ranking and snippet results#12

Merged
gaelic-ghost merged 2 commits into
mainfrom
fetchkit/ranking-snippets
Apr 28, 2026
Merged

fetchkit: refine ranking and snippet results#12
gaelic-ghost merged 2 commits into
mainfrom
fetchkit/ranking-snippets

Conversation

@gaelic-ghost
Copy link
Copy Markdown
Owner

Summary

  • refine conventional-search ranking so title hits get a modest boost, SearchKit scores are normalized per field, and cross-field matches accumulate more intentionally
  • replace the old single-term snippet behavior with shared query-aware snippets that can highlight multiple query terms and show truncation markers when context is cropped
  • add default-path and opt-in SearchKit coverage for ranking preference, phrase behavior, and snippet presentation

Verification

  • swift test
  • bash scripts/repo-maintenance/run-searchkit-tests.sh
  • bash scripts/repo-maintenance/validate-all.sh

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b548baad89

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +75 to +79
let snippetText = truncatedSnippetText(
from: text,
bounds: snippetBounds
)
let matchRanges = matches.compactMap { snippetRange(for: $0, within: snippetBounds, in: text) }
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep snippet match ranges aligned with emitted text

buildSnippet computes matchRanges from raw snippetBounds, but the emitted snippetText is produced by truncatedSnippetText, which trims whitespace and can prepend/append . Because the ranges are not adjusted after those edits, any cropped snippet can return offsets that no longer point at the matched terms in FetchSnippet.text, causing incorrect or missing highlights in consumers that trust matchRanges.

Useful? React with 👍 / 👎.

Comment on lines +103 to +104
let phrase = FetchSearchSupport.exactPhraseText(from: query)
guard !phrase.isEmpty, lowercaseText.range(of: phrase) != nil else {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve exact-phrase behavior across index backends

The in-memory path now strips quotes before exact-phrase matching, so a query like "bright apple" can match there, but the SearchKit backend still wraps the raw query text in quotes (SearchKitFetchIndex.searchString(for:kind:)), which makes quoted input a literal-quote phrase query. This introduces backend-dependent behavior for the same FetchSearchQuery input and can silently drop results when callers include quotes in .exactPhrase searches.

Useful? React with 👍 / 👎.

@gaelic-ghost gaelic-ghost merged commit 2795cc4 into main Apr 28, 2026
1 check passed
@gaelic-ghost gaelic-ghost deleted the fetchkit/ranking-snippets branch April 28, 2026 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant