sphinxqlはどのように結果数とshow metaの詳細な説明を得るか
3298 ワード
mysql:select count(*) from main_index;
しかし、これはここで文法の間違いを報告します.
第1の方法:文書を調べる:Aggregate functions(AVG()、MIN()、MAX()、SUM()in column list clause are supported.Arguments to aggregate functions can be either plain attributes or arbitrary expressions. COUNT(*) is implicitly supported as using GROUP BY will add @count column to result set. Explicit support might be added in the future. COUNT(DISTINCT attr) is supported. Currently there can be at most one COUNT(DISTINCT) per query and an argument needs to be an attribute. Both current restrictions on COUNT(DISTINCT) might be lifted in the future.
つまりgroup byの時だけcount(*)を使うことができます.
第2の方法
つまりshow metaでこのtotal_found、これが総記録数です.
次にshow meta:SHOW META shows additional meta-information about the latest query such as query time and keyword statisticsについてお話しします.
つまり、クエリ時間、キーワード統計、合計レコードなど、最近のクエリに追加された情報が表示されます.
PHPではどのように呼び出しますか?
注意:コードに複数のデータベース接続が使用されている場合は、この対応するconnを送信する必要があります.そうしないと、結果は取得されません.
しかし、これはここで文法の間違いを報告します.
第1の方法:文書を調べる:Aggregate functions(AVG()、MIN()、MAX()、SUM()in column list clause are supported.Arguments to aggregate functions can be either plain attributes or arbitrary expressions. COUNT(*) is implicitly supported as using GROUP BY will add @count column to result set. Explicit support might be added in the future. COUNT(DISTINCT attr) is supported. Currently there can be at most one COUNT(DISTINCT) per query and an argument needs to be an attribute. Both current restrictions on COUNT(DISTINCT) might be lifted in the future.
つまりgroup byの時だけcount(*)を使うことができます.
select 1 as dummy,count(*) c from main_index group by dummy;
+------+--------+-------+--------+
| id | weight | dummy | @count |
+------+--------+-------+--------+
| 1001 | 1 | 1 | 15659 |
+------+--------+-------+--------+
第2の方法
select * from main_index limit 0;
show meta;
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| total | 67 |
| total_found | 67 |
| time | 0.001 |
| keyword[0] | ha |
| docs[0] | 67 |
| hits[0] | 115 |
+---------------+-------+
つまりshow metaでこのtotal_found、これが総記録数です.
次にshow meta:SHOW META shows additional meta-information about the latest query such as query time and keyword statisticsについてお話しします.
つまり、クエリ時間、キーワード統計、合計レコードなど、最近のクエリに追加された情報が表示されます.
mysql> SELECT * FROM test1 WHERE MATCH('test|one|two');
+------+--------+----------+------------+
| id | weight | group_id | date_added |
+------+--------+----------+------------+
| 1 | 3563 | 456 | 1231721236 |
| 2 | 2563 | 123 | 1231721236 |
| 4 | 1480 | 2 | 1231721236 |
+------+--------+----------+------------+
3 rows in set (0.01 sec)
mysql> SHOW META;
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| total | 3 |
| total_found | 3 |
| time | 0.005 |
| keyword[0] | test |
| docs[0] | 3 |
| hits[0] | 5 |
| keyword[1] | one |
| docs[1] | 1 |
| hits[1] | 2 |
| keyword[2] | two |
| docs[2] | 1 |
| hits[2] | 2 |
+---------------+-------+
12 rows in set (0.00 sec)
PHPではどのように呼び出しますか?
//
private function getTotalFound($conn) {
$sql = "show meta";
$total_result = @mysql_query ( $sql,$conn );
$totals = array ();
while ( ($row = mysql_fetch_assoc ( $total_result )) !== false ) {
$totals [$row ['Variable_name']] = $row ['Value'];
}
return $totals;
}
?>
注意:コードに複数のデータベース接続が使用されている場合は、この対応するconnを送信する必要があります.そうしないと、結果は取得されません.