|
|
|
@ -24,22 +24,33 @@ export const MatchTypeEnum = { |
|
|
|
|
MATCH_LIKE: 2, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
export const ImageFilterTypeEnum = { |
|
|
|
|
MATCH_IMAGE_NAME: 1, |
|
|
|
|
export const ResultFilterTypeEnum = { |
|
|
|
|
MATCH_NAME: 1, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export const ResultTypeEnum = { |
|
|
|
|
IMAGE: 1, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export class ImageFilter { |
|
|
|
|
type = ImageFilterTypeEnum.MATCH_IMAGE_NAME; |
|
|
|
|
export class ResultFilter { |
|
|
|
|
// What kind of filtering to apply
|
|
|
|
|
type = ResultFilterTypeEnum.MATCH_NAME; |
|
|
|
|
|
|
|
|
|
// optional string used in the filtering
|
|
|
|
|
match_against = ""; |
|
|
|
|
|
|
|
|
|
// How to use the matching string
|
|
|
|
|
match_type = MatchTypeEnum.MATCH_EQUALS; |
|
|
|
|
|
|
|
|
|
// On which types of results to apply the filter
|
|
|
|
|
result_types = []; |
|
|
|
|
|
|
|
|
|
// If true, negates the filter
|
|
|
|
|
negate = false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export class UserQuery { |
|
|
|
|
image_filters = []; |
|
|
|
|
result_filters = []; |
|
|
|
|
include_result_types = [ ResultTypeEnum.IMAGE ]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -48,7 +59,7 @@ export function image_filter_to_where(image_filter) { |
|
|
|
|
var match_to = image_filter.match_against; |
|
|
|
|
var match_operator = false; |
|
|
|
|
|
|
|
|
|
if(image_filter.type == ImageFilterTypeEnum.MATCH_IMAGE_NAME) { |
|
|
|
|
if(image_filter.type == ResultFilterTypeEnum.MATCH_NAME) { |
|
|
|
|
match_from = "Image.name"; |
|
|
|
|
} else { |
|
|
|
|
throw new Error("Unsupported image filter type: " + image_filter.type); |
|
|
|
@ -86,4 +97,30 @@ export function maybe_image_query(user_query) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return image_query_with_where(where); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function filter_from_text_segment(segment) { |
|
|
|
|
var r = new ResultFilter(); |
|
|
|
|
r.match_against = segment['text']; |
|
|
|
|
r.negate = segment['negated']; |
|
|
|
|
r.match_type = MatchTypeEnum.MATCH_EQUALS; |
|
|
|
|
r.type = ResultFilterTypeEnum.MATCH_NAME; |
|
|
|
|
return r; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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 texts = parsed.getTextSegments(); |
|
|
|
|
|
|
|
|
|
var r = new UserQuery(); |
|
|
|
|
|
|
|
|
|
texts.forEach(text => { |
|
|
|
|
r.result_filters.push(filter_from_text_segment(text)); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
console.log(search_string); |
|
|
|
|
console.log(r); |
|
|
|
|
} |