Skip to content

BUG FIX: Fulltext skip overlap from N-gram output 2.1-dev (#21799) - #21844

Merged
aressu1985 merged 1 commit into
matrixorigin:v2.1.1-hotfixfrom
volgariver6:full-text-fix
May 14, 2025
Merged

aressu1985 merged 1 commit into
matrixorigin:v2.1.1-hotfixfrom
volgariver6:full-text-fix

Conversation

@volgariver6

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #21678 #21774

What this PR does / why we need it:

3-gram output is usually overlap each other. Overlap is essential for building index but it is not necessary and also introduce super complicated SQL. For query, remove the unnecessary overlap from N-gram output is a must.

e.g.

The query should not have any overlap.
{
pattern: "肥胖的原因都是因为摄入脂肪多导致的吗",
expect: "(text 0 0 肥胖的) (text 1 9 原因都) (text 2 18 是因为) (text 3 27 摄入脂) (text 4 36 肪多导) (text 5 45 致的吗)", },

We also need to remove the overlap intelligently.

e.g. "读写汉字"

With N-gram, we will have tokens "读写汉", "写汉字", "汉字, "字".

Simple way is to look for overlap sequentially and remove the overlap. The result will be "读写汉" and "字". However, "字" is a single character which require prefix_eq("字") in SQL.

The optimal tokens should be longest token, such as "读写汉", "写汉字" as a result.

In boolean mode,

we change
WITH t00 AS ( SELECT doc_id FROM _mo_index_secondaryWHERE word = '读书会') to
WITH t00 AS ( SELECT doc_id FROM _mo_index_secondaryWHERE word = '读书会' GROUP BY doc_id) and t01, t02 as well, adding the group by. Then t0 will have only 1 row.

…in#21799)

3-gram output is usually overlap each other. Overlap is essential for building index but it is not necessary and also introduce super complicated SQL. For query, remove the unnecessary overlap from N-gram output is a must.

e.g.

The query should not have any overlap.
{
pattern: "肥胖的原因都是因为摄入脂肪多导致的吗",
expect: "(text 0 0 肥胖的) (text 1 9 原因都) (text 2 18 是因为) (text 3 27 摄入脂) (text 4 36 肪多导) (text 5 45 致的吗)",
},

We also need to remove the overlap intelligently.

e.g. "读写汉字"

With N-gram, we will have tokens "读写汉", "写汉字", "汉字, "字".

Simple way is to look for overlap sequentially and remove the overlap. The result will be "读写汉" and "字".
However, "字" is a single character which require prefix_eq("字") in SQL.

The optimal tokens should be longest token, such as "读写汉", "写汉字" as a result.

In boolean mode,

we change
WITH t00 AS ( SELECT doc_id FROM _mo_index_secondaryWHERE word = '读书会')
to
WITH t00 AS ( SELECT doc_id FROM _mo_index_secondaryWHERE word = '读书会' GROUP BY doc_id)
and t01, t02 as well, adding the group by. Then t0 will have only 1 row.

Approved by: @fengttt, @XuPeng-SH, @heni02
@volgariver6
volgariver6 requested a review from aressu1985 as a code owner May 14, 2025 10:37
@volgariver6
volgariver6 requested a review from a user May 14, 2025 10:37
@volgariver6
volgariver6 requested a review from fengttt as a code owner May 14, 2025 10:37
@mergify
mergify Bot requested a review from XuPeng-SH May 14, 2025 10:37
@mergify mergify Bot added the kind/bug Something isn't working label May 14, 2025
@aressu1985
aressu1985 merged commit 51fb416 into matrixorigin:v2.1.1-hotfix May 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants