dedupe searching a bit
This commit is contained in:
parent
525fd20540
commit
7f2609f727
@ -796,21 +796,6 @@ class Image {
|
||||
return new Querylet($sql, $terms);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Querylet $img_search
|
||||
* @return Querylet
|
||||
*/
|
||||
private static function build_simple_query($img_search) {
|
||||
$query = new Querylet("SELECT images.* FROM images ");
|
||||
|
||||
if (!empty($img_search->sql)) {
|
||||
$query->append_sql(" WHERE ");
|
||||
$query->append($img_search);
|
||||
return $query;
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* WARNING: this description is no longer accurate, though it does get across
|
||||
* the general idea - the actual method has a few extra optimisations
|
||||
@ -877,7 +862,11 @@ class Image {
|
||||
|
||||
// no tags, do a simple search (+image metadata if we have any)
|
||||
if($count_tag_querylets === 0) {
|
||||
$query = self::build_simple_query($img_search);
|
||||
$query = new Querylet("
|
||||
SELECT images.*
|
||||
FROM images
|
||||
WHERE 1=1
|
||||
");
|
||||
}
|
||||
|
||||
// one positive tag (a common case), do an optimised search
|
||||
@ -889,11 +878,6 @@ class Image {
|
||||
JOIN tags ON image_tags.tag_id=tags.id
|
||||
WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(:tag)
|
||||
"), array("tag"=>$tag_querylets[0]->tag));
|
||||
|
||||
if(!empty($img_search->sql)) {
|
||||
$query->append_sql(" AND ");
|
||||
$query->append($img_search);
|
||||
}
|
||||
}
|
||||
|
||||
// more than one positive tag, or more than zero negative tags
|
||||
@ -914,8 +898,7 @@ class Image {
|
||||
$positive_tag_id_array = array_merge($positive_tag_id_array, $tag_ids);
|
||||
$tags_ok = count($tag_ids) > 0;
|
||||
if (!$tags_ok) break;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$negative_tag_id_array = array_merge($negative_tag_id_array, $tag_ids);
|
||||
}
|
||||
}
|
||||
@ -951,13 +934,7 @@ class Image {
|
||||
FROM images
|
||||
WHERE images.id IN ($sql)
|
||||
");
|
||||
|
||||
if(strlen($img_search->sql) > 0) {
|
||||
$query->append_sql(" AND ");
|
||||
$query->append($img_search);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
# one of the positive tags had zero results, therefor there
|
||||
# can be no results; "where 1=0" should shortcut things
|
||||
$query = new Querylet("
|
||||
@ -968,6 +945,12 @@ class Image {
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($img_search->sql)) {
|
||||
$query->append_sql(" AND ");
|
||||
$query->append($img_search);
|
||||
return $query;
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
@ -1040,7 +1023,11 @@ class Image {
|
||||
|
||||
// no tags, do a simple search (+image metadata if we have any)
|
||||
if($positive_tag_count + $negative_tag_count == 0) {
|
||||
$query = self::build_simple_query($img_search);
|
||||
$query = new Querylet("
|
||||
SELECT images.*
|
||||
FROM images
|
||||
WHERE 1=1
|
||||
");
|
||||
}
|
||||
|
||||
// one positive tag (a common case), do an optimised search
|
||||
@ -1056,11 +1043,6 @@ class Image {
|
||||
WHERE tag LIKE :tag0
|
||||
{$group_by}
|
||||
", $tag_search->variables);
|
||||
|
||||
if(!empty($img_search->sql)) {
|
||||
$query->append_sql(" AND ");
|
||||
$query->append($img_search);
|
||||
}
|
||||
}
|
||||
|
||||
// more than one positive tag, and zero or more negative tags
|
||||
@ -1101,12 +1083,9 @@ class Image {
|
||||
);
|
||||
$query = new Querylet('
|
||||
SELECT *
|
||||
FROM ('.$subquery->sql.') AS images ', $subquery->variables);
|
||||
|
||||
if(!empty($img_search->sql)) {
|
||||
$query->append_sql(" WHERE ");
|
||||
$query->append($img_search);
|
||||
}
|
||||
FROM ('.$subquery->sql.') AS images
|
||||
WHERE 1=1
|
||||
', $subquery->variables);
|
||||
}
|
||||
else {
|
||||
# there are no results, "where 1=0" should shortcut things
|
||||
@ -1127,6 +1106,13 @@ class Image {
|
||||
WHERE 1=0
|
||||
");
|
||||
}
|
||||
|
||||
if (!empty($img_search->sql)) {
|
||||
$query->append_sql(" AND ");
|
||||
$query->append($img_search);
|
||||
return $query;
|
||||
}
|
||||
|
||||
Image::$tag_n = 0;
|
||||
return $query;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user