我很确定应该有一种方法来在MyISAM表中使用全文索引搜索主题标签.默认设置将执行以下操作:

textfield 
hashtag
#hashtag
#two #hashtag #hashtag

SELECT * FROM table WHERE MATCH(textfield) AGAINST ('#hashtag')
> | hashtag                |
> | #hashtag               |
> | #two #hashtag #hashtag |

虽然它应该只返回第2和第3行.看起来hashtag被视为单词分隔符,因此在搜索开始之前它被“删除”.我该怎么做才能启用索引并搜索包含#作为单词一部分的术语?

解决方法:

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 07001.
  • 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 07002. For an example specific to full-text indexing, see 07003.

标签: mysql, full-text-search, myisam, hashtag

相关文章推荐

添加新评论,含*的栏目为必填