summaryrefslogtreecommitdiff
path: root/modules/search/helpers
diff options
context:
space:
mode:
authorTim Almdal <tnalmdal@shaw.ca>2009-10-08 13:47:30 -0700
committerTim Almdal <tnalmdal@shaw.ca>2009-10-08 13:47:30 -0700
commit7ad203b97a148c1e3b0585bf2554819bdc87ce98 (patch)
tree228e1e6ab9242f97687d6c0bb42f3580707b97f9 /modules/search/helpers
parent6f315ad89c06431b408fcdf24393ad13daed845d (diff)
parentb6c1ba7ea6416630b2a44b3df8400a2d48460b0a (diff)
Merge branch 'master' of git@github.com:gallery/gallery3 into talmdal_dev
Diffstat (limited to 'modules/search/helpers')
-rw-r--r--modules/search/helpers/search.php15
1 files changed, 5 insertions, 10 deletions
diff --git a/modules/search/helpers/search.php b/modules/search/helpers/search.php
index 20d26b61..069b5b77 100644
--- a/modules/search/helpers/search.php
+++ b/modules/search/helpers/search.php
@@ -31,21 +31,16 @@ class search_Core {
$access_sql = "";
}
- // Count the total number of rows. We can't do this with our regular query because of the
- // limit statement. It's possible that if we get rid of the limit (but keep the offset) on
- // the 2nd query and combine the two, it might be faster than making 2 separate queries.
- $count_query = "SELECT COUNT(*) AS c " .
- "FROM {items} JOIN {search_records} ON ({items}.`id` = {search_records}.`item_id`) " .
- "WHERE MATCH({search_records}.`data`) AGAINST ('$q' IN BOOLEAN MODE) " .
- $access_sql;
- $count = $db->query($count_query)->current()->c;
-
- $query = "SELECT {items}.*, MATCH({search_records}.`data`) AGAINST ('$q') AS `score` " .
+ $query =
+ "SELECT SQL_CALC_FOUND_ROWS {items}.*, " .
+ " MATCH({search_records}.`data`) AGAINST ('$q') AS `score` " .
"FROM {items} JOIN {search_records} ON ({items}.`id` = {search_records}.`item_id`) " .
"WHERE MATCH({search_records}.`data`) AGAINST ('$q' IN BOOLEAN MODE) " .
$access_sql .
"ORDER BY `score` DESC " .
"LIMIT $limit OFFSET $offset";
+ $data = $db->query($query);
+ $count = $db->query("SELECT FOUND_ROWS() as c")->current()->c;
return array($count, new ORM_Iterator(ORM::factory("item"), $db->query($query)));
}