|
|
|
@ -6,6 +6,7 @@ export function escape_regex(s) { |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
export function do_image_query(query, database, collection_path, collection_thumbs_path) { |
|
|
|
|
console.log("Doing image query:", query); |
|
|
|
|
return new Promise(function (resolve, reject) { |
|
|
|
|
var queries = []; |
|
|
|
|
queries.push(query); |
|
|
|
@ -42,7 +43,7 @@ export function do_album_query(query, database) { |
|
|
|
|
|
|
|
|
|
export const MatchTypeEnum = { |
|
|
|
|
MATCH_EQUALS: 1, |
|
|
|
|
MATCH_REGEXP: 2, |
|
|
|
|
MATCH_REGEXP_CASEINSENSITIVE: 2, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
export const MatchAgainstEnum = { |
|
|
|
@ -96,16 +97,20 @@ export class MatchingFilter extends ResultFilter { |
|
|
|
|
|
|
|
|
|
to_sql_where() { |
|
|
|
|
var match_type_str = false; |
|
|
|
|
var match_against = this.match_against; |
|
|
|
|
var match_from = this.match_from; |
|
|
|
|
|
|
|
|
|
if (this.match_type == MatchTypeEnum.MATCH_EQUALS) { |
|
|
|
|
match_type_str = "="; |
|
|
|
|
} else if (this.match_type == MatchTypeEnum.MATCH_REGEXP) { |
|
|
|
|
} else if (this.match_type == MatchTypeEnum.MATCH_REGEXP_CASEINSENSITIVE) { |
|
|
|
|
match_type_str = " REGEXP "; |
|
|
|
|
match_from = "LOWER(" + match_from + ")"; |
|
|
|
|
match_against = "LOWER(" + match_against + ")"; |
|
|
|
|
} else { |
|
|
|
|
throw new Error('Unsupported match type: ' + this.match_type); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return "(" + (this.negate ? "NOT " : "") + this.match_against + match_type_str + this.match_from + ")"; |
|
|
|
|
return "(" + (this.negate ? "NOT " : "") + match_against + match_type_str + match_from + ")"; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -167,22 +172,42 @@ export function maybe_album_query(user_query) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function filter_from_text_segment(result_type, segment) { |
|
|
|
|
var match_type = false; |
|
|
|
|
var match_text = false; |
|
|
|
|
var match_against = false; |
|
|
|
|
var filter = false; |
|
|
|
|
|
|
|
|
|
if (result_type == ResultTypeEnum.IMAGE) { |
|
|
|
|
match_type = MatchTypeEnum.MATCH_EQUALS; |
|
|
|
|
match_text = '"' + segment['text'] + '"'; |
|
|
|
|
match_against = "Images.name"; |
|
|
|
|
// Option 1: match on image name
|
|
|
|
|
var name_filter = new MatchingFilter( |
|
|
|
|
result_type, |
|
|
|
|
"Images.name", |
|
|
|
|
'"' + '.*' + escape_regex(segment['text']) + '.*' + '"', |
|
|
|
|
MatchTypeEnum.MATCH_REGEXP_CASEINSENSITIVE, |
|
|
|
|
segment['negated'] |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
// Option 2: match on album path
|
|
|
|
|
var album_filter = new MatchingFilter( |
|
|
|
|
result_type, |
|
|
|
|
"Albums.relativePath", |
|
|
|
|
'"' + escape_regex(segment['text']) + '(\/[^\/]+)*' + '"', |
|
|
|
|
MatchTypeEnum.MATCH_REGEXP_CASEINSENSITIVE, |
|
|
|
|
segment['negated'] |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
filter = new LogicalOperatorFilter(result_type, name_filter, album_filter, LogicalOperatorEnum.OR); |
|
|
|
|
} else if (result_type == ResultTypeEnum.ALBUM) { |
|
|
|
|
// Match against the album "name", which is the basename of its relative path.
|
|
|
|
|
match_type = MatchTypeEnum.MATCH_REGEXP; |
|
|
|
|
match_text = '"' + '\/(.*\/)*' + escape_regex(segment['text']) + '"'; |
|
|
|
|
match_against = "Albums.relativePath"; |
|
|
|
|
// TODO is it nicer to match on relative path?
|
|
|
|
|
var name_filter = new MatchingFilter( |
|
|
|
|
result_type, |
|
|
|
|
"Albums.relativePath", |
|
|
|
|
'"' + '\/(.*\/)*' + escape_regex(segment['text']) + '"', |
|
|
|
|
MatchTypeEnum.MATCH_REGEXP_CASEINSENSITIVE, |
|
|
|
|
segment['negated'] |
|
|
|
|
); |
|
|
|
|
filter = name_filter; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return new MatchingFilter(result_type, match_against, match_text, match_type, segment['negated']); |
|
|
|
|
return filter; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function user_query_from_search_string(search_string) { |
|
|
|
@ -205,9 +230,9 @@ export function user_query_from_search_string(search_string) { |
|
|
|
|
return r; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function user_query_from_album_path(album_path) { |
|
|
|
|
export function user_query_from_browsed_album(album_path) { |
|
|
|
|
var r = new UserQuery(); |
|
|
|
|
var match_type = MatchTypeEnum.MATCH_REGEXP; |
|
|
|
|
var match_type = MatchTypeEnum.MATCH_REGEXP_CASEINSENSITIVE; |
|
|
|
|
var match_text = '"' + escape_regex(album_path) + '(\/[^\/]+)*' + '"'; |
|
|
|
|
var match_against = "Albums.relativePath"; |
|
|
|
|
r.image_filter = new MatchingFilter(ResultTypeEnum.ALBUM, match_against, match_text, match_type, false); |
|
|
|
|