Commit 778b1793 authored by Ujvari Gergely's avatar Ujvari Gergely Committed by gergely-ujvari

Implement 'any' field processing

parent 0b15198a
...@@ -122,10 +122,12 @@ class SearchFilter ...@@ -122,10 +122,12 @@ class SearchFilter
# #
# options: backend specific options # options: backend specific options
# options.es: elasticsearch specific options # options.es: elasticsearch specific options
# options.es.query_type : can be: simple, query_string, match # options.es.query_type : can be: simple, query_string, match, multi_match
# defaults to: simple, determines which es query type to use # defaults to: simple, determines which es query type to use
# options.es.cutoff_frequency: if set, the query will be given a cutoff_frequency for this facet # options.es.cutoff_frequency: if set, the query will be given a cutoff_frequency for this facet
# options.es.and_or: match queries can use this, defaults to and # options.es.and_or: match and multi_match queries can use this, defaults to and
# options.es.match_type: multi_match query type
# options.es.fields: fields to search for in multi-match query
# } # }
# The models is the direct output from visualsearch # The models is the direct output from visualsearch
class QueryParser class QueryParser
...@@ -182,6 +184,18 @@ class QueryParser ...@@ -182,6 +184,18 @@ class QueryParser
case_sensitive: true case_sensitive: true
and_or: 'and' and_or: 'and'
operator: 'ge' operator: 'ge'
any:
exact_match: false
case_sensitive: false
and_or: 'and'
path: ['/quote', '/tags', '/text', '/uri', '/user']
options:
es:
query_type: 'multi_match'
match_type: 'cross_fields'
and_or: 'and'
fields: ['quote', 'tags', 'text', 'uri', 'user']
parseModels: (models) -> parseModels: (models) ->
# Cluster facets together # Cluster facets together
...@@ -197,13 +211,12 @@ class QueryParser ...@@ -197,13 +211,12 @@ class QueryParser
populateFilter: (filter, query) => populateFilter: (filter, query) =>
# Populate a filter with a query object # Populate a filter with a query object
for category, values of query for category, value of query
unless @rules[category]? then continue unless @rules[category]? then continue
unless values.length then continue terms = value.terms
unless terms.length then continue
rule = @rules[category] rule = @rules[category]
unless angular.isArray values
values = [values]
# Now generate the clause with the help of the rule # Now generate the clause with the help of the rule
exact_match = if rule.exact_match? then rule.exact_match else true exact_match = if rule.exact_match? then rule.exact_match else true
...@@ -214,7 +227,7 @@ class QueryParser ...@@ -214,7 +227,7 @@ class QueryParser
if and_or is 'or' if and_or is 'or'
val_list = '' val_list = ''
first = true first = true
for val in values for val in terms
unless first then val_list += ',' else first = false unless first then val_list += ',' else first = false
value_part = if rule.formatter then rule.formatter val else val value_part = if rule.formatter then rule.formatter val else val
val_list += value_part val_list += value_part
...@@ -226,7 +239,7 @@ class QueryParser ...@@ -226,7 +239,7 @@ class QueryParser
oper_part = oper_part =
if rule.operator? then rule.operator if rule.operator? then rule.operator
else if exact_match then 'equals' else 'matches' else if exact_match then 'equals' else 'matches'
for val in values for val in terms
value_part = if rule.formatter then rule.formatter val else val value_part = if rule.formatter then rule.formatter val else val
filter.addClause mapped_field, oper_part, value_part, case_sensitive, rule.options filter.addClause mapped_field, oper_part, value_part, case_sensitive, rule.options
......
...@@ -747,7 +747,7 @@ class ViewFilter ...@@ -747,7 +747,7 @@ class ViewFilter
_anyMatches: (filter, value, match) -> _anyMatches: (filter, value, match) ->
matchresult = [] matchresult = []
for term in filter.terms for term in filter.terms
if value instanceof Array if angular.isArray value
matchresult.push match value, term matchresult.push match value, term
else else
matchresult.push match term, value matchresult.push match term, value
...@@ -758,7 +758,7 @@ class ViewFilter ...@@ -758,7 +758,7 @@ class ViewFilter
return false if autofalsefn? and autofalsefn annotation return false if autofalsefn? and autofalsefn annotation
value = checker.value annotation value = checker.value annotation
if value instanceof Array if angular.isArray value
if filter.lowercase then value = value.map (e) -> e.toLowerCase() if filter.lowercase then value = value.map (e) -> e.toLowerCase()
return @_arrayMatches filter, value, checker.match return @_arrayMatches filter, value, checker.match
else else
...@@ -815,7 +815,6 @@ class ViewFilter ...@@ -815,7 +815,6 @@ class ViewFilter
if limit and results.length >= limit then break if limit and results.length >= limit then break
for category, filter of filters for category, filter of filters
continue if category is 'timestamp'
break unless matches break unless matches
terms = filter.terms terms = filter.terms
# No condition for this category # No condition for this category
...@@ -835,7 +834,7 @@ class ViewFilter ...@@ -835,7 +834,7 @@ class ViewFilter
continue if conf.autofalse? and conf.autofalse annotation continue if conf.autofalse? and conf.autofalse annotation
value = conf.value annotation value = conf.value annotation
if value instanceof Array if angular.isArray value
if filter.lowercase if filter.lowercase
value = value.map (e) -> e.toLowerCase() value = value.map (e) -> e.toLowerCase()
else else
......
...@@ -18,11 +18,11 @@ SEARCH_VALUES = ...@@ -18,11 +18,11 @@ SEARCH_VALUES =
class StreamSearch class StreamSearch
this.inject = [ this.inject = [
'$location', '$scope', '$rootScope', '$location', '$scope', '$rootScope',
'queryparser', 'session', 'streamfilter' 'queryparser', 'session', 'searchfilter', 'streamfilter'
] ]
constructor: ( constructor: (
$location, $scope, $rootScope, $location, $scope, $rootScope,
queryparser, session, streamfilter queryparser, session, searchfilter, streamfilter
) -> ) ->
# Initialize the base filter # Initialize the base filter
streamfilter streamfilter
...@@ -31,7 +31,8 @@ class StreamSearch ...@@ -31,7 +31,8 @@ class StreamSearch
.setPastDataHits(50) .setPastDataHits(50)
# Apply query clauses # Apply query clauses
queryparser.populateFilter streamfilter, $location.search() query = searchfilter.generateFacetedFilter $location.search().query
queryparser.populateFilter streamfilter, query
$scope.updater?.then (sock) -> $scope.updater?.then (sock) ->
filter = streamfilter.getFilter() filter = streamfilter.getFilter()
...@@ -44,11 +45,9 @@ class StreamSearch ...@@ -44,11 +45,9 @@ class StreamSearch
$scope.search.query = $location.search() $scope.search.query = $location.search()
$scope.search.show = not angular.equals($location.search(), {}) $scope.search.show = not angular.equals($location.search(), {})
$scope.search.update = (searchCollection) -> $scope.search.update = (query) ->
# Update the query parameters unless angular.equals $location.search(query), query
query = queryparser.parseModels searchCollection.models $location.search {query:query}
unless angular.equals $location.search(), query
$location.search query
$scope.search.clear = -> $scope.search.clear = ->
$location.search({}) $location.search({})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment