From bfca0c79030d5b8a18e41e8b80f5560ebaf6f202 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 23 Jun 2009 12:00:49 -0700 Subject: Refactor the install/upgrade code to be more flexible. Add xxx_installer::upgrade($version) method so that upgrade stanzas are separate from install stanzas. In the old code, to do an upgrade meant that you had to re-evolve everything from the initial install because we'd step through each version's changes. But what we really want is for the initial install to start off in the perfect initial state, and the upgrades to do the work behind the scenes. So now the install() function gets things set up properly the first time, and the upgrade() function does any work to catch you up to the latest code. See gallery_installer.php for a good example. --- modules/search/helpers/search_installer.php | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'modules/search/helpers') diff --git a/modules/search/helpers/search_installer.php b/modules/search/helpers/search_installer.php index ed4a3a90..cd253be4 100644 --- a/modules/search/helpers/search_installer.php +++ b/modules/search/helpers/search_installer.php @@ -19,20 +19,17 @@ */ class search_installer { static function install() { - $version = module::get_version("search"); $db = Database::instance(); - if ($version == 0) { - $db->query("CREATE TABLE {search_records} ( - `id` int(9) NOT NULL auto_increment, - `item_id` int(9), - `dirty` boolean default 1, - `data` LONGTEXT default NULL, - PRIMARY KEY (`id`), - KEY(`item_id`), - FULLTEXT INDEX (`data`)) - ENGINE=MyISAM DEFAULT CHARSET=utf8;"); - module::set_version("search", 1); - } + $db->query("CREATE TABLE {search_records} ( + `id` int(9) NOT NULL auto_increment, + `item_id` int(9), + `dirty` boolean default 1, + `data` LONGTEXT default NULL, + PRIMARY KEY (`id`), + KEY(`item_id`), + FULLTEXT INDEX (`data`)) + ENGINE=MyISAM DEFAULT CHARSET=utf8;"); + module::set_version("search", 1); } static function activate() { -- cgit v1.2.3 From 297ac6ebd15bc53ce6c7d96b659b22fb3b220d74 Mon Sep 17 00:00:00 2001 From: Romain LE DISEZ Date: Tue, 23 Jun 2009 16:05:15 +0800 Subject: Improve compatibility with other RDBMS Signed-off-by: Bharat Mediratta --- modules/search/helpers/search.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/search/helpers') diff --git a/modules/search/helpers/search.php b/modules/search/helpers/search.php index 15efa3b2..9046ad2d 100644 --- a/modules/search/helpers/search.php +++ b/modules/search/helpers/search.php @@ -45,7 +45,7 @@ class search_Core { "WHERE MATCH({search_records}.`data`) AGAINST ('$q' IN BOOLEAN MODE) " . $access_sql . "ORDER BY `score` DESC " . - "LIMIT $offset, $limit"; + "LIMIT $limit OFFSET $offset"; return array($count, new ORM_Iterator(ORM::factory("item"), $db->query($query))); } -- cgit v1.2.3 From da09185a4baa739dd011804eb1301cdf2d126c11 Mon Sep 17 00:00:00 2001 From: Romain LE DISEZ Date: Tue, 23 Jun 2009 16:08:55 +0800 Subject: SQL is case insensitive Signed-off-by: Bharat Mediratta --- modules/search/helpers/search.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules/search/helpers') diff --git a/modules/search/helpers/search.php b/modules/search/helpers/search.php index 9046ad2d..ea8dad81 100644 --- a/modules/search/helpers/search.php +++ b/modules/search/helpers/search.php @@ -34,11 +34,11 @@ class search_Core { // 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 " . + $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; + $count = $db->query($count_query)->current()->c; $query = "SELECT {items}.*, MATCH({search_records}.`data`) AGAINST ('$q') AS `score` " . "FROM {items} JOIN {search_records} ON ({items}.`id` = {search_records}.`item_id`) " . -- cgit v1.2.3