|
|
|
@ -35,7 +35,7 @@ export function do_album_query(query, database) { |
|
|
|
|
var albums = []; |
|
|
|
|
if (res && Array.isArray(res)) { |
|
|
|
|
res.forEach(row => { |
|
|
|
|
var album_name = new String(row["relativePath"]).substring(row["relativePath"].lastIndexOf('/') + 1); |
|
|
|
|
var album_name = row["relativePath"].substring(row["relativePath"].lastIndexOf('/') + 1); |
|
|
|
|
albums.push(create_album(row["id"], album_name, row["relativePath"])); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
@ -144,32 +144,33 @@ export class MatchingFilter extends ResultFilter { |
|
|
|
|
match_type = MatchTypeEnum.MATCH_EQUALS; |
|
|
|
|
|
|
|
|
|
to_sql_where() { |
|
|
|
|
if(this.match_against == MatchAgainstEnum.MATCH_IMAGE_NAME) { |
|
|
|
|
if(this.match_type == MatchTypeEnum.MATCH_EQUALS) { |
|
|
|
|
var expr; |
|
|
|
|
if(this.match_against === MatchAgainstEnum.MATCH_IMAGE_NAME) { |
|
|
|
|
if(this.match_type === MatchTypeEnum.MATCH_EQUALS) { |
|
|
|
|
return '(Images.name="' + this.match_from + '")'; |
|
|
|
|
} else if(this.match_type == MatchTypeEnum.MATCH_NATURAL) { |
|
|
|
|
var expr = '"' + '.*' + escape_regex(this.match_from) + '.*' + '"'; |
|
|
|
|
} else if(this.match_type === MatchTypeEnum.MATCH_NATURAL) { |
|
|
|
|
expr = '".*' + escape_regex(this.match_from) + '.*"'; |
|
|
|
|
return "(LOWER(Images.name) REGEXP LOWER(" + expr +"))"; |
|
|
|
|
} |
|
|
|
|
} else if(this.match_against == MatchAgainstEnum.MATCH_TAG_NAME) { |
|
|
|
|
if(this.match_type == MatchTypeEnum.MATCH_EQUALS) { |
|
|
|
|
} else if(this.match_against === MatchAgainstEnum.MATCH_TAG_NAME) { |
|
|
|
|
if(this.match_type === MatchTypeEnum.MATCH_EQUALS) { |
|
|
|
|
return '(Tags.name="' + this.match_from + '")'; |
|
|
|
|
} else if(this.match_type == MatchTypeEnum.MATCH_NATURAL) { |
|
|
|
|
var expr = '"' + '.*' + escape_regex(this.match_from) + '.*' + '"'; |
|
|
|
|
} else if(this.match_type === MatchTypeEnum.MATCH_NATURAL) { |
|
|
|
|
expr = '".*' + escape_regex(this.match_from) + '.*"'; |
|
|
|
|
return '(LOWER(Tags.name) REGEXP LOWER("' + expr + '"))'; |
|
|
|
|
} |
|
|
|
|
} else if(this.match_against == MatchAgainstEnum.MATCH_ALBUM_NAME) { |
|
|
|
|
if(this.match_type == MatchTypeEnum.MATCH_EQUALS) { |
|
|
|
|
var expr = '\/(.*\/)*' + escape_regex(this.match_from); |
|
|
|
|
} else if(this.match_against === MatchAgainstEnum.MATCH_ALBUM_NAME) { |
|
|
|
|
if(this.match_type === MatchTypeEnum.MATCH_EQUALS) { |
|
|
|
|
expr = '\/(.*\/)*' + escape_regex(this.match_from); |
|
|
|
|
return '(Albums.relativePath REGEXP "' + expr + '")'; |
|
|
|
|
} else if(this.match_type == MatchTypeEnum.MATCH_NATURAL) { |
|
|
|
|
} else if(this.match_type === MatchTypeEnum.MATCH_NATURAL) { |
|
|
|
|
throw new Error("Natural matching on album names is not yet supported."); |
|
|
|
|
} |
|
|
|
|
} else if(this.match_against == MatchAgainstEnum.MATCH_ALBUM_NAME_IN_TREE) { |
|
|
|
|
if(this.match_type == MatchTypeEnum.MATCH_EQUALS) { |
|
|
|
|
var expr = escape_regex(this.match_from) + '(\/[^\/]+)*'; |
|
|
|
|
} else if(this.match_against === MatchAgainstEnum.MATCH_ALBUM_NAME_IN_TREE) { |
|
|
|
|
if(this.match_type === MatchTypeEnum.MATCH_EQUALS) { |
|
|
|
|
expr = escape_regex(this.match_from) + '(\/[^\/]+)*'; |
|
|
|
|
return '(Albums.relativePath REGEXP "' + expr + '")'; |
|
|
|
|
} else if(this.match_type == MatchTypeEnum.MATCH_NATURAL) { |
|
|
|
|
} else if(this.match_type === MatchTypeEnum.MATCH_NATURAL) { |
|
|
|
|
throw new Error("Natural matching on album tree names is not yet supported."); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -195,9 +196,9 @@ export class LogicalOperatorFilter extends ResultFilter { |
|
|
|
|
var where1 = this.sub_filter_a.to_sql_where(); |
|
|
|
|
var where2 = this.sub_filter_b.to_sql_where(); |
|
|
|
|
var operator_str = ""; |
|
|
|
|
if (this.operator == LogicalOperatorEnum.AND) { |
|
|
|
|
if (this.operator === LogicalOperatorEnum.AND) { |
|
|
|
|
operator_str = " AND "; |
|
|
|
|
} else if (this.operator == LogicalOperatorEnum.OR) { |
|
|
|
|
} else if (this.operator === LogicalOperatorEnum.OR) { |
|
|
|
|
operator_str = " OR "; |
|
|
|
|
} else { |
|
|
|
|
throw new Error('Unsupported logical operator: ' + this.operator); |
|
|
|
@ -209,7 +210,7 @@ export class LogicalOperatorFilter extends ResultFilter { |
|
|
|
|
var a = this.sub_filter_a.simplify(); |
|
|
|
|
var b = this.sub_filter_b.simplify(); |
|
|
|
|
|
|
|
|
|
if(this.operator == LogicalOperatorEnum.OR) { |
|
|
|
|
if(this.operator === LogicalOperatorEnum.OR) { |
|
|
|
|
if(a.is_true() || b.is_true()) { |
|
|
|
|
return new ConstFilter(this.return_type, true); |
|
|
|
|
} |
|
|
|
@ -217,7 +218,7 @@ export class LogicalOperatorFilter extends ResultFilter { |
|
|
|
|
if(b.is_false()) { return a; } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(this.operator == LogicalOperatorEnum.AND) { |
|
|
|
|
if(this.operator === LogicalOperatorEnum.AND) { |
|
|
|
|
if(a.is_false() || b.is_false()) { |
|
|
|
|
return new ConstFilter(this.return_type, false); |
|
|
|
|
} |
|
|
|
@ -277,7 +278,7 @@ export function maybe_tag_query(user_query) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function filter_is_const_false(filter) { |
|
|
|
|
if(filter instanceof ConstFilter && filter.constval == false) { |
|
|
|
|
if(filter instanceof ConstFilter && filter.constval === false) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
// TODO resolve recursively
|
|
|
|
@ -286,10 +287,11 @@ export function filter_is_const_false(filter) { |
|
|
|
|
|
|
|
|
|
function filter_from_text_segment(result_type, segment) { |
|
|
|
|
var filter = false; |
|
|
|
|
var name_filter; |
|
|
|
|
|
|
|
|
|
if (result_type == ResultTypeEnum.IMAGE) { |
|
|
|
|
if (result_type === ResultTypeEnum.IMAGE) { |
|
|
|
|
// Option 1: match on image name
|
|
|
|
|
var name_filter = new MatchingFilter( |
|
|
|
|
name_filter = new MatchingFilter( |
|
|
|
|
result_type, |
|
|
|
|
MatchAgainstEnum.MATCH_IMAGE_NAME, |
|
|
|
|
segment['text'], |
|
|
|
@ -308,9 +310,9 @@ function filter_from_text_segment(result_type, segment) { |
|
|
|
|
if(segment['negated']) { |
|
|
|
|
filter = new NegationFilter(result_type, filter); |
|
|
|
|
} |
|
|
|
|
} else if (result_type == ResultTypeEnum.ALBUM) { |
|
|
|
|
} else if (result_type === ResultTypeEnum.ALBUM) { |
|
|
|
|
// TODO: We need a natural matcher for album names
|
|
|
|
|
var name_filter = new MatchingFilter( |
|
|
|
|
name_filter = new MatchingFilter( |
|
|
|
|
result_type, |
|
|
|
|
MatchAgainstEnum.MATCH_ALBUM_NAME, |
|
|
|
|
segment['text'], |
|
|
|
@ -320,9 +322,9 @@ function filter_from_text_segment(result_type, segment) { |
|
|
|
|
if(segment['negated']) { |
|
|
|
|
filter = new NegationFilter(result_type, filter); |
|
|
|
|
} |
|
|
|
|
} else if (result_type == ResultTypeEnum.TAG) { |
|
|
|
|
} else if (result_type === ResultTypeEnum.TAG) { |
|
|
|
|
// Match against the tag name.
|
|
|
|
|
var name_filter = new MatchingFilter( |
|
|
|
|
name_filter = new MatchingFilter( |
|
|
|
|
result_type, |
|
|
|
|
MatchAgainstEnum.MATCH_TAG_NAME, |
|
|
|
|
segment['text'], |
|
|
|
@ -341,7 +343,7 @@ export function user_query_from_search_string(search_string) { |
|
|
|
|
const parser = require('search-string'); |
|
|
|
|
|
|
|
|
|
var parsed = parser.parse(search_string); |
|
|
|
|
var conditions = parsed.getParsedQuery(); |
|
|
|
|
//var conditions = parsed.getParsedQuery();
|
|
|
|
|
var texts = parsed.getTextSegments(); |
|
|
|
|
|
|
|
|
|
var r = new UserQuery(); |
|
|
|
|