Skip to content

GITHUB#15769: Restore PathHierarchyTokenizer synonym positions for ancestor-path search - #16402

Open
vismaytiwari wants to merge 1 commit into
apache:mainfrom
vismaytiwari:fix/pathhierarchy-ancestor-positions-15769
Open

GITHUB#15769: Restore PathHierarchyTokenizer synonym positions for ancestor-path search#16402
vismaytiwari wants to merge 1 commit into
apache:mainfrom
vismaytiwari:fix/pathhierarchy-ancestor-positions-15769

Conversation

@vismaytiwari

Copy link
Copy Markdown
Contributor

Description

Fixes #15769.

PathHierarchyTokenizer is documented to emit each path prefix at the same position, so that query parsers treat them as synonyms — a query for Books/NonFic/Science/Physics becomes (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 to positionIncrement = 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 = 0 for every token after the first (the first still advances by 1). The alternative floated in the issue — keeping incrementing positions but adding a PositionLengthAttribute — doesn't work: posLen > 1 pushes QueryBuilder onto its graph (isGraph) code path and testAncestorQuery still 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 passes graphOffsetsAreCorrect = false for these inputs. That's consistent with how the tokenizer is already treated elsewhere — it's annotated @IgnoreRandomChains(reason = "broken offsets") and checkRandomData is already called with offsetsAreCorrect = 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.
  • testTokenizerViaAnalyzerOutput and the existing assertTokenStreamContents cases assert the positionIncrement {1, 0, 0, ...} pattern again.

Note for reviewers

GITHUB#12875 made the same positionIncrement = 1 change to ReversePathHierarchyTokenizer, 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.

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PathHierarchyTokenizer "ancestor search" use case broken in lucene >= 10.0

1 participant