如何使用 Sphinx PHP API 获取基于排名的 Sphinx 结果?

发布于 2025-01-01 14:38:26 字数 515 浏览 2 评论 0原文

是否可以使用 sphinx PHP API 根据排名显示 Sphinx 结果,

For example,
----------------------------------------------
Searched_Query  |  Result        |  Ranks 
----------------------------------------------
Sony Ericsson     Sony Ericsson     Best Match
                  Ericsson          Good Match
                  Sony DVD          Fair Match
                  DVD               Poor Match
----------------------------------------------

如果可以,请附上示例或参考 URL。

非常感谢帮助!

谢谢, 拉贾

Is it possible to display the Sphinx results based on ranking using sphinx PHP API,

For example,
----------------------------------------------
Searched_Query  |  Result        |  Ranks 
----------------------------------------------
Sony Ericsson     Sony Ericsson     Best Match
                  Ericsson          Good Match
                  Sony DVD          Fair Match
                  DVD               Poor Match
----------------------------------------------

If is it so, then kindly attach me the sample or reference URL.

Help is greatly appreciated !

Thanks,
Raja

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

ヤ经典坏疍 2025-01-08 14:38:26

是的,也不是。默认情况下,Sphinx 会进行排名 - 并且结果会按最佳顺序排在第一位。 (但这可以更改)

但是这里的一个重要考虑因素是“匹配” - 记录是否与查询匹配。 (这与“排名”任务略有不同,“排名”任务为每场比赛提供分数,并且通常按分数排序)

要接近,您将需要使用“匹配任何”样式匹配。这意味着只需要其中一个词。默认情况下匹配“ALL” - 需要所有单词。还可以使用 Quorum 或“OR”查询来模拟具有扩展匹配模式的任何匹配。

...在 sphinx 文档中阅读有关这些术语的更多信息。

我说“关闭”是因为 sphinx 不会真正给出示例中的最后结果。因为它没有共同的词。前三个都有一个共同的词。

也许您正在考虑 mysql 全文搜索中的“WITH EXPANSION”选项。这将做到这一点。 Sphinx没有直接可比的功能,因此必须自己实现。 (例如,运行“any qy​​ery”抓取前 100 个结果,计算出常见单词(在您的代码中)),并形成对 sphinx 的第二个查询。使用第二个查询作为向用户显示的结果)

[话虽如此,还有另一个选项,可以形成一个匹配所有文档的查询,然后仅依靠排名来获取“匹配项”以显示在顶部附近。我不会推荐这个用于一般搜索]

Yes and no. Sphinx by default does ranking - and results are ordered best first. (but this can be changed)

But an important consideration here is 'matching' - does the record even match the query. (which is slightly different to the task of 'ranking' which gives a score to each match, and usually orders by it)

To get close you will need to use the "MATCH ANY" style matching. Which means will only require one of the words. By default is match "ALL" - needing all words. Can also emulate match any with EXTENDED match mode, either using Quorum or a 'OR' query.

... read more about these terms in the sphinx documentation.

I said 'close' because sphinx wont really give you the last result in your example. Because it shares no common words. The first three all share a common word.

Perhaps you are thinking of the "WITH EXPANSION" option in mysql full-text search. This will do this. Sphinx doesnt have a directly comparable function, so it would have to be implemented yourself. (eg run a 'any qyery' grab, the top 100 results, work out the common words (in your code)), and form a second query to sphinx. use this second query as the results shown to the user)

[having said that there is another option, could form a query that matches all documents, and then just relied on ranking to get the 'matches' to show near the top. I wouldnt recommend this tho for a general search]

许仙没带伞 2025-01-08 14:38:26
require_once ( "sphinxapi.php" );

$cl = new SphinxClient ();

$cl->SetServer ("localhost", 9312);
$cl->SetMatchMode ( SPH_MATCH_EXTENDED2 );
$cl->SetSortMode ( SPH_SORT_EXTENDED, "@weight DESC" );
$res = $cl->Query ( "Sony Ericsson", "your_sphinx_index_name" );
if ( $res===false )
{
        print "ERROR: Query failed: " . $cl->GetLastError() . ".\n";
} else {
        if ( $cl->GetLastWarning() ) print "WARNING: " . $cl->GetLastWarning() . "\n\n";

        // result processing is here
}
require_once ( "sphinxapi.php" );

$cl = new SphinxClient ();

$cl->SetServer ("localhost", 9312);
$cl->SetMatchMode ( SPH_MATCH_EXTENDED2 );
$cl->SetSortMode ( SPH_SORT_EXTENDED, "@weight DESC" );
$res = $cl->Query ( "Sony Ericsson", "your_sphinx_index_name" );
if ( $res===false )
{
        print "ERROR: Query failed: " . $cl->GetLastError() . ".\n";
} else {
        if ( $cl->GetLastWarning() ) print "WARNING: " . $cl->GetLastWarning() . "\n\n";

        // result processing is here
}
苏璃陌 2025-01-08 14:38:26
require_once ( "sphinxapi.php" );
$cl = new SphinxClient ();
$cl->SetServer ("localhost", 9312); 
$cl->SetMatchMode ( SPH_RANK_SPH04 );  /*use this*/
$cl->SetMatchMode ( SPH_MATCH_EXTENDED2 );
$cl->SetSortMode ( SPH_SORT_EXTENDED, "@weight DESC" );
$res = $cl->Query ( "Sony Ericsson", "your_sphinx_index_name" );
if ( $res===false ){
    print "ERROR: Query failed: " . $cl->GetLastError() . ".\n";
}else {
    if ( $cl->GetLastWarning() ){
    print "WARNING: ".$cl->GetLastWarning() . "\n\n";
    }
    // result processing is here
}
require_once ( "sphinxapi.php" );
$cl = new SphinxClient ();
$cl->SetServer ("localhost", 9312); 
$cl->SetMatchMode ( SPH_RANK_SPH04 );  /*use this*/
$cl->SetMatchMode ( SPH_MATCH_EXTENDED2 );
$cl->SetSortMode ( SPH_SORT_EXTENDED, "@weight DESC" );
$res = $cl->Query ( "Sony Ericsson", "your_sphinx_index_name" );
if ( $res===false ){
    print "ERROR: Query failed: " . $cl->GetLastError() . ".\n";
}else {
    if ( $cl->GetLastWarning() ){
    print "WARNING: ".$cl->GetLastWarning() . "\n\n";
    }
    // result processing is here
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文