Bug 357960

Summary: baloosearch cannot filter rating criteria correctly
Product: [Frameworks and Libraries] frameworks-baloo Reporter: Saman <svps777+kde>
Component: EngineAssignee: Stefan Brüns <stefan.bruens>
Status: RESOLVED FIXED    
Severity: major CC: aspotashev, nate, noein93, pinak.ahuja, stefan.bruens
Priority: NOR    
Version: 5.18.0   
Target Milestone: ---   
Platform: Fedora RPMs   
OS: Linux   
Latest Commit: Version Fixed In: 5.53

Description Saman 2016-01-14 02:57:46 UTC
Consider below command:
baloosearch -d. "rating>=10" | grep -i unconditionally
output:
/path/to/directory/Katy Perry/Katy Perry - Unconditionally (Official)-XjwZAa2EjKA.mp4

and consider the output of getfattr:
getfattr -d Katy\ Perry\ -\ Unconditionally\ \(Official\)-XjwZAa2EjKA.mp4 
# file: Katy Perry - Unconditionally (Official)-XjwZAa2EjKA.mp4
user.baloo.rating="8"

So baloosearch shouldn't show that file. I'm using Fedora 23 65 bit:
rpm -qa | grep -i baloo
kf5-baloo-file-5.18.0-1.fc23.x86_64
baloo-kcmadv-1.00.00-1.fc22.x86_64
kf5-baloo-5.18.0-1.fc23.x86_64
kf5-baloo-libs-5.18.0-1.fc23.x86_64
baloo-widgets-15.08.1-1.fc23.x86_64
baloo-libs-4.14.3-5.fc23.x86_64

Reproducible: Always

Steps to Reproduce:
1. set "user.baloo.rating" xattribute to 8 for foo.mp4
2. run baloosearch -d. "rating>=10"
3. The file will appear in the result.

Actual Results:  
A set of files in which there are some files that don't have rating >= 10

Expected Results:  
The set of files must have rating >= 10
Comment 1 Nate Graham 2017-10-27 18:33:19 UTC
Are you still able to reproduce this issue? It works for me using KDE Frameworks 5.39.0 in KDE Neon.
Comment 2 Saman 2017-10-28 02:28:13 UTC
(In reply to Nate Graham from comment #1)
> Are you still able to reproduce this issue? It works for me using KDE
> Frameworks 5.39.0 in KDE Neon.

I'm using Frameworks 5.38.0 (Fedora 26) and I can't reproduce the bug. It is fixed!
Comment 3 Nate Graham 2017-10-28 02:28:51 UTC
Fabulous!
Comment 4 Saman 2017-10-28 02:35:27 UTC
(In reply to Nate Graham from comment #3)
> Fabulous!

Sorry my mistake. The problem still exists in 5.38.0. But the following issue is fixed in my framework version: https://bugs.kde.org/show_bug.cgi?id=378884
Comment 5 Nate Graham 2017-10-28 02:54:42 UTC
Still can't repro, but if you can, we'll keep this open and resume investigating.
Comment 6 Saman 2017-10-28 07:27:51 UTC
(In reply to Nate Graham from comment #5)
> Still can't repro, but if you can, we'll keep this open and resume
> investigating.

Unlike previous versions, the problem sometimes happens. It's strange on the same directory I see the problem but after some tries, I can't reproduce it. I try to test it more.
Comment 7 Saman 2017-10-28 18:10:53 UTC
I can reproduce this bug in Baloo 5.38.0:

$ baloosearch -d. "rating=9" | grep -v "Elapsed:" | wc -l

The output is 9

then I run the following command:

$ baloosearch -d. "rating=10" | grep -v "Elapsed:" | wc -l

The output is 5

So I expect to see 14 for the following command but I see 9 instead:

$ baloosearch -d. "rating>=9" | grep -v "Elapsed:" | wc -l

In other words there is no difference between "=" and ">=" operators.
Comment 8 Saman 2017-10-28 18:27:28 UTC
Some test cases which baloo failed in 5.38.0:

1. Create a directory named baloo_test
2. Create two files "rating10.txt" and "rating9.txt". Give rating 10 to the former and 9 to the latter.

I can see the following wrong results:

$ baloosearch -d. "rating>=10"
rating10.txt
rating9.txt

$ baloosearch -d. "rating>=9"
rating9.txt

$ baloosearch -d. "rating<=10"
rating10.txt

$ baloosearch -d. "rating<=9"
rating10.txt
rating9.txt

$ baloosearch -d. "rating<=2"
rating10.txt
Comment 9 Stefan Brüns 2018-12-01 13:48:49 UTC
Git commit e1045c4f7891e012e03caf9b1f5a5c81c585e282 by Stefan Brüns.
Committed on 01/12/2018 at 13:48.
Pushed by bruns into branch 'master'.

Fix searches for rating 10 (5 stars)

Summary:
The comparator callback/lambda used a string comparision, which returned
the wrong documents, as "2" > "10", and "10" < "9", i.e. selecting the
"Highest rating" in dolphin returned all documents with a rating of 2
or higher.

Convert the numeric suffix of the rating term ("R2", "R10", ...) to
an integer value and use it for comparision.

Reviewers: #baloo, #frameworks, ngraham, poboiko, mgallien

Reviewed By: #baloo, ngraham

Subscribers: kde-frameworks-devel

Tags: #frameworks, #baloo

Differential Revision: https://phabricator.kde.org/D17272

M  +2    -2    autotests/unit/engine/postingdbtest.cpp
M  +5    -5    src/engine/postingdb.cpp
M  +1    -1    src/engine/postingdb.h
M  +1    -1    src/engine/transaction.cpp
M  +1    -1    src/engine/transaction.h
M  +3    -4    src/lib/searchstore.cpp

https://commits.kde.org/baloo/e1045c4f7891e012e03caf9b1f5a5c81c585e282