[nautilus/wip/oholy/tracker] search-engine-tracker: Do not lose filename results due to stop words
- From: Ondrej Holy <oholy src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/oholy/tracker] search-engine-tracker: Do not lose filename results due to stop words
- Date: Thu, 5 Dec 2019 14:48:52 +0000 (UTC)
commit 53e205d8310703be85697f18294400b0f5509d20
Author: Ondrej Holy <oholy redhat com>
Date: Thu Dec 5 13:45:37 2019 +0100
search-engine-tracker: Do not lose filename results due to stop words
Tracker uses list of stop words which are not indexed. Consequently,
fts:match doesn't provide any results for such words, which also affects
filenames. I am conviced that this is not crucial issue for content
search, but it is really problem in case of filename search. We should
really always find files regardless of stop words in their names. This
can be fixed on Nautilus side by splitting the search string and using
ftp:match only for content search.
For example, currently it is not possible to find "file-name.txt" file
using "file-n" search string, because "name" is stop word, but it works
nicely with this fix.
Just note that /org/freedesktop/tracker/fts/ignore-stop-words setting
needs to be changed to fix this issue for content search as well.
See the original downstream report:
https://bugzilla.redhat.com/show_bug.cgi?id=1646352
src/nautilus-search-engine-tracker.c | 43 +++++++++++++++++++++++++++---------
1 file changed, 32 insertions(+), 11 deletions(-)
---
diff --git a/src/nautilus-search-engine-tracker.c b/src/nautilus-search-engine-tracker.c
index 66494cae8..67f1121b3 100644
--- a/src/nautilus-search-engine-tracker.c
+++ b/src/nautilus-search-engine-tracker.c
@@ -286,6 +286,9 @@ search_finished_idle (gpointer user_data)
return FALSE;
}
+/* This is used to compensate rank if fts:rank is not set (resp. fts:match is not used). */
+#define FILENAME_RANK 5.0
+
static void
nautilus_search_engine_tracker_start (NautilusSearchProvider *provider)
{
@@ -327,7 +330,11 @@ nautilus_search_engine_tracker_start (NautilusSearchProvider *provider)
location_uri = location ? g_file_get_uri (location) : NULL;
mimetypes = nautilus_query_get_mime_types (tracker->query);
- sparql = g_string_new ("SELECT DISTINCT nie:url(?urn) fts:rank(?urn) nfo:fileLastModified(?urn)
nfo:fileLastAccessed(?urn)");
+ sparql = g_string_new ("SELECT DISTINCT"
+ " nie:url(?urn)"
+ " xsd:double(COALESCE(?rank2, ?rank1)) AS ?rank"
+ " nfo:fileLastModified(?urn)"
+ " nfo:fileLastAccessed(?urn)");
if (tracker->fts_enabled)
{
@@ -342,14 +349,33 @@ nautilus_search_engine_tracker_start (NautilusSearchProvider *provider)
" tracker:available true;"
" nie:url ?url");
- if (*search_text)
+ if (mimetypes->len > 0)
{
- g_string_append_printf (sparql, "; fts:match '\"%s\"*'", search_text);
+ g_string_append (sparql, "; nie:mimeType ?mime");
}
- if (mimetypes->len > 0)
+ if (tracker->fts_enabled)
{
- g_string_append (sparql, "; nie:mimeType ?mime");
+ /* Use fts:match only for content search to not lose some filename results due to stop words. */
+ g_string_append_printf (sparql,
+ " { ?urn fts:match '\"nie:plainTextContent\" : \"%s\"*' ."
+ " BIND(fts:rank(?urn) AS ?rank1) } UNION {",
+ search_text);
+ }
+ else
+ {
+ g_string_append_printf (sparql, " .");
+ }
+
+ g_string_append_printf (sparql,
+ " BIND(%f AS ?rank2) ."
+ " FILTER(fn:contains(fn:lower-case(nfo:fileName(?urn)), '%s'))",
+ FILENAME_RANK,
+ search_text);
+
+ if (tracker->fts_enabled)
+ {
+ g_string_append_printf (sparql, "}");
}
g_string_append_printf (sparql, " . FILTER( ");
@@ -363,11 +389,6 @@ nautilus_search_engine_tracker_start (NautilusSearchProvider *provider)
g_string_append_printf (sparql, "tracker:uri-is-descendant('%s', ?url)", location_uri);
}
- if (!tracker->fts_enabled)
- {
- g_string_append_printf (sparql, " && fn:contains(fn:lower-case(nfo:fileName(?urn)), '%s')",
search_text);
- }
-
date_range = nautilus_query_get_date_range (tracker->query);
if (date_range)
{
@@ -424,7 +445,7 @@ nautilus_search_engine_tracker_start (NautilusSearchProvider *provider)
g_string_append (sparql, ")\n");
}
- g_string_append (sparql, ")} ORDER BY DESC (fts:rank(?urn))");
+ g_string_append (sparql, ")} ORDER BY DESC (?rank)");
tracker->cancellable = g_cancellable_new ();
tracker_sparql_connection_query_async (tracker->connection,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]