]> git.wh0rd.org Git - tt-rss.git/commitdiff
allow selecting stemming language in search dialog
authorAndrew Dolgov <noreply@madoka.volgo-balt.ru>
Tue, 4 Aug 2015 10:53:48 +0000 (13:53 +0300)
committerAndrew Dolgov <noreply@madoka.volgo-balt.ru>
Tue, 4 Aug 2015 10:53:48 +0000 (13:53 +0300)
classes/feeds.php
include/functions2.php

index 996b1b23fb824ad61df6f529481c1af966f4873c..ced6bbb4ab59ce2770fb6317e56bed53ecdbd0cc 100644 (file)
@@ -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 "<hr/><span style='float : right'>".T_sprintf('in %s', getFeedTitle($active_feed_id, $is_cat))."</span>";
 
+               if (DB_TYPE == "pgsql") {
+                       print "<hr/>";
+                       print_select("search_language", "", Pref_Feeds::$feed_languages,
+                               "dojoType='dijit.form.Select' title=\"".__('Used for word stemming')."\"");
+               }
+
                print "</div>";
 
                print "<div class=\"dlgButtons\">";
index 551d55d730838aee30c6c67df7111ef384957587..9e4f0b0e09f85d670a03aa33773538e04af12b2a 100644 (file)
                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);
 
                        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'))");
                        }
 
                }
                $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"];
 
                                // 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 {