0

我已经开始使用狮身人面像,并尝试安装狮身人面像。一切正常,但我想搜索部分关键字。我想知道如何在网页中显示结果。
前任。
我搜索“
,结果应该是:“”、“更新”、“迟到”、“讨厌”等。
我的 sphinx.con :

source src1
{
  type          = mysql
  sql_host      = localhost
  sql_user      = username
  sql_pass      = *******
  sql_db        = db_name
  sql_port      = 3306  # optional, default is 3306

  sql_query     = \
    SELECT id, msgtext, created \
    FROM agi_sms

  sql_attr_string = msgtext
  sql_attr_timestamp    = created

  sql_query_info        = SELECT * FROM agi_sms WHERE id=$id

}

   index test1
   {
  source            = src1
  path          = C:/Sphinx/data/test1
  docinfo           = extern
  charset_type      = sbcs
  enable_star = 1
  morphology = stem_en
  min_infix_len = 2
  infix_fields = msgtext
  dict = keywords

    }



    indexer
    {
       mem_limit        = 32M
    }


    searchd
    {
  listen            = 9312
  listen            = 9306:mysql41
  log           = C:/Sphinx/log/searchd.log
  query_log     = C:/Sphinx/log/query.log
  read_timeout      = 5
  max_children      = 30
  pid_file      = C:/Sphinx/log/searchd.pid
  max_matches       = 1000
  seamless_rotate       = 1
  preopen_indexes       = 1
  unlink_old        = 1
  workers           = threads # for RT to work
  binlog_path       = C:/Sphinx/data
    }

这是我的 php 文件:

$cl = new SphinxClient ();
$q = $_POST['search'];
$sql = "";
$mode = SPH_MATCH_EXTENDED2;
$host = "localhost";
$port = 9312;
$index = "*";
$groupby = "";
$filter = "created";
$filtervals = array();
$distinct = "";
$sortby = "";

$sortexpr = "";
$limit = 20;
$ranker = SPH_RANK_PROXIMITY_BM25;
$select = "";

////////////
// do query
////////////

  $cl = new SphinxClient();
  $cl->SetServer( "localhost", 9312 );
  $cl->SetMatchMode( SPH_MATCH_ANY );
  $cl->SetFilter( 'created', array( 3 ) );

$res = $cl->Query ( $q, $index );
////////////////
// print me out
////////////////

if ( $res===false )
{
  print "Query failed: " . $cl->GetLastError() . ".\n";

} else
{
  if ( $cl->GetLastWarning() )
    print "WARNING: " . $cl->GetLastWarning() . "\n\n";

  print "<li>Query '$q' retrieved $res[total] of $res[total_found] matches in $res[time] sec.\n</li>";
  print "<li>Query stats:\n";
  if ( is_array($res["words"]) )
    foreach ( $res["words"] as $word => $info )
      print "    '$word' found $info[hits] times in $info[docs] documents\n</li>";
  print "\n";


}  

结果:

Query 'good' retrieved 0 of 0 matches in 0.007 sec.
Query stats: 'good' found 7534 times in 7534 documents

但是,如果我尝试搜索“goo”,它什么也没搜索。

Query 'goo' retrieved 0 of 0 matches in 0.000 sec.
Query stats: 'goo' found 0 times in 0 documents

我想得到结果,所有东西都有一个单词/字母' goo '。

像这样 :

Array(1 element) {
    0 Object {
        id = 1,
        message = Good Morning
    }
    2 Object {
        id = 2,
        message = Good Day!
    }
}
4

1 回答 1

1

$cl->SetFilter('created', array(3)); 你确定你有created=3的记录吗?同样对于通配符搜索,您应该执行“goo*”(标记 *)或设置 expand_keywords = 1。

于 2014-01-07T09:27:58.417 回答