After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 775961 - Search doesn't do full text search; only does filename search
Search doesn't do full text search; only does filename search
Status: RESOLVED FIXED
Product: nautilus
Classification: Core
Component: general
3.22.x
Other Linux
: Normal normal
: ---
Assigned To: Nautilus Maintainers
Nautilus Maintainers
: 776398 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2016-12-11 20:59 UTC by Nate Graham
Modified: 2018-04-30 23:26 UTC
See Also:
GNOME target: ---
GNOME version: 3.21/3.22


Attachments
Full text results only shown with tracker-needle, not Activities Overview search (1.51 MB, video/webm)
2016-12-11 20:59 UTC, Nate Graham
  Details
search-engine-tracker: Don't limit results to filename matches (1.23 KB, patch)
2017-04-06 10:36 UTC, Felipe Borges
needs-work Details | Review
implement fts (31.13 KB, patch)
2017-06-19 10:24 UTC, Alexandru Pandelea
none Details | Review
implement fts (32.83 KB, patch)
2017-06-20 20:44 UTC, Alexandru Pandelea
none Details | Review
implement fts (33.18 KB, patch)
2017-06-22 13:45 UTC, Alexandru Pandelea
committed Details | Review

Description Nate Graham 2016-12-11 20:59:51 UTC
Created attachment 341778 [details]
Full text results only shown with tracker-needle, not Activities Overview search

Fedora 25 + GNOME 3.22

The Activities Overview search only appears to do filename searching, not full-text searching. The attached video shows the problem: When I run a search for "incendiary" using tracker-needle, full-text search results are included. When I run the same search from Activities Overview, the only result displayed is a file with the word "incendiary" in the name. The text and PDF files with the word "incendiary" inside them are not displayed.
Comment 1 Florian Müllner 2016-12-11 23:02:33 UTC
gnome-shell itself only does search for applications (but even that implementation mostly lives in GIO nowadays). What is shown in the video is nautilus' search provider, so reassigning there.
Comment 2 Allan Day 2016-12-16 12:33:56 UTC
I'm inclined to agree - Files should do full text search and not just match file names. We have all this search power available to us, and we're not using it.

Imagine a situation where someone is searching for a term that appears inside their files, but isn't in the file names. Right now we wouldn't present any results at all, even though we have the capacity to return something.

As an optional extra, an extract from the file could be shown in the results list, in order to give a hint at why some files are being returned:

https://raw.githubusercontent.com/gnome-design-team/gnome-mockups/master/nautilus/nautilus-next/wire-search.png

However, I don't think that enabling full text search is dependent on this.
Comment 3 Nate Graham 2016-12-16 15:07:49 UTC
> Imagine a situation where someone is searching for a term that appears inside
> their files, but isn't in the file names. Right now we wouldn't present any
> results at all, even though we have the capacity to return something.

Yes, that's exactly my typical use case. I have to use tracker-needle instead of Nautilus or the Activities Overview search, which is a less satisfying user experience.
Comment 4 Felipe Borges 2017-04-06 10:36:29 UTC
Created attachment 349350 [details] [review]
search-engine-tracker: Don't limit results to filename matches

The filter SPARQL query was matching the query string to the
parent AND to the filename.

With this patch, the results are not limited to filename matches,
causing the fts:match search criteria to search within file
contents.
Comment 5 Felipe Borges 2017-04-06 10:38:21 UTC
(In reply to Felipe Borges from comment #4)
> Created attachment 349350 [details] [review] [review]
> search-engine-tracker: Don't limit results to filename matches
> 

Of course just showing the results is not enough, it is just a beginning, but I would rather present the results anyway.

For the Full text search feature, we should have UI and better ranking capabilities IMO.
Comment 6 Felipe Borges 2017-04-06 10:47:43 UTC
I was informed that there will be a GSoC/Outreachy project for this round about "Improving the Nautilus search" see https://wiki.gnome.org/Outreach/SummerOfCode/2017/Ideas
Comment 7 Carlos Soriano 2017-04-06 10:58:55 UTC
Review of attachment 349350 [details] [review]:

Hey Felipe,

Thanks for the patch! As you could imagine, the problem is that I'm not sure we want to show files that only matches text inside without any visual clue. This is even more important if we want to keep in mind the use cases of type-ahead for our search, as I have been trying in the past. I believe at some point we will need some way to limit results to only the file name, or give priority to those (even more than the current search ranking we have). This requires experimenting and tweaking, and for that I added it as task for GSoC. But if you feel like going ahead with it, please go :)

In any case, the patch would need work, so marking as such,
Comment 8 Florian Müllner 2017-04-06 10:59:04 UTC
Review of attachment 349350 [details] [review]:

::: src/nautilus-search-engine-tracker.c
@@ +346,3 @@
     else
     {
+        g_string_append_printf (sparql, "tracker:uri-is-descendant('%s', ?url) || ", location_uri);

Shouldn't non-recursive search in the branch above get the same treatment?
Comment 9 Nate Graham 2017-04-06 14:44:35 UTC
I was envisioning the full-text functionality being limited to just the global Activities Overview search, where it's clear that you're looking for things across the whole system. In Nautilus itself, this is problematic because of how search replaced type-ahead. If type-ahead was brought back, it would be a lot less problematic...
Comment 10 Carlos Soriano 2017-04-07 08:10:19 UTC
(In reply to Nate Graham from comment #9)
> I was envisioning the full-text functionality being limited to just the
> global Activities Overview search, where it's clear that you're looking for
> things across the whole system.
Search in Nautilus is across the system, all the times (except if you turn it off in preferences)

> In Nautilus itself, this is problematic
> because of how search replaced type-ahead. If type-ahead was brought back,
> it would be a lot less problematic...

Yeah, we want the current search to also cover part of the type-ahead use case. type-ahead itself clashes with the search, so we cannot include in the way that was previously done. You can take a look at our discussion in https://bugzilla.gnome.org/show_bug.cgi?id=681871
Comment 11 Nate Graham 2017-04-08 02:07:59 UTC
https://bugzilla.gnome.org/show_bug.cgi?id=681871 definitely seems like the right approach to me. Performing a search  when typing starts in a Nautilus window violates the principle of least astonishment (https://en.wikipedia.org/wiki/Principle_of_least_astonishment) and also makes the actual search UI invisible. Consider what would happen if a user starts typing accidentally; the whole view is replaced with a search view that they may not know how to exit from.

I think novice users would be much better served by having the search UI be clear and visible--invoked through a search box--and expert users would be better served by bringing back type-ahead.

And as a happy side effect, this would instantly resolve the thorny issue we're grappling with in this bug.
Comment 12 Carlos Soriano 2017-04-08 06:13:00 UTC
Hey Nate,

The type ahead vs search was thoughtfully discussed in the bug I commented and in the past. This is probably not a good bug report to discuss this.

Regarding principle of least astonishment, I see where are you coming from, but I don't think it applies that much in here - We use this pattern all through GNOME, and we give enough feedback that search is active, with the button active too, so the user can guess how to exit. Also regular shortcuts like <esc> continue working in there.

Also, I don't think this has much to do with this bug report, not having UI for FTS is the issue, nothing else, and has nothing to do with type-ahead, even if having that separation in the UI having a FTS without UI would be confusing.
Comment 13 Alexandru Pandelea 2017-06-19 10:24:34 UTC
Created attachment 354031 [details] [review]
implement fts
Comment 14 Carlos Garnacho 2017-06-20 11:59:17 UTC
Review of attachment 354031 [details] [review]:

It's shaping up well! I've found a few things to fix, mostly nits :).

::: data/org.gnome.nautilus.gschema.xml
@@ +220,3 @@
+    <key type="b" name="fts-default">
+      <default>true</default>
+      <summary>Whether to have full text search as default when opening a new window/tab</summary>

I suggest s/as default/enabled by default/ here

@@ +221,3 @@
+      <default>true</default>
+      <summary>Whether to have full text search as default when opening a new window/tab</summary>
+      <description>If set to true, then Nautilus will also match the file contents besides the name</description>

This just toggles the checkbutton default active state, right? Would be nice to mention it, and that users can still override it in the UI.

::: src/nautilus-file.c
@@ +925,3 @@
+    if (file->details->fts_snippet)
+    {
+        g_free (file->details->fts_snippet);

free/g_free are already NULL aware, you can remove the if() check

@@ +6157,3 @@
+void
+nautilus_file_set_search_fts_snippet (NautilusFile *file,
+                                      gchar        *fts_snippet)

Since you're copying this string and leaving it unmodified, it's better to pass it as const gchar*

@@ +6165,3 @@
+nautilus_file_get_search_fts_snippet (NautilusFile *file)
+{
+    return file->details->fts_snippet;

And here you're returning the internal copy which is not for the caller to modify, so better make this function return const gchar* as well.

::: src/nautilus-list-view.c
@@ +1570,3 @@
                         -1);
 
+    escaped_name = g_markup_escape_text (text, g_utf8_strlen (text, -1));

Using g_utf8_strlen here is subtly wrong, as it returns the count of utf8 characters, whereas basically all glib functions that take a "len" argument expect byte length as returned by strlen().

Taking the word "ñoño" as an example, g_utf8_strlen would return 4 while strlen would return 6 (because each 'ñ' takes 2 bytes). It would effectively mean that you're asking g_markup_escape_text to process text until the middle of the second 'ñ', which yields invalid utf8.

In this case you can simply pass -1 here to g_markup_escape_text, since the string is NUL-terminated

@@ +1616,3 @@
+        {
+            replaced_text = eel_str_replace_substring (snippet, "\n", "");
+            escaped_text = g_markup_escape_text (replaced_text, g_utf8_strlen (replaced_text, -1));

Same here, just pass -1.

::: src/nautilus-search-engine-tracker.c
@@ +333,3 @@
     mime_count = g_list_length (mimetypes);
 
+    sparql = g_string_new ("SELECT DISTINCT nie:url(?urn) fts:rank(?urn) nfo:fileLastModified(?urn) nfo:fileLastAccessed(?urn) fts:snippet(?urn)\n"

Would maybe be nicer to make the fts:snippet argument optional depending on fts_enabled? that'd also mean that you have to optionally get the result through tracker_sparql_cursor_get_string(cursor,4,NULL);

::: src/nautilus-search-hit.c
@@ +49,3 @@
     PROP_ACCESS_TIME,
     PROP_FTS_RANK,
+    PROP_FTS_SNIPPET,

Hmm, you added this but didn't do g_object_class_install_property(), I see you handle it in set_property(), but didn't do the same with get_property(). I think that makes sense since you have a getter function.

@@ +162,3 @@
 
+gchar *
+nautilus_search_hit_get_fts_snippet (NautilusSearchHit *hit)

This function should return const gchar* too :)

@@ +224,3 @@
+    if (hit->fts_snippet)
+    {
+        g_free (hit->fts_snippet);

No need for NULL checks before g_free

::: src/nautilus-search-popover.c
@@ +803,3 @@
+                                        NULL,
+                                        NULL,
+                                        g_cclosure_marshal_generic,

This is not wrong per se, but IMHO g_cclosure_marshal_VOID__BOOLEAN is better to use here. The generic marshaler is considerably slower, which I guess doesn't matter a lot here, but glib already provides us the better fit (i.e. no need to generate it).

...And on second thought, you have a signal communicate updates to the fts_enabled boolean, that's basically a pseudoproperty. IMHO it seems nicer to actually make this a property, do g_object_notify() and g_signal_connect(...,"notify::fts-enabled") on the other end.
Comment 15 Alexandru Pandelea 2017-06-20 20:44:31 UTC
Created attachment 354125 [details] [review]
implement fts

The search text can now also match the contents of a file, besides
the file name.

This is done with the help of a Tracker query, using fts:match, which
matces both the contents of a file and the filename.

The user also has the option to choose whether to use or not the
Full Text Search. This can be done with a preference, which represents
the default option when opening a new tab/window or from the search
popover.
Comment 16 Carlos Garnacho 2017-06-22 13:13:42 UTC
Review of attachment 354125 [details] [review]:

Looks good! just minor 2 nits I found, I don't think another review round is necessary after those, so feel free to push after fixing locally.

::: src/nautilus-search-hit.c
@@ +321,3 @@
+        case PROP_FTS_SNIPPET:
+        {
+            g_value_set_string (value, hit->fts_snippet);

You do handle get_property() here and added the property for real. Good :), but the set_property() counterpart is still missing.

@@ +350,3 @@
 
+    if (hit->fts_snippet)
+        g_free (hit->fts_snippet);

No need for NULL check
Comment 17 Alexandru Pandelea 2017-06-22 13:45:27 UTC
Created attachment 354249 [details] [review]
implement fts

The search text can now also match the contents of a file, besides
the file name.

This is done with the help of a Tracker query, using fts:match, which
matces both the contents of a file and the filename.

The user also has the option to choose whether to use or not the
Full Text Search. This can be done with a preference, which represents
the default option when opening a new tab/window or from the search
popover.
Comment 18 Alexandru Pandelea 2017-06-22 13:52:26 UTC
Attachment 354249 [details] pushed as 11cbe22 - implement fts
Comment 19 António Fernandes 2018-04-30 23:26:43 UTC
*** Bug 776398 has been marked as a duplicate of this bug. ***