From 60e680599d200134db6f8e07f797d099e330c8a2 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 4 Aug 2015 13:53:48 +0300 Subject: [PATCH] allow selecting stemming language in search dialog --- classes/feeds.php | 8 ++++++++ include/functions2.php | 12 +++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/classes/feeds.php b/classes/feeds.php index 996b1b23f..ced6bbb4a 100644 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -202,6 +202,7 @@ class Feeds extends Handler_Protected { } @$search = $this->dbh->escape_string($_REQUEST["query"]); + @$search_language = $this->dbh->escape_string($_REQUEST["search_language"]); // PGSQL only if ($search) { $disable_cache = true; @@ -247,6 +248,7 @@ class Feeds extends Handler_Protected { "view_mode" => $view_mode, "cat_view" => $cat_view, "search" => $search, + "search_language" => $search_language, "override_order" => $override_order, "offset" => $offset, "include_children" => $include_children, @@ -1143,6 +1145,12 @@ class Feeds extends Handler_Protected { print "
".T_sprintf('in %s', getFeedTitle($active_feed_id, $is_cat)).""; + if (DB_TYPE == "pgsql") { + print "
"; + print_select("search_language", "", Pref_Feeds::$feed_languages, + "dojoType='dijit.form.Select' title=\"".__('Used for word stemming')."\""); + } + print ""; print "
"; diff --git a/include/functions2.php b/include/functions2.php index 551d55d73..9e4f0b0e0 100644 --- a/include/functions2.php +++ b/include/functions2.php @@ -280,13 +280,18 @@ return $data; } - function search_to_sql($search) { + function search_to_sql($search, $search_language) { $keywords = str_getcsv($search, " "); $query_keywords = array(); $search_words = array(); $search_query_leftover = array(); + if ($search_language) + $search_language = db_escape_string(mb_strtolower($search_language)); + else + $search_language = "english"; + foreach ($keywords as $k) { if (strpos($k, "-") === 0) { $k = substr($k, 1); @@ -402,7 +407,7 @@ if (DB_TYPE == "pgsql") { array_push($query_keywords, - "(tsvector_combined @@ to_tsquery('english', '$search_query_leftover'))"); + "(tsvector_combined @@ to_tsquery('$search_language', '$search_query_leftover'))"); } } @@ -447,6 +452,7 @@ $view_mode = $params["view_mode"]; $cat_view = isset($params["cat_view"]) ? $params["cat_view"] : false; $search = isset($params["search"]) ? $params["search"] : false; + $search_language = isset($params["search_language"]) ? $params["search_language"] : ""; $override_order = isset($params["override_order"]) ? $params["override_order"] : false; $offset = isset($params["offset"]) ? $params["offset"] : 0; $owner_uid = isset($params["owner_uid"]) ? $params["owner_uid"] : $_SESSION["uid"]; @@ -471,7 +477,7 @@ // fall back in case of no plugins if (!$search_query_part) { - list($search_query_part, $search_words) = search_to_sql($search); + list($search_query_part, $search_words) = search_to_sql($search, $search_language); } $search_query_part .= " AND "; } else {