略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: 范例

2024-12-23

范例

Example #1 基本使用范例

<?php

$s 
= new SphinxClient;
$s->setServer("localhost"6712);
$s->setMatchMode(SPH_MATCH_ANY);
$s->setMaxQueryTime(3);

$result $s->query("test");

var_dump($result);

?>

以上例程的输出类似于:

array(10) {
  ["error"]=>
  string(0) ""
  ["warning"]=>
  string(0) ""
  ["status"]=>
  int(0)
  ["fields"]=>
  array(3) {
    [0]=>
    string(7) "subject"
    [1]=>
    string(4) "body"
    [2]=>
    string(6) "author"
  }
  ["attrs"]=>
  array(0) {
  }
  ["matches"]=>
  array(1) {
    [3]=>
    array(2) {
      ["weight"]=>
      int(1)
      ["attrs"]=>
      array(0) {
      }
    }
  }
  ["total"]=>
  int(1)
  ["total_found"]=>
  int(1)
  ["time"]=>
  float(0)
  ["words"]=>
  array(1) {
    ["to"]=>
    array(2) {
      ["docs"]=>
      int(1)
      ["hits"]=>
      int(1)
    }
  }
}
add a note add a note

User Contributed Notes 2 notes

up
-3
mesaque dot silva at apiki dot com
3 years ago
it is deprecated, use instead SphinxQL-Query-Builder
up
-26
iradu at unix-world dot org
3 years ago
SphinxQL-Query-Builder is an ORM for Sphinx.

ORM generally is for dumb developers that have no ability to write SQL complex queries.
More, ORMs are covering just 10...15% of the SQL syntax.

So, my advice, don't go with ORM in any case ...
Use the SQL syntax always:
http://sphinxsearch.com/docs/current.html#sphinxql-reference

PS:
I have seen many ORMs like Doctrine or others, but they are a joke comparing with the SQL ;)

官方地址:https://www.php.net/manual/en/sphinx.examples.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3