bpatrik / pigallery2

A fast directory-first photo gallery website, with rich UI, optimized for running on low resource servers (especially on raspberry pi)
http://bpatrik.github.io/pigallery2/
MIT License
1.71k stars 197 forks source link

Improving keyword filtering #907

Open jlvdb opened 2 months ago

jlvdb commented 2 months ago

When filtering on keywords, the current behavior seems to be that only images are selected that match all the selected keywords. However, if an image has multiple keywords/tags, the image is only selected if all the tags have been selected, which makes it difficult to find such photos.

My suggestion would be to change the behavior from matching images that have all to having any of the selected keywords/tags.

jlvdb commented 1 month ago

After trying to figure out what the corresponding code does (in FilterService.applyFilters), it seems to be a limitation of the current implementation when dealing with meta data that are array-like (isArrayValue), such as the keywords. The filtering is done "in reverse", i.e. the code goes through all unselected keywords and rejects images that contain them. While this is fine for single value meta data, for arrays this leads to unexpected behavior.

Example

An example: You select keyA and keyB, which means deselecting keyC. You have images A (with keywords keyA), AB (with keywords keyA, keyB), AC (with keywords keyA, keyC), and ABC (with keywords keyA, keyC, keyC).

Expected result

Actual result

The selection for cases, where only some of the keywords or additional keywords are present, are being reversed.

bpatrik commented 3 weeks ago

Yeah I agree that indeed seems to be confusing.

If you have the time, I would appreciate if you can send a PR. Otherwise I don't I will get to it any time soon like O(years)