问题
I have problem with full text search just on UTF8/Unicode Persian/Arabic Language (nothing found from querys).
- Tables are set with utf8/utf8_persian_ci on encoding.
- Using
mysql_query("SET NAMES 'UTF8'");for Unicode Querys. - English strings work fine.
Below is My search codes:
<?php
mysql_connect("localhost", "user", "password");
mysql_select_db("search");
mysql_query("SET NAMES 'UTF8'");
$q = $_GET['q'];
?>
<form action="<?php $_SERVER['PHP_SELF']; ?>">
<input type="text" name="q" value="<?php echo $q; ?>">
<input type="submit" value="Search!">
</form>
<hr>
<?php
if (isset($q))
{
$res = mysql_query("SELECT *, MATCH(name, description) AGAINST ('$q') AS score from search_test WHERE MATCH (name, description) AGAINST('$q') order by score desc");
$ant = mysql_num_rows($res);
if ($ant > 0)
{ // query provided results – display results
echo ("<br/><h2>Search results for \"$q\":</h2>");
while ($result = mysql_fetch_array($res))
{
echo ("<h3>{$result['name']} ({$result['score']})</h3>{$result['description']}<br/><br/>");
}
}
else
{ // query provided 0 results – display 0 hit message
echo ("<br/><h2>Nothing Found \"$q\" query</h2>");
}
}
?>
where is the problem or how can I search with full-text on Unicode language ?
回答1:
Indexed columns must <= 1000 byte encoding.
You cannot do a FULLTEXT search on Persian letters as the have > 1000 byte encoding. As it is stated here.
for example your آزمایشی has the following character encoding bytes map:
Array
(
[0] => 1570
[1] => 1586
[2] => 1605
[3] => 1575
[4] => 1740
[5] => 1588
[6] => 1740
)
回答2:
MySQL fulltext search works well for Persian. Just make sure of the following where needed:
COLLATION = utf8_persian_ci&CHARACTER SET = utf8. (Databases, Tables, and Columns).- Index words of 3 letters and more. This is Very Important for Arabic,
ft_min_word_len = 3(seeshow variables like "ft_%";) - Check the version of MySQL (5.5 or 5.6), and Engine (InnoDb or MyISAM)
来源:https://stackoverflow.com/questions/12073163/mysql-full-text-search-with-utf8-persian-arabic