Repository navigation
Conversation
V3 finds matched fields after the query, from each hit's stored values, and did not apply synonyms. The analyzers do expand them, so a hit retrieved only through a synonym, such as a name holding one spelling when the query used the other, came back with no matched fields. Match tiers then saw no name match at all, and the two spellings of one query ranked differently. MatchedFields now adds the stems of the query's synonyms, and of each of its words' synonyms, from the synonym files the analyzers load, so such a hit reports the field it matched through.
PR SummaryOverview Search templates gain Docs for Search V3 highlight behavior and Mustache context are updated accordingly. Reviewed by Cursor Bugbot for commit 8c1ba11. Bugbot is set up for automated code reviews on this repo. Configure here. |
Smart test selectionpytest smoke testsMode: active. Only the selection below runs for the pytest smoke tests on this PR (applied:
Selected scopes (30 files or classes, 146 tests)
Add the Playwright E2E testsThis run:
Specs selected because of this PR (8)
Add the commit |
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
The template `synonyms` list holds the synonyms of the whole query and of each of its words. That suits recall clauses, but an exact-name clause built on it treats a word's synonym as a name for the whole query: for a two-word query, an entity named like one word's synonym would count as an exact match. Templates can now read `exactSynonyms`, the synonyms of the whole query only, capped like `synonyms`. The design doc lists it and corrects the `synonyms` row, which described the whole query only.
Review follow-up for the synonym-aware V3 matched fields: - A multi-word synonym matches the engine only as a phrase, but the word scan matched each of its words alone, so a hit holding just one of them reported a field. Multi-word synonyms are now left out. - A synonym-only match could take a field's single reported value, or the fragment anchor, from a value that also held a typed word. A field now reports a value with a typed word first and falls back to a synonym-only value.
…ynonyms docs Review follow-up: - A name such as a dataset's can be read from its own key and from fallback paths, and the template scan took the first match per name across separate scans, so a synonym-only value on the key could hide a typed match on a fallback path. MatchedFields.firstPerName scans one name's paths together, typed words first, and the template and stage scans use it. - The shipped fulltext template's exact-name term still expands every word's synonym; the docs and Javadoc now say exactSynonyms is for such a clause rather than that one reads it. The operator context table lists it, and the design doc says one-word synonyms now count in matched fields.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit c5486cf. Configure here.
The scan grouped a label's key with its stored paths by renaming each path through the fallback labels. A label key that is also a stored path of another label was then renamed to that label and never reported under its own name. firstPerName now takes the paths of each name explicitly, so one path can be listed under two names. The per-path scan behind the non-template V3 search also drops a synonym-only value when another path of the same name holds a typed word.
…abel once The synonym lookup read the raw query split on whitespace, while the analyzers fold the query's words and expand their synonyms before they drop short words. A quoted or punctuated query, or one whose only word is shorter than the minimum length, reported no synonym match, although the engine found the hit through that synonym. The lookup now reads the folded words, and a synonym counts as a query word. The queried and highlighted label sets were scanned one after the other, so a label could report a synonym-only value from the first scan and hide a typed value from a stored path that only the second set gives it. Both sets now give their paths to one scan per label. Tests also cover the exactSynonyms cap, a typed stored path against a synonym on the label key, and a synonym match in explain output.
…eated synonym terms A caller that reads the first of several matched names, such as a match tier that takes a display name, could get a synonym-only value ahead of a typed one on a later name. Typed matches are now reported first. The synonym catalog kept only the last line of a term that appears on several lines, while the analyzers' synonym map takes the members of every line. It now merges them. The shipped synonym file repeats no term, so its expansions do not change.
alexsku
left a comment
There was a problem hiding this comment.
I found two cases where the engine can match a stored name but the V3 response omits it from matchedFields. The inline examples are small enough to add to MatchedFieldsTest. I also found a whitespace inconsistency in the new exactSynonyms variable.
| final Matcher matcher = WORD.matcher(text); | ||
| while (matcher.find()) { | ||
| for (String form : forms(matcher.group())) { | ||
| if (synonymStems.contains(stem(form))) { |
There was a problem hiding this comment.
Searching staging reports name=stg_orders, but name=stgOrders produces no matched field. I checked the index-side word delimiter with the V3 settings and it emits stg for stgOrders. This scan folds the entire camel-case token before comparing stems and loses that boundary. Could we preserve the index-side word forms when scanning stored values and test both spellings against staging?
| // multi-word synonym matches only as a phrase, which this word scan cannot check, so it is left | ||
| // out rather than matching each of its words alone. | ||
| final Set<String> synonymStems = new HashSet<>(); | ||
| for (String synonym : SearchTemplateSynonyms.expansions(String.join(" ", foldedWords))) { |
There was a problem hiding this comment.
For data platform team, the shipped data platform, dataplatform equivalence rule produces dataplatform in Lucene’s synonym graph. The lookup here tries the entire query and each individual word, so a stored name=dataplatform yields no matched field. Could the scan recognize a multi-token input phrase within a longer query when the rule emits a single token? That would also preserve the existing behavior that an individual word of a multi-word output is insufficient.
| */ | ||
| @Nonnull | ||
| public static List<String> wholeQuery(@Nonnull String query) { | ||
| String text = query.toLowerCase(Locale.ROOT).trim(); |
There was a problem hiding this comment.
wholeQuery("data platform") returns dataplatform, while wholeQuery("data platform") returns an empty list. The matched-field scan recognizes the phrase with either spacing. Could we normalize internal whitespace before looking up a whole phrase and add a test for repeated spaces?

Two synonym fixes for Search V3.
Matched fields for synonyms. On V3, matched fields are found after the query from each hit's stored values (
MatchedFields), because the sharedcopy_tofields the query reads cannot be highlighted. That scan did not apply synonyms, while the analyzers do expand them. A hit retrieved only through a synonym, such as a name holding one spelling when the query used the other, came back with no matched fields, so match tiers saw no name match and the two spellings of one query ranked their results differently.MatchedFieldsnow also matches the one-word synonyms of the query and of each of its words, from the equivalence lines of the synonym files (SearchTemplateSynonyms). As in the analyzers, the lookup reads the folded words of the query before short words are dropped, so a quoted query, words joined by punctuation and a word shorter than the minimum length still find the synonyms of each word (a synonym-file phrase that itself contains punctuation, such assingle sign-on, is not matched as a whole query). A field reports a value that holds a typed word ahead of one that holds only a synonym. Multi-word synonyms, which the engine matches only as phrases, and explicit=>rules are left out, and prefix matching still applies only to the last word as typed. In explain output a synonym match reads as a word match on the stemmed subfield.Whole-query synonyms for templates. The template
synonymslist holds the synonyms of the whole query and of each of its words, which suits recall clauses. An exact-name clause built on it would treat a word's synonym as a name for the whole query. Templates can now readexactSynonyms, the synonyms of the whole query only, capped likesynonyms. The design doc and the operator context table list it, and the design doc corrects thesynonymsrow, which described the whole query only. The shippedfulltexttemplate's exact-name term still readssynonyms; switching it changes default ranking and needs its own seed revision, so it is left for a follow-up.Tests:
MatchedFieldsTest.testSynonymsOfTheQueryMatchuses an equivalence line from the shipped synonym file where neither word is a prefix or stem of the other, and fails without the change.testMultiWordSynonymWordsDoNotMatchAloneandtestTypedWordsWinOverSynonymscover the phrase and preference rules.SearchTemplateSynonymTest.testWholeQuerySynonymsLeaveOutWordSynonymschecks that a multi-word query's word synonyms stay out ofexactSynonyms, that a phrase synonym is in it, and that a body may branch on it at write time.MatchedFieldsTest.testTypedWordsWinAcrossThePathsOfOneNameandtestAPathListedUnderTwoNamesReportsBoth, andSearchTemplateRequestFlowTest.testALabelKeyKeepsItsNameWhenAnotherLabelReadsIt, cover how a label's paths are grouped;testATypedStoredPathWinsOverASynonymOnTheLabelKeyandtestAHighlightedPathCountsWithTheQueriedPathsOfALabelcover the same rule through the template scan, andtestSynonymsOfShortAndQuotedWordsMatchcovers the folded lookup and the explain output of a synonym match.testExactSynonymsLeaveOutWordSynonymsalso checks thatexactSynonymsfollows the synonym cap. The existing matched-field, request-handler, render, golden and contract tests pass unchanged.A label read from its own key and from stored paths reports a typed match from any of them ahead of a synonym-only one (
MatchedFields.firstPerName, used by the template and stage scans). Each name's paths are listed explicitly, so a label key that another label also reads keeps its own name, and the queried and highlighted label sets give their paths to one scan per label. Within one scan, matches that hold a typed word are reported ahead of synonym-only ones, each group in label order, so a caller that reads the first of several matched labels gets a typed one when there is one (structured-property paths are scanned after the labels); a label matched only through a stored path no longer follows the labels matched on their own key. The synonym catalog now merges a term that appears on several lines, as the analyzers' synonym map does; the shipped synonym file repeats no term, so its expansions do not change. A query whose only words are shorter than the minimum length, such ass3, now fetches the scanned paths when it has a synonym, on the template and non-template V3 paths. The per-path scan behind the non-template V3 search drops a synonym-only value when another path of the same name holds a typed word.In OSS the visible change is the matched-fields report and explain output. A deployment with a match-tier post-process ranks by these fields too: on such an evaluation catalog with spelling-variant synonyms, the two spellings of a two-word query now rank the same top five, and no other ranking assertion changed.