I have installed sphinx on my server, indexed it and running query successfully. I am using sphinxrt code from https://github.com/andrew-s/codeigniter-sphinxrt to search but, it always give me the search for exact phrase. I am not able to search as we do in the sql like query.I have also build the search in php file with the Sphinxql foolz code and that was working perfectly giving me the result as we have in like. I just want same result in the codeigniter also.
Asked
Active
Viewed 946 times
0
-
please share the actual code you running. – barryhunter Sep 09 '15 at 15:12
-
$result = $this->sphinxrt->search('people', array('search' => 'john', 'limit' => 100, 'start' => 0 )); This what i am using for searching. – HKumar Sep 10 '15 at 06:21
-
If you are searching for a single word 'john' how are you getting match for phrase? Thats not a phrase? Think you need to explain more exactly what your problem actully is. – barryhunter Sep 10 '15 at 09:26
-
My problem was that to get record with the name "John Leo" in the search result, I have to give complete name "John" in the search box, where the name should be populate when i type "joh" – HKumar Sep 10 '15 at 09:31
1 Answers
0
I check the code in the library for sphinxrt. You will find a function named as _escape($string), just modify the return value as return '\'^' . (string)$string . '*\''
then it will search wild card for any value start or end with the keyword.

HKumar
- 1,535
- 3
- 13
- 28
-
Note that ^ is the field start operator, not a wildcard. So it will require the first word of your search query, to be the first world in the field. The last word in the query (also first if only one keyword!), will have the * on the end. So could match part words. – barryhunter Sep 10 '15 at 11:52
-
Yes, you are right. I have just check for this. Can you please tell me what should I do get result like '%$name%'. – HKumar Sep 10 '15 at 14:16
-
Its very hard to exactly minic a LIKE like that, sphinx is something very different, its a inverse index, based on tokenized words. ie the input data is tokenized and stored. Not just as a simple string (like a varchar in a database) The closest would be `"*{$string}*"` which is a phrase match combined with wildcards. But would still be subject to charset_table rules, not an exact charactor match. – barryhunter Sep 10 '15 at 14:29
-
I have tried using "*{$string}*" but with this its only search for the complete word not a part of it – HKumar Sep 15 '15 at 07:03