Skip to content

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

Merged
mergify[bot] merged 2 commits into
matrixorigin:2.1-devfrom
cpegeric:fulltext_skip_overlap_2_1
May 8, 2025
Merged

mergify[bot] merged 2 commits into
matrixorigin:2.1-devfrom
cpegeric:fulltext_skip_overlap_2_1

Conversation

@cpegeric

@cpegeric cpegeric commented May 7, 2025

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.

volgariver6 pushed a commit to volgariver6/matrixone that referenced this pull request May 14, 2025
…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
aressu1985 pushed a commit that referenced this pull request May 14, 2025
…21844)

## What type of PR is this?

- [ ] API-change
- [x] 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.

Co-authored-by: Eric Lam <[email protected]>

This branch was previously deployed

1 inactive deployment
ci — 9ba7db22 Deployed May 8, 2025 by mergify[bot]
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 size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants