Skip to content
Browse files

#2081 - Add search module option to limit item types in results.

  • Loading branch information...
1 parent 26ac565 commit 24ef67f64dac04114b76c9ceda80d689300887b9 @shadlaws shadlaws committed
View
3 installer/install.sql
@@ -385,7 +385,7 @@ CREATE TABLE {vars} (
`value` text,
PRIMARY KEY (`id`),
UNIQUE KEY `module_name` (`module_name`,`name`)
-) AUTO_INCREMENT=51 DEFAULT CHARSET=utf8;
+) AUTO_INCREMENT=52 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
INSERT INTO {vars} VALUES (NULL,'gallery','active_site_theme','wind');
INSERT INTO {vars} VALUES (NULL,'gallery','active_admin_theme','admin_wind');
@@ -432,6 +432,7 @@ INSERT INTO {vars} VALUES (NULL,'info','show_owner','1');
INSERT INTO {vars} VALUES (NULL,'info','show_name','1');
INSERT INTO {vars} VALUES (NULL,'info','show_captured','1');
INSERT INTO {vars} VALUES (NULL,'info','show_dimensions','1');
+INSERT INTO {vars} VALUES (NULL,'search','item_types','all');
INSERT INTO {vars} VALUES (NULL,'search','wildcard_mode','append_stem');
INSERT INTO {vars} VALUES (NULL,'search','short_search_fix','0');
INSERT INTO {vars} VALUES (NULL,'search','short_search_prefix','1Z');
View
9 modules/search/classes/Search/Controller/Admin/Search.php
@@ -26,9 +26,17 @@ public function action_index() {
->add("submit", "input|submit", t("Save"));
$form->settings
->set("label", t("Settings"))
+ ->add("item_types", "select", Module::get_var("search", "item_types", "all"))
->add("wildcard_mode", "select", Module::get_var("search", "wildcard_mode", "append_stem"))
->add("short_search_fix", "checkbox", Module::get_var("search", "short_search_fix", false))
->add("short_search_prefix", "input", Module::get_var("search", "short_search_prefix", "1Z"));
+ $form->settings->item_types
+ ->set("label", t("Item types shown in search results"))
+ ->set("opts", array(
+ "all" => t("all (default)"),
+ "no_albums" => t("no albums; photos and movies only"),
+ "photos_only" => t("photos only; no albums or movies")
+ ));
$form->settings->wildcard_mode
->set("label", t("Wildcard mode"))
->set("opts", array(
@@ -52,6 +60,7 @@ public function action_index() {
Search::mark_dirty();
}
+ Module::set_var("search", "item_types", $form->settings->item_types->val());
Module::set_var("search", "wildcard_mode", $form->settings->wildcard_mode->val());
Module::set_var("search", "short_search_fix", $form->settings->short_search_fix->val());
Module::set_var("search", "short_search_prefix", $form->settings->short_search_prefix->val());
View
2 modules/search/classes/Search/Hook/SearchInstaller.php
@@ -32,6 +32,7 @@ static function install() {
ENGINE=MyISAM
DEFAULT CHARSET=utf8;");
+ Module::set_var("search", "item_types", "all");
Module::set_var("search", "wildcard_mode", "append_stem");
Module::set_var("search", "short_search_fix", false);
Module::set_var("search", "short_search_prefix", "1Z");
@@ -48,6 +49,7 @@ static function activate() {
static function upgrade($version) {
if ($version == 1) {
// In v2, we added some additional module variables for wildcards and short search fixes.
+ Module::set_var("search", "item_types", "all");
Module::set_var("search", "wildcard_mode", "append_stem");
Module::set_var("search", "short_search_fix", false);
Module::set_var("search", "short_search_prefix", "1Z");
View
13 modules/search/classes/Search/Search.php
@@ -62,6 +62,19 @@ static function get_search_query($q, $album, $where=array()) {
$q_boolean = Database::instance()->escape(implode("", (array)$q_boolean));
$q_natural = Database::instance()->escape(implode("", (array)$q_natural));
+ switch ($item_types = Module::get_var("search", "item_types", "all")) {
+ case "no_albums":
+ $where[] = array("type", "<>", "album");
+ break;
+ case "photos_only":
+ $where[] = array("type", "=", "photo");
+ break;
+ case "all":
+ break;
+ default:
+ throw new Gallery_Exception("Invalid search item_types setting: $item_types");
+ }
+
// Build the query.
return $album->descendants
->with("search_record")

0 comments on commit 24ef67f

Please sign in to comment.
Something went wrong with that request. Please try again.