Redis以冒号(:)结束时未完成搜索

时间:2014-08-28 16:08:34

标签: php redis

我正在尝试对已排序的集进行自动完成搜索。当输入以$ input =“00:”之类的冒号结束时,它实际上不会完成搜索。我可以使用双引号并围绕输入,它可以工作,但搜索时间从2毫秒到15秒。

 $input = "00:2" works in 2ms
 $input = "00:" doesnt work
 $input = '"00:"'; works in 15 seconds


 function getNextChar($char) {
     $char++;
     if(strlen($char) > 1) { $char--; }
     return $char;
 }

 function getLexicalAutocomplete($redis, $dictionaryKey, $input) {
     $inputNext = substr($input, 0, -1) . getNextChar(substr($input, -1)); //ab -> ac

     $redis->zadd($dictionaryKey, 0, $input);
     $redis->zadd($dictionaryKey, 0, $inputNext);

     $rangeStart = $redis->zrank($dictionaryKey, $input)+1;
     $rangeEnd = $redis->zrank($dictionaryKey, $inputNext)-1;

     $autocompleteResults = $redis->zrange($dictionaryKey, $rangeStart, $rangeEnd);

     $redis->zrem($dictionaryKey, $input);
     $redis->zrem($dictionaryKey, $inputNext);

     return $autocompleteResults;
 }

0 个答案:

没有答案