Skip to content

Fix position increment in (Reverse)PathHierarchyTokenizer#12875

Merged
mikemccand merged 2 commits intoapache:mainfrom
lukas-vlcek:FixPositionIncrement
Dec 18, 2023
Merged

Fix position increment in (Reverse)PathHierarchyTokenizer#12875
mikemccand merged 2 commits intoapache:mainfrom
lukas-vlcek:FixPositionIncrement

Conversation

@lukas-vlcek
Copy link
Copy Markdown
Contributor

@lukas-vlcek lukas-vlcek commented Dec 4, 2023

Description

Incrementing position attribute for each token in both PathHieararchyTokenizer and ReversePathHieararchyTokenizer.
This change makes it possible to use both tokenizers in BaseTokenStreamTestCase.assertAnalyzesTo() method (test cases extended to demonstrate this).

This PR solves and surpasses #12750.

@msfroh I included your original commit from your Lucene fork to keep proper commit attribution.

Shall we squash all commits?

posAtt.setPositionIncrement(0);
}
posIncAtt.setPositionIncrement(1);
posLenAtt.setPositionLength(1);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Note that 1 is already the default for PositionLengthAttribute so you could skip pulling/setting it.

posAtt.setPositionIncrement(0);
}
posIncAtt.setPositionIncrement(1);
posLenAtt.setPositionLength(1);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same here.

@mikemccand
Copy link
Copy Markdown
Member

Thanks for tackling this @lukas-vlcek and @msfroh! I left a couple small comments, but otherwise it looks great.

Given that this alters the indexed tokens (makes them non-overlapping), I think this should be a 10.0 only change? It's highly unlikely any users are relying on how PhraseQuery or synonyms, etc. (any positional tokenfilters / queries) behave on fieleds analyzed with these tokenizers, but, still, could you add an entry in MIGRATE.txt explaining this change? Note that this should make highlighting based on postings offsets (e.g. UnifiedHighlighter, in certain modes) work on such fields when it does not today.

Also please add a CHANGES.txt entry under 10.0 as well. Thanks!

@lukas-vlcek
Copy link
Copy Markdown
Contributor Author

Note that this should make highlighting based on postings offsets (e.g. UnifiedHighlighter, in certain modes) work on such fields when it does not today.

Ture... so it sounds like we shall add a test for this as well if we want to claim it in the migration notes!

@lukas-vlcek
Copy link
Copy Markdown
Contributor Author

@mikemccand Do you think you can give me some hint about?

(e.g. UnifiedHighlighter, in certain modes)

I am looking at TestUnifiedHighlighter* tests. Does it mean that I need to use specific fieldType? Can I use any fieldType(s) from existing UHTestHelper.parametersFactoryList()? Such as postingsType and postingsWithTvType?

@mikemccand
Copy link
Copy Markdown
Member

I am looking at TestUnifiedHighlighter* tests. Does it mean that I need to use specific fieldType? Can I use any fieldType(s) from existing UHTestHelper.parametersFactoryList()? Such as postingsType and postingsWithTvType?

Hi @lukas-vlcek -- I don't think we need to add a specific unit test to UnifiedHighlighter tests for this. I think it's fine to say something general in the MIGRATE.txt like "(Reverse)PathHieararchyTokenizer now produces sequential (instead of overlapping) tokens with accurate offsets, making positional queries and highlighters possible for fields tokenized with this tokenizer" or so?

msfroh and others added 2 commits December 18, 2023 11:56
PathHierarchyTokenizer was emitting multiple tokens in the same position
with changing offsets. To be consistent with EdgeNGramTokenizer (which
is conceptually similar -- it's emitting multiple prefixes/suffixes off
the input string), we can output every token with length 1 with
positions incrementing by 1.
Making ReversePathHierarchyTokenizer consistent with recent changes in PathHierarchyTokenizer.
@lukas-vlcek
Copy link
Copy Markdown
Contributor Author

@mikemccand Thanks for review. Done!
Shall I squash all commits are will you do it when merging in GH?

@mikemccand
Copy link
Copy Markdown
Member

Thanks @lukas-vlcek -- looks great -- no need to squash, I'll take care during merge. Exciting improvement, finally!

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.

3 participants