Merge branch 'master' of github.com:shish/shimmie2
This commit is contained in:
commit
61f3a9d372
@ -609,6 +609,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
|
||||
*
|
||||
* SELECT * FROM images WHERE
|
||||
@ -742,32 +745,29 @@ class Image {
|
||||
$have_pos = count($positive_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) {
|
||||
$positive_tag_id_list = join(', ', $positive_tag_id_array);
|
||||
$sql .= "
|
||||
images.id IN (
|
||||
SELECT image_id
|
||||
FROM image_tags
|
||||
WHERE tag_id IN ($positive_tag_id_list)
|
||||
GROUP BY image_id
|
||||
HAVING COUNT(image_id)>=$positive_tag_count
|
||||
)
|
||||
SELECT image_id
|
||||
FROM image_tags
|
||||
WHERE tag_id IN ($positive_tag_id_list)
|
||||
GROUP BY image_id
|
||||
HAVING COUNT(image_id)>=$positive_tag_count
|
||||
";
|
||||
}
|
||||
if($have_pos && $have_neg) {
|
||||
$sql .= " AND ";
|
||||
$sql .= " EXCEPT ";
|
||||
}
|
||||
if($have_neg) {
|
||||
$negative_tag_id_list = join(', ', $negative_tag_id_array);
|
||||
$sql .= "
|
||||
images.id NOT IN (
|
||||
SELECT image_id
|
||||
FROM image_tags
|
||||
WHERE tag_id IN ($negative_tag_id_list)
|
||||
)
|
||||
SELECT image_id
|
||||
FROM image_tags
|
||||
WHERE tag_id IN ($negative_tag_id_list)
|
||||
";
|
||||
}
|
||||
$sql .= ")";
|
||||
$query = new Querylet($sql);
|
||||
|
||||
if(strlen($img_search->sql) > 0) {
|
||||
|
@ -224,7 +224,11 @@ class Index extends Extension {
|
||||
}
|
||||
else if(preg_match("/^(filename|name)=([a-zA-Z0-9]*)$/i", $event->term, $matches)) {
|
||||
$filename = strtolower($matches[2]);
|
||||
$event->add_querylet(new Querylet('images.filename LIKE "%'.$filename.'%"'));
|
||||
$event->add_querylet(new Querylet('images.filename LIKE :fn', array("fn"=>"%$filename%")));
|
||||
}
|
||||
else if(preg_match("/^(source)=([a-zA-Z0-9]*)$/i", $event->term, $matches)) {
|
||||
$filename = strtolower($matches[2]);
|
||||
$event->add_querylet(new Querylet('images.source LIKE :src', array("src"=>"%$filename%")));
|
||||
}
|
||||
else if(preg_match("/^posted(<|>|<=|>=|=)([0-9-]*)$/", $event->term, $matches)) {
|
||||
$cmp = $matches[1];
|
||||
|
@ -394,46 +394,52 @@ class TagList extends Extension {
|
||||
global $database;
|
||||
global $config;
|
||||
|
||||
$wild_tags = Tag::explode($search);
|
||||
// $search_tags = array();
|
||||
$related_tags = $database->cache->get("related_tags:$search");
|
||||
|
||||
$tag_id_array = array();
|
||||
$tags_ok = true;
|
||||
foreach($wild_tags as $tag) {
|
||||
$tag = str_replace("*", "%", $tag);
|
||||
$tag = str_replace("?", "_", $tag);
|
||||
$tag_ids = $database->get_col("SELECT id FROM tags WHERE tag LIKE :tag", array("tag"=>$tag));
|
||||
// $search_tags = array_merge($search_tags,
|
||||
// $database->get_col("SELECT tag FROM tags WHERE tag LIKE :tag", array("tag"=>$tag)));
|
||||
$tag_id_array = array_merge($tag_id_array, $tag_ids);
|
||||
$tags_ok = count($tag_ids) > 0;
|
||||
if(!$tags_ok) break;
|
||||
}
|
||||
$tag_id_list = join(', ', $tag_id_array);
|
||||
if(empty($related_tags)) {
|
||||
$wild_tags = Tag::explode($search);
|
||||
// $search_tags = array();
|
||||
|
||||
if($tags_ok) {
|
||||
$query = "
|
||||
SELECT t2.tag AS tag, COUNT(it2.image_id) AS calc_count
|
||||
FROM
|
||||
image_tags AS it1,
|
||||
image_tags AS it2,
|
||||
tags AS t1,
|
||||
tags AS t2
|
||||
WHERE
|
||||
t1.id IN($tag_id_list)
|
||||
AND it1.image_id=it2.image_id
|
||||
AND it1.tag_id = t1.id
|
||||
AND it2.tag_id = t2.id
|
||||
GROUP BY t2.tag
|
||||
ORDER BY calc_count
|
||||
DESC LIMIT :limit
|
||||
";
|
||||
$args = array("limit"=>$config->get_int('tag_list_length'));
|
||||
|
||||
$related_tags = $database->get_all($query, $args);
|
||||
if(count($related_tags) > 0) {
|
||||
$this->theme->display_refine_block($page, $related_tags, $wild_tags);
|
||||
$tag_id_array = array();
|
||||
$tags_ok = true;
|
||||
foreach($wild_tags as $tag) {
|
||||
$tag = str_replace("*", "%", $tag);
|
||||
$tag = str_replace("?", "_", $tag);
|
||||
$tag_ids = $database->get_col("SELECT id FROM tags WHERE tag LIKE :tag", array("tag"=>$tag));
|
||||
// $search_tags = array_merge($search_tags,
|
||||
// $database->get_col("SELECT tag FROM tags WHERE tag LIKE :tag", array("tag"=>$tag)));
|
||||
$tag_id_array = array_merge($tag_id_array, $tag_ids);
|
||||
$tags_ok = count($tag_ids) > 0;
|
||||
if(!$tags_ok) break;
|
||||
}
|
||||
$tag_id_list = join(', ', $tag_id_array);
|
||||
|
||||
if($tags_ok) {
|
||||
$query = "
|
||||
SELECT t2.tag AS tag, COUNT(it2.image_id) AS calc_count
|
||||
FROM
|
||||
image_tags AS it1,
|
||||
image_tags AS it2,
|
||||
tags AS t1,
|
||||
tags AS t2
|
||||
WHERE
|
||||
t1.id IN($tag_id_list)
|
||||
AND it1.image_id=it2.image_id
|
||||
AND it1.tag_id = t1.id
|
||||
AND it2.tag_id = t2.id
|
||||
GROUP BY t2.tag
|
||||
ORDER BY calc_count
|
||||
DESC LIMIT :limit
|
||||
";
|
||||
$args = array("limit"=>$config->get_int('tag_list_length'));
|
||||
|
||||
$related_tags = $database->get_all($query, $args);
|
||||
$database->cache->set("related_tags:$search", $related_tags, 60*60);
|
||||
}
|
||||
}
|
||||
|
||||
if(count($related_tags) > 0) {
|
||||
$this->theme->display_refine_block($page, $related_tags, $wild_tags);
|
||||
}
|
||||
}
|
||||
// }}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user