GITHUB#15769: Restore PathHierarchyTokenizer synonym positions for ancestor-path search - #16402
Open
vismaytiwari wants to merge 1 commit into
Open
Conversation
…e position Restore the synonym positions (positionIncrement 0 after the first token) that GITHUB#12875 replaced with 1. Query parsers again treat the emitted path tokens as synonyms rather than a phrase, so the documented "ancestor path" search works as designed again. The tokenizer test now calls assertAnalyzesTo with graphOffsetsAreCorrect=false, since the overlapping-prefix offsets are legitimate but do not form a valid graph, and adds ancestor/descendant query regression tests based on Hoss Man's patch from the issue.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #15769.
PathHierarchyTokenizeris documented to emit each path prefix at the same position, so that query parsers treat them as synonyms — a query forBooks/NonFic/Science/Physicsbecomes(Books OR Books/NonFic OR Books/NonFic/Science OR Books/NonFic/Science/Physics). That "ancestor path" use case has been broken since 10.0: GITHUB#12875 (5d6086e) changed every token topositionIncrement = 1, so the parser now builds a phrase instead and the query matches nothing.As @hossman points out in the issue, GITHUB#12875 was motivated purely by making the tokenizer pass
assertAnalyzesTo(), not by any real-world problem, and it silently regressed the documented behavior.This restores
positionIncrement = 0for every token after the first (the first still advances by 1). The alternative floated in the issue — keeping incrementing positions but adding aPositionLengthAttribute— doesn't work:posLen > 1pushesQueryBuilderonto its graph (isGraph) code path andtestAncestorQuerystill fails. Plain synonyms are what the design intended and what the query builders expect.The one cost is that the overlapping-prefix offsets are not a valid token graph, so
assertAnalyzesTo()can't validate them under its strict graph-offset check. The tokenizer test passesgraphOffsetsAreCorrect = falsefor these inputs. That's consistent with how the tokenizer is already treated elsewhere — it's annotated@IgnoreRandomChains(reason = "broken offsets")andcheckRandomDatais already called withoffsetsAreCorrect = false.Tests
testAncestorQuery/testDescendantQuery: end-to-end regression tests for both documented use cases (adapted from Hoss Man's patch on the issue), asserting exact hit counts.testTokenizerViaAnalyzerOutputand the existingassertTokenStreamContentscases assert thepositionIncrement{1, 0, 0, ...}pattern again.Note for reviewers
GITHUB#12875 made the same
positionIncrement = 1change toReversePathHierarchyTokenizer, which likely has the same latent problem for its mirror use case. I kept this PR scoped to the forward tokenizer that #15769 is about — happy to follow up on the reverse one separately if that's wanted.