Short_Search_Fix Version 1 - first commit to github.
This commit is contained in:
parent
80db5d36f9
commit
546d9fa018
@ -0,0 +1,63 @@
|
|||||||
|
<?php defined("SYSPATH") or die("No direct script access.");
|
||||||
|
/**
|
||||||
|
* Gallery - a web based photo album viewer and editor
|
||||||
|
* Copyright (C) 2000-2011 Bharat Mediratta
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
class Admin_Short_Search_Fix_Controller extends Admin_Controller {
|
||||||
|
public function index() {
|
||||||
|
$view = new Admin_View("admin.html");
|
||||||
|
$view->page_title = t("Short search fix settings");
|
||||||
|
$view->content = new View("admin_short_search_fix.html");
|
||||||
|
$view->content->form = $this->_get_admin_form();
|
||||||
|
print $view;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save() {
|
||||||
|
access::verify_csrf();
|
||||||
|
$form = $this->_get_admin_form();
|
||||||
|
$form->validate();
|
||||||
|
module::set_var("short_search_fix", "search_prefix",
|
||||||
|
$form->short_search_fix_settings->search_prefix->value);
|
||||||
|
message::success(t("Short search fix settings updated"));
|
||||||
|
if ($form->short_search_fix_settings->mark_rebuild_search_records->value) {
|
||||||
|
$db = Database::instance();
|
||||||
|
$db->query("UPDATE {search_records} SET dirty=1;");
|
||||||
|
}
|
||||||
|
if ($form->short_search_fix_settings->mark_uptodate_search_records->value) {
|
||||||
|
$db = Database::instance();
|
||||||
|
$db->query("UPDATE {search_records} SET dirty=0;");
|
||||||
|
}
|
||||||
|
url::redirect("admin/short_search_fix");
|
||||||
|
}
|
||||||
|
|
||||||
|
private function _get_admin_form() {
|
||||||
|
$form = new Forge("admin/short_search_fix/save", "", "post",
|
||||||
|
array("id" => "g-short-search-fix-admin-form"));
|
||||||
|
$short_search_fix_settings = $form->group("short_search_fix_settings")->label(t("Prefix and search record rebuild"));
|
||||||
|
$short_search_fix_settings->input("search_prefix")
|
||||||
|
->label(t("Enter the prefix to be added to the start of every search word (Default: 1Z)"))
|
||||||
|
->value(module::get_var("short_search_fix", "search_prefix"));
|
||||||
|
$short_search_fix_settings->checkbox("mark_rebuild_search_records")
|
||||||
|
->label(t("Mark all search records for rebuild. This is needed when the prefix is changed. Afterward, go to Maintenace | Update search records."))
|
||||||
|
->checked(false);
|
||||||
|
$short_search_fix_settings->checkbox("mark_uptodate_search_records")
|
||||||
|
->label(t("Mark all search records as up-to-date. This is a pseudo-undo of the above."))
|
||||||
|
->checked(false);
|
||||||
|
$short_search_fix_settings->submit("save")->value(t("Save"));
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
|
}
|
58
3.0/modules/short_search_fix/helpers/MY_search.php
Normal file
58
3.0/modules/short_search_fix/helpers/MY_search.php
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
<?php defined("SYSPATH") or die("No direct script access.");
|
||||||
|
/**
|
||||||
|
* Gallery - a web based photo album viewer and editor
|
||||||
|
* Copyright (C) 2000-2012 Bharat Mediratta
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
class search extends search_Core {
|
||||||
|
/**
|
||||||
|
* Add more terms to the query by wildcarding the stem value of the first
|
||||||
|
* few terms in the query.
|
||||||
|
*/
|
||||||
|
static function add_query_terms($q) {
|
||||||
|
$MAX_TERMS = 5;
|
||||||
|
|
||||||
|
// strip leading, trailing, and extra whitespaces
|
||||||
|
$terms = preg_replace('/^\s+/', '', $q);
|
||||||
|
$terms = preg_replace('/\s+$/', '', $terms);
|
||||||
|
$terms = preg_replace('/\s\s+/', ' ', $terms);
|
||||||
|
|
||||||
|
$terms = explode(" ", $terms, $MAX_TERMS);
|
||||||
|
//$terms = explode(" ", $q, $MAX_TERMS); // commented out from original function
|
||||||
|
for ($i = 0; $i < min(count($terms), $MAX_TERMS - 1); $i++) {
|
||||||
|
// Don't wildcard quoted or already wildcarded terms
|
||||||
|
if ((substr($terms[$i], 0, 1) != '"') && (substr($terms[$i], -1, 1) != "*")) {
|
||||||
|
$terms[] = rtrim($terms[$i], "s") . "*";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//return implode(" ", $terms); // commented out from original function
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the search prefix to the start of every word.
|
||||||
|
*/
|
||||||
|
$prefix = module::get_var("short_search_fix","search_prefix");
|
||||||
|
$terms = implode(" ", $terms);
|
||||||
|
$terms = preg_replace('/^\s+/', '', $terms); // the implode seems to add this back in
|
||||||
|
// add the prefixes
|
||||||
|
if (preg_match('/\w/',$terms) > 0) {
|
||||||
|
$terms = ' ' . $terms;
|
||||||
|
$terms = str_replace(' ', ' '.$prefix, $terms);
|
||||||
|
$terms = str_replace(' '.$prefix.'"', ' '.'"'.$prefix, $terms);
|
||||||
|
$terms = substr($terms,1);
|
||||||
|
}
|
||||||
|
return $terms;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
<?php defined("SYSPATH") or die("No direct script access.");
|
||||||
|
/**
|
||||||
|
* Gallery - a web based photo album viewer and editor
|
||||||
|
* Copyright (C) 2000-2011 Bharat Mediratta
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
class short_search_fix_event_Core {
|
||||||
|
|
||||||
|
static function admin_menu($menu, $theme) {
|
||||||
|
$menu->get("settings_menu")
|
||||||
|
->append(Menu::factory("link")
|
||||||
|
->id("short_search_fix")
|
||||||
|
->label(t("Short search fix"))
|
||||||
|
->url(url::site("admin/short_search_fix")));
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is the function that changes what's written to the search_records database
|
||||||
|
static function item_index_data($item, $data) {
|
||||||
|
$prefix = module::get_var("short_search_fix","search_prefix");
|
||||||
|
foreach ($data as &$terms) {
|
||||||
|
// strip leading, trailing, and extra whitespaces
|
||||||
|
$terms = preg_replace('/^\s+/', '', $terms);
|
||||||
|
$terms = preg_replace('/\s+$/', '', $terms);
|
||||||
|
$terms = preg_replace('/\s\s+/', ' ', $terms);
|
||||||
|
// add the prefixes
|
||||||
|
if (preg_match('/\w/',$terms) > 0) {
|
||||||
|
$terms = $prefix . str_replace(' ', ' '.$prefix, $terms);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
<?php defined("SYSPATH") or die("No direct script access.");
|
||||||
|
/**
|
||||||
|
* Gallery - a web based photo album viewer and editor
|
||||||
|
* Copyright (C) 2000-2011 Bharat Mediratta
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
class short_search_fix_installer {
|
||||||
|
static function install() {
|
||||||
|
$db = Database::instance();
|
||||||
|
module::set_var("short_search_fix", "search_prefix", "1Z");
|
||||||
|
module::set_version("short_search_fix", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static function activate() {
|
||||||
|
$db = Database::instance();
|
||||||
|
$db->query("UPDATE {search_records} SET dirty=1;");
|
||||||
|
}
|
||||||
|
|
||||||
|
static function deactivate() {
|
||||||
|
$db = Database::instance();
|
||||||
|
$db->query("UPDATE {search_records} SET dirty=1;");
|
||||||
|
}
|
||||||
|
|
||||||
|
static function uninstall() {
|
||||||
|
$db = Database::instance();
|
||||||
|
module::clear_var("short_search_fix", "search_prefix");
|
||||||
|
}
|
||||||
|
}
|
7
3.0/modules/short_search_fix/module.info
Normal file
7
3.0/modules/short_search_fix/module.info
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
name = "Short Search Fix"
|
||||||
|
description = "Allows 2-3 letter searches to be performed without requiring SQL system variable modification (useful for shared hosting)."
|
||||||
|
version = 1
|
||||||
|
author_name = "Shad Laws"
|
||||||
|
author_url = ""
|
||||||
|
info_url = "http://codex.gallery2.org/Gallery3:Modules:short_search_fix"
|
||||||
|
discuss_url = "http://gallery.menalto.com/node/105935"
|
@ -0,0 +1,10 @@
|
|||||||
|
<?php defined("SYSPATH") or die("No direct script access.") ?>
|
||||||
|
<div class="g-block">
|
||||||
|
<h1> <?= t("Short search fix settings") ?> </h1>
|
||||||
|
<p>
|
||||||
|
<?= t("This module works by padding every search term with a prefix. Since MySQL system variables typically set the minimum search term to 4 characters, the default 2-character prefix makes all 2-letter searches valid.") ?>
|
||||||
|
</p>
|
||||||
|
<div class="g-block-content">
|
||||||
|
<?= $form ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
Reference in New Issue
Block a user