|
|
|
@ -11,6 +11,7 @@ export function do_image_query(query, database, collection_path, collection_thum |
|
|
|
|
var queries = []; |
|
|
|
|
queries.push(query); |
|
|
|
|
sqljs_async_queries(database, queries).then(res => { |
|
|
|
|
console.log("response: ", res); |
|
|
|
|
var photos = []; |
|
|
|
|
if (res && Array.isArray(res) && res.length > 0) { |
|
|
|
|
var cols = res[0].columns; |
|
|
|
@ -30,7 +31,8 @@ export function do_image_query(query, database, collection_path, collection_thum |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
resolve(photos); |
|
|
|
|
}); |
|
|
|
|
}) |
|
|
|
|
.catch(err => { throw err; }); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -58,13 +60,14 @@ export function do_tag_query(query, database) { |
|
|
|
|
return new Promise(function (resolve, reject) { |
|
|
|
|
var queries = []; |
|
|
|
|
queries.push(query); |
|
|
|
|
console.log("Provided DB tags schema before query:", database.exec("PRAGMA table_info([Tags]);")); |
|
|
|
|
sqljs_async_queries(database, queries).then(res => { |
|
|
|
|
var tags = []; |
|
|
|
|
if (res && Array.isArray(res) && res.length > 0) { |
|
|
|
|
var cols = res[0].columns; |
|
|
|
|
var data = res[0].values; |
|
|
|
|
data.forEach(row => { |
|
|
|
|
tags.push(create_tag(row[cols.indexOf("id")], row[cols.indexOf("fullname")])); |
|
|
|
|
tags.push(create_tag(row[cols.indexOf("id")], row[cols.indexOf("name")], row[cols.indexOf("fullname")])); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
resolve(tags); |
|
|
|
@ -79,7 +82,10 @@ export const MatchTypeEnum = { |
|
|
|
|
MATCH_ALBUM_EQUALS_OR_CHILD: 4, // Match on the full name (relative path) of the relevant album, if any, or any of its children
|
|
|
|
|
MATCH_ALBUM_NATURAL: 5, |
|
|
|
|
MATCH_ALBUM_NAME_EQUALS: 6, // Match on the local album name (excluding parents)
|
|
|
|
|
MATCH_TAG_EQUALS: 7, // Match on the name of the relevant tag(s), if any
|
|
|
|
|
MATCH_TAG_EQUALS: 7, // Match on the full name (relative path) of the relevant tag, if any
|
|
|
|
|
MATCH_TAG_EQUALS_OR_CHILD: 8, // Match on the full name (path) of the relevant tag, if any, or any of its children
|
|
|
|
|
MATCH_TAG_NATURAL: 9, |
|
|
|
|
MATCH_TAG_NAME_EQUALS: 10, // Match on the local tag name (excluding parents)
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export const ResultTypeEnum = { |
|
|
|
@ -164,7 +170,7 @@ export class MatchingFilter extends ResultFilter { |
|
|
|
|
+ escape_regex(this.match_from) |
|
|
|
|
+ '.*"))'; |
|
|
|
|
} else if (this.match_type == MatchTypeEnum.MATCH_ALBUM_EQUALS) { |
|
|
|
|
return '(Albums.relativePath = "' + this.match_from + '")'; |
|
|
|
|
return '(Albums.relativePath="' + this.match_from + '")'; |
|
|
|
|
} else if (this.match_type == MatchTypeEnum.MATCH_ALBUM_EQUALS_OR_CHILD) { |
|
|
|
|
return 'REGEXP(Albums.relativePath, "' |
|
|
|
|
+ escape_regex(this.match_from) |
|
|
|
@ -176,7 +182,17 @@ export class MatchingFilter extends ResultFilter { |
|
|
|
|
+ escape_regex(this.match_from) |
|
|
|
|
+ '(\/[^\/]+)*")'; |
|
|
|
|
} else if (this.match_type == MatchTypeEnum.MATCH_TAG_EQUALS) { |
|
|
|
|
return '(Tags.name="' + this.match_from + '")'; |
|
|
|
|
return '(Tags.fullname="' + this.match_from + '")'; |
|
|
|
|
} else if (this.match_type == MatchTypeEnum.MATCH_TAG_EQUALS_OR_CHILD) { |
|
|
|
|
return '(Tags.fullname NOT NULL AND REGEXP(Tags.fullname, "' |
|
|
|
|
+ escape_regex(this.match_from) |
|
|
|
|
+ '(\/[^\/]+)*"))'; |
|
|
|
|
} else if (this.match_type == MatchTypeEnum.MATCH_TAG_NATURAL) { |
|
|
|
|
throw new Error("Natural matching on tag names is not yet supported."); |
|
|
|
|
} else if (this.match_type == MatchTypeEnum.MATCH_TAG_NAME_EQUALS) { |
|
|
|
|
return 'REGEXP(Tags.fullname, "\/(.*\/)*' |
|
|
|
|
+ escape_regex(this.match_from) |
|
|
|
|
+ '(\/[^\/]+)*")'; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
console.log(this); |
|
|
|
@ -314,7 +330,7 @@ function filter_from_text_segment(result_type, segment) { |
|
|
|
|
var album_filter = new MatchingFilter( |
|
|
|
|
result_type, |
|
|
|
|
segment['text'], |
|
|
|
|
MatchTypeEnum.MATCH_ALBUM_NAME_EQUALS |
|
|
|
|
MatchTypeEnum.MATCH_ALBUM_NAME_EQUALS_OR_CHILD |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
filter = new LogicalOperatorFilter(result_type, name_filter, album_filter, LogicalOperatorEnum.OR); |
|
|
|
@ -326,18 +342,18 @@ function filter_from_text_segment(result_type, segment) { |
|
|
|
|
name_filter = new MatchingFilter( |
|
|
|
|
result_type, |
|
|
|
|
segment['text'], |
|
|
|
|
MatchTypeEnum.MATCH_ALBUM_NAME_EQUALS |
|
|
|
|
MatchTypeEnum.MATCH_ALBUM_NAME_EQUALS_OR_CHILD |
|
|
|
|
); |
|
|
|
|
filter = name_filter; |
|
|
|
|
if (segment['negated']) { |
|
|
|
|
filter = new NegationFilter(result_type, filter); |
|
|
|
|
} |
|
|
|
|
} else if (result_type === ResultTypeEnum.TAG) { |
|
|
|
|
// Match against the tag name.
|
|
|
|
|
// TODO: We need a natural matcher for tag names
|
|
|
|
|
name_filter = new MatchingFilter( |
|
|
|
|
result_type, |
|
|
|
|
segment['text'], |
|
|
|
|
MatchTypeEnum.MATCH_TAG_EQUALS |
|
|
|
|
MatchTypeEnum.MATCH_TAG_NAME_EQUALS_OR_CHILD |
|
|
|
|
); |
|
|
|
|
filter = name_filter; |
|
|
|
|
if (segment['negated']) { |
|
|
|
@ -371,26 +387,51 @@ export function user_query_from_search_string(search_string) { |
|
|
|
|
|
|
|
|
|
export function user_query_from_browsed_album(album_path) { |
|
|
|
|
var r = new UserQuery(); |
|
|
|
|
r.image_filter = new MatchingFilter( |
|
|
|
|
ResultTypeEnum.IMAGE, |
|
|
|
|
album_path, |
|
|
|
|
MatchTypeEnum.MATCH_ALBUM_EQUALS_OR_CHILD, |
|
|
|
|
false).simplify(); |
|
|
|
|
r.album_filter = new ConstFilter(ResultTypeEnum.ALBUM, false).simplify(); |
|
|
|
|
r.tag_filter = new ConstFilter(ResultTypeEnum.TAG, false).simplify(); |
|
|
|
|
|
|
|
|
|
r.image_filter = |
|
|
|
|
new MatchingFilter( |
|
|
|
|
ResultTypeEnum.IMAGE, |
|
|
|
|
album_path, |
|
|
|
|
MatchTypeEnum.MATCH_ALBUM_EQUALS_OR_CHILD, |
|
|
|
|
false).simplify(); |
|
|
|
|
/* |
|
|
|
|
r.album_filter = |
|
|
|
|
new MatchingFilter( |
|
|
|
|
ResultTypeEnum.ALBUM, |
|
|
|
|
album_path, |
|
|
|
|
MatchTypeEnum.MATCH_ALBUM_EQUALS_OR_CHILD, |
|
|
|
|
false).simplify(); |
|
|
|
|
r.tag_filter = |
|
|
|
|
new MatchingFilter( |
|
|
|
|
ResultTypeEnum.TAG, |
|
|
|
|
album_path, |
|
|
|
|
MatchTypeEnum.MATCH_ALBUM_EQUALS_OR_CHILD, |
|
|
|
|
false).simplify(); |
|
|
|
|
*/ |
|
|
|
|
return r; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function user_query_from_browsed_tag(name) { |
|
|
|
|
export function user_query_from_browsed_tag(tag_path) { |
|
|
|
|
var r = new UserQuery(); |
|
|
|
|
r.image_filter = new MatchingFilter( |
|
|
|
|
ResultTypeEnum.IMAGE, |
|
|
|
|
name, |
|
|
|
|
MatchTypeEnum.MATCH_TAG_EQUALS, |
|
|
|
|
false).simplify(); |
|
|
|
|
r.album_filter = new ConstFilter(ResultTypeEnum.ALBUM, false).simplify(); |
|
|
|
|
r.tag_filter = new ConstFilter(ResultTypeEnum.TAG, false).simplify(); |
|
|
|
|
r.image_filter = |
|
|
|
|
new MatchingFilter( |
|
|
|
|
ResultTypeEnum.IMAGE, |
|
|
|
|
tag_path, |
|
|
|
|
MatchTypeEnum.MATCH_TAG_EQUALS_OR_CHILD, |
|
|
|
|
false).simplify(); |
|
|
|
|
/* |
|
|
|
|
r.album_filter = |
|
|
|
|
new MatchingFilter( |
|
|
|
|
ResultTypeEnum.ALBUM, |
|
|
|
|
tag_path, |
|
|
|
|
MatchTypeEnum.MATCH_TAG_EQUALS_OR_CHILD, |
|
|
|
|
false).simplify(); |
|
|
|
|
r.tag_filter = |
|
|
|
|
new MatchingFilter( |
|
|
|
|
ResultTypeEnum.TAG, |
|
|
|
|
tag_path, |
|
|
|
|
MatchTypeEnum.MATCH_TAG_EQUALS_OR_CHILD, |
|
|
|
|
false).simplify(); |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
return r; |
|
|
|
|
} |