View Full Version : mysql match query escape '-'
sir pannels
07-29-2008, 10:18 AM
hi all,
I'm using MySQL match to return some selective results.. in match you can use the + and - symbols to specify to include / exclude words... however I wish to search for a word with a - in part of the word.. does any know how to escape them so the word doesnt get excluded?
Many thanks =]
aquachimera
07-29-2008, 09:12 PM
Have you tried just using \- instead of - ? I haven't tried using it with MySql, but it works to escape other special characters so it's possible it will work in this context too.
derzok
07-30-2008, 05:01 PM
What language are you using? In most languages there exist special mysql escaping functions.
CFMaBiSmAd
07-30-2008, 05:11 PM
To start with, a "word" that contains a "-" is not one word. It is two words with a "-" separator between them.
From the MATCH section in the mysql manual -
If you want to change the set of characters that are considered word characters, you can do so in two ways. Suppose that you want to treat the hyphen character ('-') as a word character. Use either of these methods:
Modify the MySQL source: In 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 <ctype><map> contents in one of the character set XML files to specify that '-' is a “letter.” Then use the given character set for your FULLTEXT indexes.
After making the modification, you must rebuild the indexes for each table that contains any FULLTEXT indexes.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.