Sphinx搜索使用命令行返回不同的结果,而不是php api

时间:2012-10-12 16:47:43

标签: php mysql search search-engine sphinx

命令行搜索(26019个文档/ 26019次点击)

search.exe --config c:\sphinx\sphinx.conf keyword

OR

search.exe --config c:\sphinx\sphinx.conf keyword -e2

PHP API (总计:1000 /总共找到:51038)

//sphinx command line and php api

mysql_connect("localhost", "username", "password");
mysql_select_db("database");

require_once('sphinxapi.php');

$cl = new SphinxClient;
$cl->setServer("127.0.0.1", 9312); // NOT "localhost" under Windows 7!
$cl->setMatchMode(SPH_MATCH_EXTENDED2);
$cl->SetLimits(0, 20);

$result = $cl->Query("keyword");

if ($result['total'] > 0)
{
    echo 'Total: ' . $result['total'] . "<br />\n";
    echo 'Total Found: ' . $result['total_found'] . "<br />\n";
    echo '<table>';
    echo '<tr><td>ID</td><td>Date</td><td>Title</td><td>Content</td></tr>';

    foreach ($result['matches'] as $id => $otherStuff)
    {
        $row = mysql_fetch_array(mysql_query("select * from table where id = $id"));
        extract($row);

        echo "<tr><td>$id</td><td>$date</td><td>$title</td><td>$content</td></tr>";
    }
    echo '</table>';
}
else
{
    echo 'No results found';
}

匹配模式:

SPH_MATCH_ALL / SPH_MATCH_ANY / SPH_MATCH_PHRASE / SPH_MATCH_BOOLEAN / SPH_MATCH_EXTENDED / SPH_MATCH_EXTENDED2

PS:命令行结果是正确的,因为我直接从MySQL做了选择,我也得到了它。

$sql = "SELECT t1.field1, t1.field2, t1.field3, t2.field4
    FROM t_table1 AS t1
    LEFT JOIN t_table2 AS t2 ON t2.id = t1.t2_id WHERE t2.field4 LIKE 'keyword'";

3 个答案:

答案 0 :(得分:0)

忘了找到“search.exe”。忽略它。真。忘掉它。现在。我会等。

现在,请尝试具体说明要搜索的索引(在查询函数调用上)

对于你得到的每一行也运行一次查询,这并不好。您应该只为所有结果发出一个SQL查询。 mysql IN()函数使它变得简单。

示例http://www.nearby.org.uk/sphinx/search-example5-withcomments.phps

更基本但功能性更强的例子http://www.nearby.org.uk/sphinx/search-example2.phps

答案 1 :(得分:0)

Sphinx仅限返回1000个结果。

有一些建议要提高这个限制,所以请检查他们的页面。只知道你可以将旧的sphinx relesase中的数字更改为你想要的任何数字,但它会以最大值返回1000。

答案 2 :(得分:0)

在这里回答:

http://sphinxsearch.com/docs/manual-2.0.5.html#conf-max-matches

除非您打算在同一页面上使用26019匹配,否则我建议您使用分页(如果您只显示结果)

相关问题