Photo Organizer

This is the bug tracker for Photo Organizer.
Tasklist

FS#158 - AND in search for keywords does not work

Attached to Project: Photo Organizer
Opened by Peter Kreussel (pepe) - Tuesday, 02 January 2007, 09:27 GMT-5
Task Type Bug Report
Category Backend / Core
Status Closed
Assigned To Solomon Peachy (pizza)
Operating System All
Severity High
Priority Normal
Reported Version Stable
Due in Version Undecided
Due Date 2007-01-02
Percent Complete 100%
Votes 0
Private No

Details

Searching for 2 keywords linked with AND always gives back an empty result.
Eg.: I have 2 images that both have the keywords "abstract" and "art" attached to them. They can't be found by the search "abstract AND art".

Looking at the SQL that PO sends to the database, I could trace the error. The search above produces the SQL:

[...]
OR photo.identifier in (select k.photo from photo_keywords k where (k.keyword ~* 'abstract' and k.keyword ~* 'art'))
[...]

This seems to be wrong since k.keyword contains only ONE keyword at a time. So "k.keyword ~* 'abstract' and k.keyword ~* 'art'" will never find a corresponding line in the database.

The SQL-part about keywords should be

photo.identifier in(select k.photo from photo_keywords k where k.keyword ~* 'abstract') and photo.identifier in(select k.photo from photo_keywords k where k.keyword ~* 'art')

The "AND" must be between the two "in(select... )"-Subqueries, not in them.

The problem in the code is in search.text.general.php, line 160, where a string plus the build_sql_search_string-function are used to generate $sql_search_keyword. I would suggest to write a new function, which is the same as build_sql_search_string() exept the part that handles "AND". This should be something like:


elseif (strncmp($keyword[operator], "AND", 3) == 0) {
if ($sql_search_string == "")
$sql_search_string = "photo.identifier in (select k.photo from photo_keywords k where " .sprintf("%s %s", $sql_field_name, $keyword[keyword]);
else
$sql_search_string .= " and photo.identifier in (select k.photo from photo_keywords k where " .sprintf("%s %s", $sql_field_name, $keyword[keyword]).")";
}

In line 160 in search.text.general.php ")" should be added to the return of this new function at the end, but no text at the beginning.
That should fix the simple search.
I have not investigated into the complex search, which doesn't find keywords linked by "AND" either.
This task depends upon

Closed by  Solomon Peachy (pizza)
Sunday, 21 January 2007, 14:24 GMT-5
Reason for closing:  Fixed
Additional comments about closing:  Whee, done.
Comment by Solomon Peachy (pizza) - Tuesday, 09 January 2007, 17:08 GMT-5
I've never actually tested complex keyword searches, so in hindsight it's not surprising this hit.

The search SQL generation code really needs to be rewritten, as it's pretty ugly, not to mention very, very slow.
Comment by Solomon Peachy (pizza) - Sunday, 21 January 2007, 14:11 GMT-5
A proper fix has been checked into the -devel tree; backporting will happen next. Once that's done, the 2.33b release will come out.
Comment by Solomon Peachy (pizza) - Sunday, 21 January 2007, 14:12 GMT-5
backported to -stable, in r1057

Loading...