saner wildcard handling, and only handle '*'

This commit is contained in:
Shish 2013-03-03 18:26:47 +00:00
parent 9fbc31dbf2
commit 72a82c7487

View File

@ -665,17 +665,13 @@ class Image {
} }
} }
else { else {
$term = str_replace("*", "%", $term);
$term = str_replace("?", "_", $term);
if(!preg_match("/^[%_]+$/", $term)) {
$expansions = Tag::resolve_wildcard($term); $expansions = Tag::resolve_wildcard($term);
if($positive) $positive_tag_count++; if($expansions && $positive) $positive_tag_count++;
foreach($expansions as $term) { foreach($expansions as $term) {
$tag_querylets[] = new TagQuerylet($term, $positive); $tag_querylets[] = new TagQuerylet($term, $positive);
} }
} }
} }
}
// merge all the image metadata searches into one generic querylet // merge all the image metadata searches into one generic querylet
@ -1024,12 +1020,22 @@ class Tag {
} }
public static function resolve_wildcard($tag) { public static function resolve_wildcard($tag) {
if(strpos($tag, "%") === false && strpos($tag, "_") === false) { // if there is no wildcard, return the tag
if(strpos($tag, "*") === false) {
return array($tag); return array($tag);
} }
// if the whole match is wild, return null to save the database
else if(str_replace("*", "", $tag) == "")) {
return array();
}
// else find some matches
else { else {
global $database; global $database;
$newtags = $database->get_col("SELECT tag FROM tags WHERE tag LIKE ?", array($tag)); $db_wild_tag = str_replace("%", "\%", $tag);
$db_wild_tag = str_replace("*", "%", $tag);
$newtags = $database->get_col($database->scoreql_to_sql("SELECT tag FROM tags WHERE SCORE_STRNORM(tag) LIKE SCORE_STRNORM(?)"), array($db_wild_tag));
if(count($newtags) > 0) { if(count($newtags) > 0) {
$resolved = $newtags; $resolved = $newtags;
} else { } else {