Search code examples
phpmysqlpdosphinxql

Sphinxql with 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.


Solution

  • 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.