开发者

mysql searching phrase using match againts with INsensitive case

开发者 https://www.devze.com 2023-02-20 05:06 出处:网络
To introduce the question, mysql doc reads : quoted strings in Match/Against clause are Case Sensitive...

To introduce the question, mysql doc reads :

quoted strings in Match/Against clause are Case Sensitive...

My datas :

INSERT INTO table.col VALUES ('this 开发者_Python百科is a custom phrase to match');

My query :

SELECT * FROM table
WHERE MATCH ( col1,..,col10 ) AGAINST ('"Custom Phrase"' IN BOOLEAN MODE)  

This doesn't match because of case.


I'm looking for a way to use this query in a case INsensitive way

Something where these phrases will all matches the data :

  • "custom phrase"
  • "Custom Phrase"
  • "CUSTOM PHRASE"
  • "CuStOm PhRAsE"

Any help is welcome, thank you in advance ^^


Read the end of this (http://bugs.mysql.com/bug.php?id=22343) which says that this is by-design, because you have mixed different column types.

If you must search across columns, convert them all (including specifying collation during conversion) to text types on the left side of the MATCH.


MySQL Reference states that by default with latin1 nonbinary collation is case insensitive. Looks like you can also use the collate function to force a specific setting (either case insensitive or case sensitive).


Thanx for your help

As i was facing another problem with fulltext indexes that can't contains more than 16 columns (while i need 33 columns to be matched) i decided to use another way :

(a solution that appears a lot when it comes about fulltext search)

  1. I concatenate all the columns of a row in a string, which I convert to lowercase.

  2. I save this string in a newly added column (type longtext, with a fulltext index on it)column which is dedicated solely to this FT search and updated after every insert/update query.

  3. Now I need to pass lowercase terms to the AGAINST clause, while using the BOOLEAN MODE. With all datas to lowercase, case sensitive search is no more a problem.

    SELECT * FROM table WHERE MATCH ( longtextcol ) AGAINST ('"a lowercase phrase" lowercaseword1 lowercaseword2')

Thanks for your replies ^^

0

精彩评论

暂无评论...
验证码 换一张
取 消