最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

sphinxql如何得到結(jié)果數(shù)及show meta的詳細(xì)說(shuō)明

 更新時(shí)間:2013年02月07日 17:35:18   作者:  
想用sphinxql只得到結(jié)果數(shù)。跟mysql里的count(*)一樣

mysql:
select count(*) from main_index;

但是這個(gè)在這里卻報(bào)語(yǔ)法錯(cuò)誤。

第一種方法:
查文檔得:
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.

也就是說(shuō)只有在group by的時(shí)候才能用count(*),如:

復(fù)制代碼 代碼如下:

select 1 as dummy,count(*) c from main_index group by dummy;
+------+--------+-------+--------+
| id | weight | dummy | @count |
+------+--------+-------+--------+
| 1001 | 1      | 1 | 15659 |
+------+--------+-------+--------+

第二種方法
復(fù)制代碼 代碼如下:

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 |
+---------------+-------+

也就是說(shuō)用show meta來(lái)得到這個(gè)total_found,這個(gè)就是總記錄數(shù)。

下面我們來(lái)說(shuō)一下show meta:
SHOW META shows additional meta-information about the latest query such as query time and keyword statistics:

也就是說(shuō)它顯示的是最近一次查詢附加的一些信息,比如查詢時(shí)間、關(guān)鍵字統(tǒng)計(jì)、總記錄等。

復(fù)制代碼 代碼如下:

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中如何調(diào)用?
復(fù)制代碼 代碼如下:

<?php
//獲取總記錄個(gè)數(shù)
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;
}
?>

注意:如果代碼中用了多個(gè)數(shù)據(jù)庫(kù)連接的話,這個(gè)相應(yīng)的conn必須傳進(jìn)來(lái),否則是取不到結(jié)果的。

相關(guān)文章

最新評(píng)論

扶绥县| 蓬溪县| 东阿县| 重庆市| 桃源县| 剑河县| 海口市| 左权县| 广宁县| 衢州市| 泸定县| 游戏| 东乌珠穆沁旗| 通城县| 吉首市| 灯塔市| 芮城县| 彭州市| 清河县| 庆云县| 寿光市| 兴国县| 华池县| 莫力| 郁南县| 原阳县| 山西省| 石泉县| 瑞昌市| 志丹县| 昔阳县| 济阳县| 通渭县| 东乌珠穆沁旗| 微山县| 绵竹市| 盐池县| 紫阳县| 怀柔区| 上栗县| 泰兴市|