未显示单字符搜索的结果

时间:2017-11-30 07:44:17

标签: php mysql sphinx

我正在尝试使用sphinx / php在控制台上查看单字符搜索结果的结果。但它没有显示结果。理想情况下应该将所有结果从特定字符开始

标签表

的MySQL> select * from tags;

+ -------- + --------- + -------------------- +

| tag_id |关键字| belongsstotablename |

+ -------- + --------- + -------------------- +

| 1 |鹿|物种|

| 2 |狩猎|活动|

+ -------- + --------- + -------------------- +

2行(0.00秒)

Php文件

<?php
include_once 'sphinxapi.php';
// Build search query
$cl = new SphinxClient();
$cl->SetServer('127.0.0.1', 9312);
$cl->SetMatchMode(SPH_MATCH_EXTENDED);
$cl->SetRankingMode (SPH_RANK_SPH04);
// Execute the query
$query = 'hun';
$partialQueryStr = " @keyword $query";
$cl->AddQuery($partialQueryStr, 'customsearch');
$result = $cl->RunQueries();
print_r($result);

if ( $result === false ) {
      echo "Query failed: " . $cl->GetLastError() . ".\n";
  }
  else {
      if ( $cl->GetLastWarning() ) {
          echo "WARNING: " . $cl->GetLastWarning() . "<br>";
      }

        if ($result['matches'] > 0) {
            print_r($result['matches']);        
        } else {
                echo 'No results found';        
        }
  }
exit;
?>

sphinx.conf中

    source customsearch {
    type = mysql
    sql_host = localhost
    sql_user = root
    sql_pass = hello123
    sql_db = testsphinx
    sql_port = 3306

    sql_query = \
                SELECT \
                UUID_SHORT() AS sphinxid, \
                tg.keyword AS keyword, \
                tg.belongstotablename AS ref \
                FROM tags AS tg;

    sql_attr_uint = sphinxid
    sql_field_string = keyword
    sql_field_string = ref
    }

    index customsearch {
        source = customsearch
        path = /etc/sphinx/data/customsearch
        docinfo                 = extern
        dict                    = keywords
        morphology              = stem_en
        #morphology             = soundex
        min_stemming_len        = 1
        min_prefix_len          = 1
    }

    searchd {
    listen = 9312
    listen = 9306:mysql41
    log = /home/xxx/www/log/searchd.log
    query_log = /home/xxx/sphinx/log/query.log
    read_timeout = 5
    max_children = 30
    pid_file = /home/xxx/sphinx/log/searchd.pid
    preopen_indexes = 1
    unlink_old = 1
    }

    indexer
    {
        mem_limit       = 136M
    }

控制台结果

vikas@vikas-pc:~$ php /www/fwv2/php/search/practicesearch.php 
Array
(
    [0] => Array
        (
            [error] => 
            [warning] => 
            [status] => 0
            [fields] => Array
                (
                    [0] => keyword
                    [1] => ref
                )

            [attrs] => Array
                (
                    [keyword] => 7
                    [ref] => 7
                )

            [total] => 0
            [total_found] => 0
            [time] => 0.000
            [words] => Array
                (
                    [hun] => Array
                        (
                            [docs] => 0
                            [hits] => 0
                        )

                )

        )

)
PHP Notice:  Undefined index: matches in /home/xxx//practicesearch.php on line 24
No results found

根据我的理解,它应该为“hun”查询带来1条记录。

0 个答案:

没有答案