Enable TokenFilters to assign offsets when splitting tokens [LUCENE-8450]
- Dominant language
- Java
- Stars
- 3.6k
- Forks
- 1.4k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 88
Description
CharFilters and TokenFilters may alter token lengths, meaning that subsequent filters cannot perform simple arithmetic to calculate the original ("correct") offset of a character in the interior of the token. A similar situation exists for Tokenizers, but these can call CharFilter.correctOffset() to map offsets back to their original location in the input stream. There is no such API for TokenFilters.
This issue calls for adding an API to support use cases like highlighting the correct portion of a compound token. For example the german word "außerstand" (meaning afaict "unable to do something") will be decompounded and match "stand and "ausser", but as things are today, offsets are always set using the start and end of the tokens produced by Tokenizer, meaning that highlighters will match the entire compound.
I'm proposing to add this method to `TokenStream`:
` public CharOffsetMap getCharOffsetMap();`
referencing a CharOffsetMap with these methods:
` int correctOffset(int currentOff);`
` int uncorrectOffset(int originalOff);`
The uncorrectOffset method is a pseudo-inverse of correctOffset, mapping from original offset forward to the current "offset space".
---
Migrated from [LUCENE-8450](https://issues.apache.org/jira/browse/LUCENE-8450) by Michael Sokolov (@msokolov), 1 vote, updated Aug 20 2018
Attachments: [offsets.patch](https://apache.github.io/lucene-jira-archive/attachments/LUCENE-8450/offsets.patch)
Contributor guide
Research direction
Start by reading TokenStream, CharFilters, TokenFilters, and the attached offsets.patch to understand the proposed CharOffsetMap API. Determine how correctOffset and uncorrectOffset should support highlighting compound-token matches, and consider the existing discussion before defining what a complete implementation would require.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- search
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100