SPHINX搜索php查询,如何显示数组结果?

发布于 2024-09-25 04:59:34 字数 1836 浏览 3 评论 0原文

我开始学习 sphinx search php api

运行此查询后

   <?php
  include('sphinxapi.php');
  $cl = new SphinxClient();
  $cl->SetServer( "192.168.0.100", 9312 );
  $cl->SetMatchMode( SPH_MATCH_ANY  );
  $result = $cl->Query( "mimmi",  "searchtest" );

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

      if ( ! empty($result["matches"]) ) {
          foreach ( $result["matches"] as $doc => $docinfo ) {
                echo "$doc\n";
          }

          print_r( $result );
      }
  }

  exit;
?>   

如何正确显示结果,它显示这样的输出

2183 3262 5256 7812 838 1475 1701 6184 1816 Array ( [error] => [warning] => [status] => 0 [fields] => Array ( [0] => namn [1] => title [2] => identification_text [3] => id [4] => namn [5] => title [6] => identification_text [7] => description ) [attrs] => Array ( ) [matches] => Array ( [2183] => Array ( [weight] => 6 [attrs] => Array ( ) ) [3262] => Array ( [weight] => 6 [attrs] => Array ( ) ) [5256] => Array ( [weight] => 6 [attrs] => Array ( ) ) [7812] => Array ( [weight] => 6 [attrs] => Array ( ) ) [838] => Array ( [weight] => 4 [attrs] => Array ( ) ) [1475] => Array ( [weight] => 4 [attrs] => Array ( ) ) [1701] => Array ( [weight] => 4 [attrs] => Array ( ) ) [6184] => Array ( [weight] => 4 [attrs] => Array ( ) ) [1816] => Array ( [weight] => 2 [attrs] => Array ( ) ) ) [total] => 9 [total_found] => 9 [time] => 0.001 [words] => Array ( [mimmi] => Array ( [docs] => 9 [hits] => 46 ) ) )  

我不知道该怎么做,我如何显示结果。

Im beginning to learn sphinx search php api

after running this query

   <?php
  include('sphinxapi.php');
  $cl = new SphinxClient();
  $cl->SetServer( "192.168.0.100", 9312 );
  $cl->SetMatchMode( SPH_MATCH_ANY  );
  $result = $cl->Query( "mimmi",  "searchtest" );

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

      if ( ! empty($result["matches"]) ) {
          foreach ( $result["matches"] as $doc => $docinfo ) {
                echo "$doc\n";
          }

          print_r( $result );
      }
  }

  exit;
?>   

how can i display the results properly, it shows up output like this

2183 3262 5256 7812 838 1475 1701 6184 1816 Array ( [error] => [warning] => [status] => 0 [fields] => Array ( [0] => namn [1] => title [2] => identification_text [3] => id [4] => namn [5] => title [6] => identification_text [7] => description ) [attrs] => Array ( ) [matches] => Array ( [2183] => Array ( [weight] => 6 [attrs] => Array ( ) ) [3262] => Array ( [weight] => 6 [attrs] => Array ( ) ) [5256] => Array ( [weight] => 6 [attrs] => Array ( ) ) [7812] => Array ( [weight] => 6 [attrs] => Array ( ) ) [838] => Array ( [weight] => 4 [attrs] => Array ( ) ) [1475] => Array ( [weight] => 4 [attrs] => Array ( ) ) [1701] => Array ( [weight] => 4 [attrs] => Array ( ) ) [6184] => Array ( [weight] => 4 [attrs] => Array ( ) ) [1816] => Array ( [weight] => 2 [attrs] => Array ( ) ) ) [total] => 9 [total_found] => 9 [time] => 0.001 [words] => Array ( [mimmi] => Array ( [docs] => 9 [hits] => 46 ) ) )  

i don't know what to make out of it, how do i display the results.

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

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

发布评论

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

评论(2

凶凌 2024-10-02 04:59:34

此时,您想要获取从 sphinx 返回的 ID 并用它们查询数据库。

<?php
     $IDs = implode(",",array_keys($result["matches"]));
     $sql = "SELECT * FROM `tbl` WHERE `id` IN ($IDs) ORDER BY FIELD(`id`,$IDs)";
?>

At this point you want to take the IDs returned from sphinx and query your database with them.

<?php
     $IDs = implode(",",array_keys($result["matches"]));
     $sql = "SELECT * FROM `tbl` WHERE `id` IN ($IDs) ORDER BY FIELD(`id`,$IDs)";
?>
眼趣 2024-10-02 04:59:34

您在 /etc/sphinxsearch/sphinx.conf 中声明的字段将在 $result['matches'] 中可用:

sql_field_string = my_field  # will be both indexed and stored

这样,无需查询数据库

Fields you declare inside your /etc/sphinxsearch/sphinx.conf will be available in $result['matches'] :

sql_field_string = my_field  # will be both indexed and stored

This way, there's no need to query your database

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文