MySQL Full Text Period

后端 未结 2 1431
逝去的感伤
逝去的感伤 2021-01-24 05:23

I have a table of product names, and full text works great up until using a period, e.g. searching for a 3.7 battery.. i try

select .. where match(name) against          


        
相关标签:
2条回答
  • 2021-01-24 05:28

    As documented under Fine-Tuning MySQL Full-Text Search:

    You can change the set of characters that are considered word characters in several ways, as described in the following list. After making the modification, rebuild the indexes for each table that contains any FULLTEXT indexes. Suppose that you want to treat the hyphen character ('-') as a word character. Use one of these methods:

    • Modify the MySQL source: In storage/myisam/ftdefs.h, see the true_word_char() and misc_word_char() macros. Add '-' to one of those macros and recompile MySQL.

    • Modify a character set file: This requires no recompilation. The true_word_char() macro uses a “character type” table to distinguish letters and numbers from other characters. . You can edit the contents of the <ctype><map> array in one of the character set XML files to specify that '-' is a “letter.” Then use the given character set for your FULLTEXT indexes. For information about the <ctype><map> array format, see Section 10.3.1, “Character Definition Arrays”.

    • Add a new collation for the character set used by the indexed columns, and alter the columns to use that collation. For general information about adding collations, see Section 10.4, “Adding a Collation to a Character Set”. For an example specific to full-text indexing, see Section 12.9.7, “Adding a Collation for Full-Text Indexing”.

    0 讨论(0)
  • 2021-01-24 05:32
    where match(name) against ('+battery' in boolean mode)
      AND name LIKE '%3.7v%'
    

    This requires some intelligence in your app when constructing the query.

    Other variants:

    This makes sure the 3.7v is next to battery:

    where match(name) against ('+battery' in boolean mode)
      AND name LIKE '%3.7v battery%'
    

    This makes sure it has word boundaries around it:

    where match(name) against ('+battery' in boolean mode)
      AND name REGEXP '[[:<:]]3.7v[[:>:]]'
    
    0 讨论(0)
提交回复
热议问题