Skip to content

[Bug]: classic fulltext BOOLEAN quotes only form a phrase when they wrap the entire search string #29289

Closed as not planned

Description

@Ariznawlll

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

main

Commit ID

66da387

Other Environment Information

  • Hardware parameters: Apple Silicon
  • OS type: macOS
  • Others: Reproduced on a local mo-service (SELECT version() = 8.0.30-MatrixOne-v1.3.0) at 127.0.0.1:6001. pkg/fulltext/fulltext.go and pkg/fulltext/sql.go on origin/main at the commit above contain the scanner and SQL generator cited below.

Actual Behavior

Classic fulltext BOOLEAN mode turns double quotes into a phrase only when they wrap the entire search string.

ParsePatternInBooleanMode (pkg/fulltext/fulltext.go) calls ParsePhrase only when strings.HasPrefix(pattern, "\"") && strings.HasSuffix(pattern, "\""). GetOp leaves the '"' arm commented out, so an internal quote is an ordinary character. The boolean scanner then ends the token at the first space inside the quotes.

GenTextSql re-tokenizes each piece in natural-language mode, which treats " as a breaker and drops it. No phrase anchor (pos - N / HAVING COUNT(*)) is generated. MATCH returns success rows that are not the phrase.

Live results on default, ngram, and gojieba (same four rows: matrix database, matrix origin here, origin matrix, database only):

AGAINST pattern Actual ids Expected ids
"matrix origin" 2 2
+"matrix origin" 1, 2, 3 2
"matrix origin" database 1, 2, 3, 4 1, 2, 4
+"matrix origin" +database 1 empty

+"matrix origin" requires the word matrix and treats origin as optional, so every document containing matrix matches. "matrix origin" database becomes a bag-of-words OR, so origin matrix (id 3) matches even though it is not the phrase and does not contain database. +"matrix origin" +database requires matrix AND database and returns matrix database.

The scanner runs before parser-specific logic, so the json parser takes the same split.

Expected Behavior

"" is a documented BOOLEAN operator together with +, -, *, and ~ (CREATE FULLTEXT INDEX). A quoted span is one phrase wherever it sits in the expression:

  • +"matrix origin" returns only documents that contain the adjacent phrase matrix origin.
  • "matrix origin" database returns documents that contain that phrase or the word database.
  • +"matrix origin" +database returns only documents that contain both the phrase and database.

Whole-string "matrix origin" already does this and is not the bug.

Steps to Reproduce

drop database if exists ft_quote_probe;
create database ft_quote_probe;
use ft_quote_probe;
create table src(id bigint primary key, body varchar(200));
create fulltext index ft on src(body);
insert into src values
  (1, 'matrix database'),
  (2, 'matrix origin here'),
  (3, 'origin matrix'),
  (4, 'database only');

select id from src where match(body) against('"matrix origin"' in boolean mode) order by id;
-- 2

select id from src where match(body) against('+"matrix origin"' in boolean mode) order by id;
-- actual: 1, 2, 3    expected: 2

select id from src where match(body) against('"matrix origin" database' in boolean mode) order by id;
-- actual: 1, 2, 3, 4    expected: 1, 2, 4

select id from src where match(body) against('+"matrix origin" +database' in boolean mode) order by id;
-- actual: 1    expected: empty

WITH PARSER ngram and WITH PARSER gojieba produce the same +"matrix origin" result (ids 1, 2, 3). Whole-string "matrix origin" on those parsers still returns only id 2.

The pattern tree for +"matrix origin" is (+ (text "matrix)) (text origin"). SqlBoolean emits a required word = 'matrix' posting and UNIONs the optional origin term. The whole-string pattern "matrix origin" emits word = 'matrix' at pos - 0 UNION word = 'origin' at pos - 7 with HAVING COUNT(*) = 2.

Additional information

Cause is the whole-string guard in ParsePatternInBooleanMode and the commented-out '"' arm in GetOp (pkg/fulltext/fulltext.go). GenTextSql (pkg/fulltext/sql.go) then strips the leftover quote characters, so the posted SQL looks like a normal word search.

This is not #29271. #29271 is the whole-string ParsePhrase path looking up the raw quoted text instead of the index tokenizer. Here the quotes never become a PHRASE node, and the query returns extra rows.

Unquoted +matrix +origin correctly returns ids 2 and 3. That control is not this bug.

Activity

  1. added this to the MO-202609 milestone on Sep 23, 2026
  2. added
    kind/bug
    on Sep 23, 2026
  3. added theissue type on Sep 23, 2026
  4. Ariznawlll commented on Sep 23, 2026

    @Ariznawlll
    CollaboratorAuthor

    Same scanner, one more successful wrong row. A minus in front of the quotes does not exclude the phrase; it excludes the individual words.

    On

    CREATE TABLE p (id INT PRIMARY KEY, body VARCHAR(128));
    CREATE FULLTEXT INDEX fp ON p (body);
    INSERT INTO p VALUES
      (1, 'matrix database'),
      (2, 'matrix origin here'),
      (3, 'origin matrix'),
      (4, 'database only');

    MATCH(body) AGAINST('+database -"matrix origin"' IN BOOLEAN MODE) returns only id 4.

    id 1 contains database and does not contain the phrase matrix origin, so it should be returned. It is dropped because the quotes are not parsed as a phrase: the minus is applied to matrix, and EvalMinus removes every document that contains that word.

    -"matrix origin" alone returns empty. A minus-only boolean query is empty either way, so that statement does not add a separate symptom.

  5. added
    severity/s0
    and removed on Sep 23, 2026
  6. cpegeric commented on Sep 24, 2026

    @cpegeric
    Contributor

    there is no such thing in boolean mode. '"matrix origin" database' does not work. please close it.

  7. Ariznawlll commented on Sep 27, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:5be6cd90b501da225be591ffffe6000bf01f515e
    • 部署方式:本地单机(1 CN / 1 TN / 1 LogService)
    • 测试日期:2026-09-27

    原问题验证

    按 issue 原始 classic fulltext SQL 在最新 main 上独立执行 3 次,3/3 与研发在 issue comment 中确认的产品契约一致。本结论是设计确认,不表示 classic fulltext 行为被改写。

    Happy Path 覆盖

    1. whole-string quoted phrase 返回 id 2;内部 quote 组合按 classic boolean scanner 的现有语义返回研发确认的结果。

    Unhappy Path 覆盖

    1. 覆盖 +"..."、quoted phrase 加普通词及双 required 组合;该语法不作为受支持的 phrase 组合。

    白盒验证

    对照 issue 中研发的 WON'T FIX/按设计说明,并核对 classic fulltext 当前 parser/index 路径;实测结果与说明一致。

    回归测试

    未加入 MOTR:该行为是 classic fulltext 的已确认设计/限制,研发同时指向 FULLTEXT2 作为正确实现方向;不新增 classic 内部细节的兼容承诺。

    测试证据

    • MatrixOne main commit:5be6cd90b501da225be591ffffe6000bf01f515e
    • 原始 SQL:本地连续 3 次结果一致
    • 研发契约:当前 issue 内 comment

    测试结论

    测试通过。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions