apache / apache/lucene

ICU Tokenizer: letter-space-number-letter tokenized inconsistently [LUCENE-9754]

Open
#10,793 12 comments 0 reactions 0 assignees View on GitHub
affects-version:7.5 legacy-jira-priority:Major module:core/search type:bug
Dominant language
Java
Stars
3.6k
Forks
1.4k
Avg merge
2d 11h
Merged PRs (30d)
88

Description

The tokenization of strings like _14th_ with the ICU tokenizer is affected by the character that comes before preceeding whitespace.

For example, _x 14th_ is tokenized as x | 14th; _ァ 14th_ is tokenized as ァ | 14 | th.

In general, in a letter-space-number-letter sequence, if the writing system before the space is the same as the writing system after the number, then you get two tokens. If the writing systems differ, you get three tokens.

~~If the conditions are just right, the chunking that the ICU tokenizer does (trying to split on spaces to create <4k chunks) can create an artificial boundary between the tokens (e.g., between _ァ_ and _14th_) and prevent the unexpected split of the second token (_14th_). Because chunking changes can ripple through a long document, editing text or the effects of a character filter can cause changes in tokenization thousands of lines later in a document.~~ _(This inconsistency was included as a side issue that I thought might add more weight to the main problem I am concerned with, but it seems to be more of a distraction. Chunking issues should perhaps be addressed in a different ticket, so I'm striking it out.)_

My guess is that some "previous character set" flag is not reset at the space, and numbers are not in a character set, so _t_ is compared to _ァ_ and they are not the same—causing a token split at the character set change—but I'm not sure.

---
Migrated from [LUCENE-9754](https://issues.apache.org/jira/browse/LUCENE-9754) by Trey Jones, updated Mar 04 2021
Environment:
```
Tested most recently on Elasticsearch 6.5.4.
```

Attachments: [LUCENE-9754_prototype.patch](https://apache.github.io/lucene-jira-archive/attachments/LUCENE-9754/LUCENE-9754_prototype.patch)

Contributor guide

Open the contributing guide

Research direction

Start with the ICU tokenizer and reproduce the reported token streams for “x 14th” and “ァ 14th”. Trace why the letter-space-number-letter sequence differs by writing system, then verify that equivalent inputs are tokenized consistently without changing the separate chunking concern.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
search
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.