使用 PHP 查詢 Sphinx 的全文檢索

發表時間: 2010-11-17 19:32:12
一劃
2010-11-17 19:32:12

先安裝 libsphinxclient 因為之前的 Sphinx 是自己抓 source 回來 complier 的,所以直接到 source 的API目錄下的 libsphinxclient $ cd sphinx-0.9.9/api/libsphinxclient/

先改個BUG http://www.sphinxsearch.com/forum/view.html?id=4801

在 sphinxclient.c 的 280 行

void sock_close ( int sock );

改成

static void sock_close ( int sock );

$ ./configure --prefix=/usr/local/sphinx $ make $ sudo make installl $ cd /usr/local/php5/bin $ sudo ./pecl install sphinx 接著會問你 libsphinxclient 裝在哪,輸入 /usr/local/sphinx 再按 enter。 這樣一來,就產生了 sphinx 的動態附加元件檔 sphinx.so 再去 php.ini 加入 extension=sphinx.so 就 OK 了。

由 PHP 查詢範例


<?php
$attrtype = SPH_MATCH_ANY;
$q = "test";
$s = new SphinxClient;
$s->setServer("localhost", 9312);
$s->setMatchMode($attrtype);
$s->setMaxQueryTime(3);
if ( $s->GetLastWarning() )
    print "WARNING: " . $s->GetLastWarning() . "<br/>";
$res = $s->query($q);
print_r($res)
?>;

回應文章

  • :D
  • ::urr::
  • *^^*
  • ::iIi::
  • ::|||::
  • ::love::
  • :::~~::
  • ::KISS::
  • ::cry::
  • [[ZZZ]]
  • :(
  • ::hey::
  • ::ur::
  • ::\_/::
  • ::Arr::
  • ::X::
  • :p
  • ::?::
  • ::GOD::
  • ::^_^::
  • ^_-
  • ::三小::
  • ::ccc::
  • ::grrr::