使用utf8进行MySQL全文搜索(波斯语/阿拉伯语) [英] MySQL Full Text Search with utf8 (Persian/Arabic)

查看:137
本文介绍了使用utf8进行MySQL全文搜索(波斯语/阿拉伯语)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在UTF8 / Unicode波斯语/阿拉伯语(全部查询中没有发现)的全文搜索时遇到问题。


  • 表格在编码时设置为utf8 / utf8_persian_ci。

  • 对于Unicode Querys,使用 mysql_query(SET NAMES'UTF8');
  • 英文字符串正常工作。



以下是我的搜索代码: b

 <?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 =textname =qvalue =<?php echo $ q;?>>
< input type =submitvalue =Search!>
< / form>
< hr>
<?php
if(isset($ q))
{
$ res = mysql_query(SELECT *,MATCH(name,description)AGAINST('$ q' )来自search_test的AS得分WHERE MATCH(名称,描述)通过得分desc反对('$ q')排序);
$ ant = mysql_num_rows($ res);
if($ ant> 0)
{//查询提供的结果 - 显示结果
echo(< br />< h2> \\ q的搜索结果$ q \ :其中/ H2> 中);
while($ result = mysql_fetch_array($ res))
{
echo(< h3> {$ result ['name']}({$ result ['score']} )< / H3> {$结果[ '描述']}<峰; br /><峰; br />中);

$ b $ else
{//查询提供了0个结果 - 显示0个命中消息
echo(< br />< h2>没有找到\$ q \查询< / h2>);
}
}
?>

问题在哪里,或者如何在Unicode上使用全文搜索语言?

解决方案

索引列必须<= 1000字节编码。



您无法对波斯语字母进行FULLTEXT搜索,因为它具有> 1000字节的编码。正如此处所述。



例如您的آزمایشی具有以下字符编码字节映射:

数组

[0] => 1570
[1] => 1586
[2] => 1605
[3] => 1575
[4] => 1740
[5] => 1588
[6] => 1740


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 ?

解决方案

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
)

这篇关于使用utf8进行MySQL全文搜索(波斯语/阿拉伯语)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆