GNOME Bugzilla – Bug 764587
nautilus shell search provider only searches full words
Last modified: 2016-10-11 18:24:35 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.
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.
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.
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.
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.
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.
(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.
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).
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
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 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
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.
Review of attachment 337009 [details] [review]: Perfect, thanks!
Attachment 337009 [details] pushed as 2bbc67c - shell-search-provider: do not search for whole words only
*** Bug 771630 has been marked as a duplicate of this bug. ***