allow selecting stemming language in search dialog

This commit is contained in:
Andrew Dolgov 2015-08-04 13:53:48 +03:00
parent df659891ac
commit 60e680599d
2 changed files with 17 additions and 3 deletions

View File

@ -202,6 +202,7 @@ class Feeds extends Handler_Protected {
} }
@$search = $this->dbh->escape_string($_REQUEST["query"]); @$search = $this->dbh->escape_string($_REQUEST["query"]);
@$search_language = $this->dbh->escape_string($_REQUEST["search_language"]); // PGSQL only
if ($search) { if ($search) {
$disable_cache = true; $disable_cache = true;
@ -247,6 +248,7 @@ class Feeds extends Handler_Protected {
"view_mode" => $view_mode, "view_mode" => $view_mode,
"cat_view" => $cat_view, "cat_view" => $cat_view,
"search" => $search, "search" => $search,
"search_language" => $search_language,
"override_order" => $override_order, "override_order" => $override_order,
"offset" => $offset, "offset" => $offset,
"include_children" => $include_children, "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>"; 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>";
print "<div class=\"dlgButtons\">"; print "<div class=\"dlgButtons\">";

View File

@ -280,13 +280,18 @@
return $data; return $data;
} }
function search_to_sql($search) { function search_to_sql($search, $search_language) {
$keywords = str_getcsv($search, " "); $keywords = str_getcsv($search, " ");
$query_keywords = array(); $query_keywords = array();
$search_words = array(); $search_words = array();
$search_query_leftover = 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) { foreach ($keywords as $k) {
if (strpos($k, "-") === 0) { if (strpos($k, "-") === 0) {
$k = substr($k, 1); $k = substr($k, 1);
@ -402,7 +407,7 @@
if (DB_TYPE == "pgsql") { if (DB_TYPE == "pgsql") {
array_push($query_keywords, 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"]; $view_mode = $params["view_mode"];
$cat_view = isset($params["cat_view"]) ? $params["cat_view"] : false; $cat_view = isset($params["cat_view"]) ? $params["cat_view"] : false;
$search = isset($params["search"]) ? $params["search"] : 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; $override_order = isset($params["override_order"]) ? $params["override_order"] : false;
$offset = isset($params["offset"]) ? $params["offset"] : 0; $offset = isset($params["offset"]) ? $params["offset"] : 0;
$owner_uid = isset($params["owner_uid"]) ? $params["owner_uid"] : $_SESSION["uid"]; $owner_uid = isset($params["owner_uid"]) ? $params["owner_uid"] : $_SESSION["uid"];
@ -471,7 +477,7 @@
// fall back in case of no plugins // fall back in case of no plugins
if (!$search_query_part) { 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 "; $search_query_part .= " AND ";
} else { } else {