dsk920417 2015-12-27 11:25
浏览 86
已采纳

Sphinxql与PDO php

I am integrating Sphinxsearch into my site, and rewriting my old code to use Sphinx. The problem i got is with special characters inside MATCH in SphinxQL.
Example : want to search for H&M
With plain mysql i get thousand of records, so im quite sure i got title's containing that word in my database.
I don't need extended query syntax in MATCH.

$q = "h&m";  
$spxq = "SELECT * FROM sphinx_index WHERE MATCH(:query) LIMIT 0,10";  
$stmt = $DB->prepare($spxq);  
$stmt->bindValue(':query', $q, PDO::PARAM_STR);  
$stmt->execute();  
$res = $stmt->fetchAll(PDO::FETCH_ASSOC); 

This isn't returning any results.
After this i tried escaping $q so :

$q = "h\&m";

Still not working.Tried with double escaping too, still not working.
Any help would be appriciated.

  • 写回答

1条回答 默认 最新

  • douwen9534 2016-01-16 07:42
    关注

    Ok, i got this, if anyone in the future has this same problem. The solution is to add the special characters you want to be able to search for in the sphinx.conf file, in the charset_table.

    So for my case of H&M, you need to add the & character (U+026) in to the charset table.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题