Robert Stepanek
2024-Jan-04 16:50 UTC
Possible bug using FLAG_WORD_BREAKS with fullwidth Unicode codepoints
I think I found a bug in Xapian 1.5 when using FLAG_WORD_BREAKS for input that contains characters in Unicode Halfwidth and Fullwidth Forms (https://unicode.org/charts/PDF/UFF00.pdf). Since I am undecided yet if and how to fix this in Xapian I haven't come up with a pull request. Because trac currently is offline, I could not file a bug. I hope it's OK to post my analysis here first, I'll be happy to follow up reporting that bug proper later (should we conclude that it actually is a bug). Imagine indexing the following Japanese text "??????????????" which in English denotes the "Mitsubishi UFJ Factors Limited" bank. Using word segmentation in Xapian 1.5 this causes the following terms to get indexed: ????? ?? ???? ??? Note that last term, which starts with FULLWIDTH LATIN CAPITAL LETTER U' (U+FF35). Xapian's Unicode library correctly assigns this the UPPERCASE_LETTER category and indexes this verbatim. However, querying for ??? produces the query Query(???@1). That is, it queries for the lowercase form which seems to be the result of unconditional lower-casing at https://github.com/xapian/xapian/blob/master/xapian-core/queryparser/queryparser.lemony#L1459. As a result, the query returns no result. I have written code that demonstrates this at https://gist.github.com/rsto/168a61536793e10a0a07c3920977e5eb Now, I think that much of this issue can be prevented by normalizing both indexed text and queries before passing them over the Xapian, but this requires to rewrite indexes so isn't necessarily a quick fix. As a workaround, I chose to detect such queries and query for both the lower-cased and original uppercase forms in our systems. Still, I do think it is a bug for Xapian not to return a result when querying for a term that's verbatim in the original input and the database. Should you agree I will be happy to discuss how to fix this and might come up with a pull request once we agreed on a solution. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.xapian.org/pipermail/xapian-devel/attachments/20240104/19872ad8/attachment.htm>
Olly Betts
2024-Jan-07 18:45 UTC
Possible bug using FLAG_WORD_BREAKS with fullwidth Unicode codepoints
On Thu, Jan 04, 2024 at 05:50:22PM +0100, Robert Stepanek wrote:> Since I am undecided yet if and how to fix this in Xapian I haven't > come up with a pull request. Because trac currently is offline, I > could not file a bug. I hope it's OK to post my analysis here first, > I'll be happy to follow up reporting that bug proper later (should we > conclude that it actually is a bug).I've restarted trac.> Still, I do think it is a bug for Xapian not to return a result when > querying for a term that's verbatim in the original input and the > database. Should you agree I will be happy to discuss how to fix this > and might come up with a pull request once we agreed on a solution.I think the cause is that the list of ranges of characters which need word breaks findings includes this block of full- and half-width latin forms, coupled with an assumption that there's no lowercase vs uppercase forms in these alphabets. Assuming the latter is valid, just removing this block (or removing the parts of it which are Lu or Ll) should fix the problem as then tokenisation will switch mode - I tried this and it fixes your case at least: diff --git a/xapian-core/queryparser/word-breaker.cc b/xapian-core/queryparser/word-breaker.cc index 8108523ccd53..4fabc23f4b56 100644 --- a/xapian-core/queryparser/word-breaker.cc +++ b/xapian-core/queryparser/word-breaker.cc @@ -103,7 +103,7 @@ is_unbroken_script(unsigned p) // FE30..FE4F; CJK Compatibility Forms 0xFE30 - 1, 0xFE4F, // FF00..FFEF; Halfwidth and Fullwidth Forms - 0xFF00 - 1, 0xFFEF, + //0xFF00 - 1, 0xFFEF, // 1AFF0..1AFFF; Kana Extended-B // 1B000..1B0FF; Kana Supplement // 1B100..1B12F; Kana Extended-A If we're fixing it this way we should check this list for other instances of this (and doing this would probably reveal if that assumption is valid). Cheers, Olly
Apparently Analagous Threads
- Possible bug using FLAG_WORD_BREAKS with fullwidth Unicode codepoints
- Possible bug using FLAG_WORD_BREAKS with fullwidth Unicode codepoints
- Possible bug using FLAG_WORD_BREAKS with fullwidth Unicode codepoints
- Possible bug using FLAG_WORD_BREAKS with fullwidth Unicode codepoints
- patch - Some CJK codepoints are also punctuation