merge image ID lists before scanning the images table, not after
This commit is contained in:
parent
f81fa08077
commit
fd725d3363
@ -613,6 +613,9 @@ class Image {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* WARNING: this description is no longer accurate, though it does get across
|
||||||
|
* the general idea - the actual method has a few extra optimisiations
|
||||||
|
*
|
||||||
* "foo bar -baz user=foo" becomes
|
* "foo bar -baz user=foo" becomes
|
||||||
*
|
*
|
||||||
* SELECT * FROM images WHERE
|
* SELECT * FROM images WHERE
|
||||||
@ -746,32 +749,29 @@ class Image {
|
|||||||
$have_pos = count($positive_tag_id_array) > 0;
|
$have_pos = count($positive_tag_id_array) > 0;
|
||||||
$have_neg = count($negative_tag_id_array) > 0;
|
$have_neg = count($negative_tag_id_array) > 0;
|
||||||
|
|
||||||
$sql = "SELECT images.* FROM images WHERE ";
|
$sql = "SELECT images.* FROM images WHERE images.id IN (";
|
||||||
if($have_pos) {
|
if($have_pos) {
|
||||||
$positive_tag_id_list = join(', ', $positive_tag_id_array);
|
$positive_tag_id_list = join(', ', $positive_tag_id_array);
|
||||||
$sql .= "
|
$sql .= "
|
||||||
images.id IN (
|
|
||||||
SELECT image_id
|
SELECT image_id
|
||||||
FROM image_tags
|
FROM image_tags
|
||||||
WHERE tag_id IN ($positive_tag_id_list)
|
WHERE tag_id IN ($positive_tag_id_list)
|
||||||
GROUP BY image_id
|
GROUP BY image_id
|
||||||
HAVING COUNT(image_id)>=$positive_tag_count
|
HAVING COUNT(image_id)>=$positive_tag_count
|
||||||
)
|
|
||||||
";
|
";
|
||||||
}
|
}
|
||||||
if($have_pos && $have_neg) {
|
if($have_pos && $have_neg) {
|
||||||
$sql .= " AND ";
|
$sql .= " EXCEPT ";
|
||||||
}
|
}
|
||||||
if($have_neg) {
|
if($have_neg) {
|
||||||
$negative_tag_id_list = join(', ', $negative_tag_id_array);
|
$negative_tag_id_list = join(', ', $negative_tag_id_array);
|
||||||
$sql .= "
|
$sql .= "
|
||||||
images.id NOT IN (
|
|
||||||
SELECT image_id
|
SELECT image_id
|
||||||
FROM image_tags
|
FROM image_tags
|
||||||
WHERE tag_id IN ($negative_tag_id_list)
|
WHERE tag_id IN ($negative_tag_id_list)
|
||||||
)
|
|
||||||
";
|
";
|
||||||
}
|
}
|
||||||
|
$sql .= ")";
|
||||||
$query = new Querylet($sql);
|
$query = new Querylet($sql);
|
||||||
|
|
||||||
if(strlen($img_search->sql) > 0) {
|
if(strlen($img_search->sql) > 0) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user