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 764587 - nautilus shell search provider only searches full words
nautilus shell search provider only searches full words
Status: RESOLVED FIXED
Product: nautilus
Classification: Core
Component: File Search Interface
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Nautilus Maintainers
Nautilus Maintainers
Depends on:
Blocks:
 
 
Reported: 2016-04-04 13:34 UTC by Jiri Cerny
Modified: 2016-10-11 18:24 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
make gnome-shell-search work with prefix only (702 bytes, patch)
2016-04-07 08:38 UTC, Jiri Cerny
rejected Details | Review
another try to make the prefix search work (706 bytes, patch)
2016-04-10 08:08 UTC, Jiri Cerny
reviewed Details | Review
shell-search-provider: do not search for whole words only (1.05 KB, patch)
2016-10-05 19:23 UTC, Jiri Cerny
committed Details | Review

Description Jiri Cerny 2016-04-04 13:34:23 UTC
With nautilus-3.20 on fedora 24 alpha, when I search for 'Biblio', say,  in the gnome-shell search box, there are no results even if I have a file 'Bibliography' in one of the subfolders of my home. Only if I type the full name 'Bibliography' into the box, the result appear. This is not very practical, since find-as-type does not work.

If I use nautilus search function inside of a nautilus window, everything works correctly.
Comment 1 Carlos Soriano 2016-04-05 07:32:30 UTC
I believe this is for newcomers with some small knowledge already, just try to check the differences on searching for the two ways and investigate how to make it work.
Comment 2 Jiri Cerny 2016-04-07 07:47:59 UTC
I tried to try to understand why the two searches are different (I am not developer, so I might be wrong). 
Looking on source code, the first difference seems to be that gnome-shell search provider uses only tracker search provider, while the nautilus window search uses also simple and model(??) search providers. But this does not seem to be a problem.

Reading libnautilus-provider/nautilus-search-engine-tracker.c it seems that the following query (simplified, without mime types, modification dates, etc.) is passed to tracker

SELECT DISTINCT nie:url(?urn) fts:rank(?urn) nfo:fileLastModified(?urn) nfo:fileLastAccessed(?urn) WHERE { ?urn a nfo:FileDataObject; nfo:fileLastModified ?mtime; nfo:fileLastAccessed ?atime; tracker:available true; fts:match '"%s*"' . FILTER( fn:contains(fn:lower-case(nfo:fileName(?urn)), '%s'))} ORDER BY DESC (fts:rank(?urn)), 

where %s is the search term. Observe that %s is there twice, once as fts:match (I suppose full text search) and once as fn:contains (?file name contains).

I tried to run various versions of this query through "tracker-sparql -q" command, and observed the following

- If the fts:match part is deleted from the query, than it works as I expect: Searching for 'biblio' gives all files and directories whose name contains biblio as substring

- If one keeps only the fts:match part, then it searches only for whole words.

The second seems to be a problem. Observe that there is %s* in the argument of fts:match, so, according to https://wiki.gnome.org/Projects/Tracker/Documentation/Examples/SPARQL/FTS, it should search for prefix (not substring but it would be fine). In reality it seems to look for whole words only, i.e. this might be a tracker problem.

I also do not understand why the fts:match part is needed when the query works correctly (at least for me) without it.
Comment 3 Jiri Cerny 2016-04-07 08:38:53 UTC
Created attachment 325524 [details] [review]
make gnome-shell-search work with prefix only

One additional remark,
If one replaces fts:match '"%s*"' in the above query by fts:match '%s*', then it corrects the problem for me. I rebuild nautilus with this patch and everything is fine.
Comment 4 Jiri Cerny 2016-04-07 20:57:43 UTC
Please ignore the previous patch, it has problems: It is not possible to search for full filenames like 'foo.txt'. It is then a wrong syntax.

I believe now that this problem is a regression between 3.18 and 3.20 (or fedora 23, 24?). The query from comment #2 gives desired results on an older system, but fails on a new one. 

Can it be related to some tracker changes?

In any case, it does not seem to be a 'newcomer' issue.
Comment 5 Carlos Soriano 2016-04-07 21:11:33 UTC
Hey Jiri,

Thanks for taking the time to dig into this.
I think it's fine for a newcomer with some experience already, since it's easily reproducible, a "print" debug can easily spot the source of the problem.

Maybe it's true the tracker query is not easy to debug, if that's the source of the problem. Feel free to choose a different newcomer bug report.

AS a side note, I don't think it's related to tracker. We changed that query from 3.18 to 3.20, so that might be the issue.
Comment 6 Jiri Cerny 2016-04-08 15:12:08 UTC
(In reply to Carlos Soriano from comment #5)

Actually I believe that this is related to tracker. I put the following simpilfed query to a file, say foo,

SELECT DISTINCT nie:url(?urn) fts:rank(?urn) nfo:fileLastModified(?urn) nfo:fileLastAccessed(?urn) WHERE { ?urn a nfo:FileDataObject; nfo:fileLastModified ?mtime; nfo:fileLastAccessed ?atime; tracker:available true; fts:match '\"biblio*\"' . FILTER( fn:contains(fn:lower-case(nfo:fileName(?urn)), 'biblio'))} ORDER BY DESC (fts:rank(?urn))

and then run 

tracker sparql -f foo 

On Fedora 23 it finds the directory "Bibliography" somewhere in my home tree, on Fedora 24 it finds nothing. 

Observe that there is no nautilus involved here. 

Also, I am really not sparql expert but https://wiki.gnome.org/Projects/Tracker/Documentation/Examples/SPARQL/FTS, section about Sentences says

"... If any FTS-syntax operator appears inside the sentence (between the escaped double-quotes), it will NOT be treated as an operator, and will be removed from the query. ..."

so I actually do not understand why 

fts:match '\"biblio*\"'

should match Bibliography. If I read it correctly the * should be ignored, i.e. F24 behaviour is correct.
Comment 7 Jiri Cerny 2016-04-10 08:08:28 UTC
Created attachment 325650 [details] [review]
another try to make the prefix search work

After some more digging, I find out that putting the * out of the quotation marks,
makes the search work as expected on 3.20/F24, at least for me (see the attached patch). 

Problem is that the same patch breaks 3.18/F23. 

It must be tracker/sqlite issue (whatever parses the query).
Comment 8 Jiri Cerny 2016-08-28 08:37:28 UTC
The problem disappeared in 3.20.2, at least partially: The gnome-shell search finds what it should, but it seems that it takes more time than before. 

The reason why the problem disappeared is probably
https://git.gnome.org/browse/nautilus/commit/?id=2668164

I.e. the bug seems to be related to
https://bugzilla.gnome.org/show_bug.cgi?id=766174
Comment 9 Carlos Soriano 2016-10-04 19:32:48 UTC
Review of attachment 325650 [details] [review]:

This is obvious, how it slipped my eyes!
So reading https://wiki.gnome.org/Projects/Tracker/Documentation/Examples/SPARQL/FTS#Sentences everything inside "" will be removed if it's an operator. So your patch makes sense, thanks a lot!

However it lacks commit message, could you add one following https://wiki.gnome.org/Newcomers/CodeContributionWorkflow#Commit_guidelines?

thanks!
Comment 10 Carlos Soriano 2016-10-04 19:33:28 UTC
Comment on attachment 325524 [details] [review]
make gnome-shell-search work with prefix only

rejected because this will make the search not a sentence one, following https://wiki.gnome.org/Newcomers/CodeContributionWorkflow#Commit_guidelines
Comment 11 Jiri Cerny 2016-10-05 19:23:13 UTC
Created attachment 337009 [details] [review]
shell-search-provider: do not search for whole words only

Starting from 3.20 the shell search works only for whole words, not
prefixes. Make it work again.
Comment 12 Carlos Soriano 2016-10-05 19:51:04 UTC
Review of attachment 337009 [details] [review]:

Perfect, thanks!
Comment 13 Carlos Soriano 2016-10-11 18:23:47 UTC
Attachment 337009 [details] pushed as 2bbc67c - shell-search-provider: do not search for whole words only
Comment 14 Carlos Soriano 2016-10-11 18:24:35 UTC
*** Bug 771630 has been marked as a duplicate of this bug. ***