Commit 2a673e1a authored by Ujvari Gergely's avatar Ujvari Gergely

StreamSearch improvements

- Now it supports created search-facet
- Searchhelper rule: operator property (uses this exact operator)
- Bugfix: Space was a split value for the facet value. It is no longer one.
parent bcdf38da
...@@ -16,6 +16,7 @@ get_quote = (annotation) -> ...@@ -16,6 +16,7 @@ get_quote = (annotation) ->
# exact_match: true|false (default: true) # exact_match: true|false (default: true)
# case_sensitive: true|false (default: false) # case_sensitive: true|false (default: false)
# and_or: and|or for multiple values should it threat them as 'or' or 'and' (def: or) # and_or: and|or for multiple values should it threat them as 'or' or 'and' (def: or)
# operator: if given it'll use this operator regardless of other circumstances
# } # }
# The models is the direct output from visualsearch # The models is the direct output from visualsearch
# The limit is the default limit # The limit is the default limit
...@@ -49,13 +50,14 @@ class SearchHelper ...@@ -49,13 +50,14 @@ class SearchHelper
# 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
case_sensitive = if rule.case_sensitive? then rule.case_sensitive else false case_sensitive = if rule.case_sensitive? then rule.case_sensitive else false
cs_part = if case_sensitive then '' else 'i'
and_or = if rule.and_or? then rule.and_or else 'or' and_or = if rule.and_or? then rule.and_or else 'or'
if values.length is 1 if values.length is 1
oper_part = if exact_match then '=' else '#' oper_part =
if rule.operator? then rule.operator
else if exact_match then 'equals' else 'matches'
value_part = if rule.formatter then rule.formatter values[0] else values[0] value_part = if rule.formatter then rule.formatter values[0] else values[0]
filter.addClausesParse category+':' + cs_part + oper_part + value_part filter.addClause '/'+category, oper_part, value_part, case_sensitive
else else
if and_or is 'or' if and_or is 'or'
val_list = '' val_list = ''
...@@ -64,13 +66,17 @@ class SearchHelper ...@@ -64,13 +66,17 @@ class SearchHelper
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
value_list += value_part value_list += value_part
oper_part = if exact_match then '[' else '{' oper_part =
filter.addClausesParse category+':' + cs_part + oper_part + value_part if rule.operator? then rule.operator
else if exact_match then 'one_of' else 'match_of'
filter.addClause '/'+category, oper_part, value_part, case_sensitive
else else
oper_part = if exact_match then '=' else '#' oper_part =
if rule.operator? then rule.operator
else if exact_match then 'equals' else 'matches'
for val in values for val in values
value_part = if rule.formatter then rule.formatter val else val value_part = if rule.formatter then rule.formatter val else val
filter.addClausesParse category+':' + cs_part + oper_part + value_part filter.addClause '/'+category, oper_part, value_part, case_sensitive
filter.getFilter() filter.getFilter()
...@@ -102,11 +108,23 @@ class StreamSearch ...@@ -102,11 +108,23 @@ class StreamSearch
exact_match: false exact_match: false
case_sensitive: false case_sensitive: false
and_or: 'or' and_or: 'or'
#TODO: work on time, custom operator, proper format created:
#time: formatter: (past) ->
# exact_match: false seconds =
# case_sensitive: true switch past
# and_or: 'and' when '5 min' then 5*60
when '30 min' then 30*60
when '1 hour' then 60*60
when '12 hours' then 12*60*60
when '1 day' then 24*60*60
when '1 week' then 7*24*60*60
when '1 month' then 30*24*60*60
when '1 year' then 365*24*60*60
new Date(new Date().valueOf() - seconds*1000)
exact_match: false
case_sensitive: true
and_or: 'and'
operator: 'ge'
this.inject = ['$element', '$location', '$scope', '$timeout', 'streamfilter'] this.inject = ['$element', '$location', '$scope', '$timeout', 'streamfilter']
constructor: ( constructor: (
...@@ -152,11 +170,11 @@ class StreamSearch ...@@ -152,11 +170,11 @@ class StreamSearch
'query' : query 'query' : query
facetMatches: (callback) => facetMatches: (callback) =>
return callback ['text','tags', 'uri', 'quote','time','user', 'limit'], {preserveOrder: true} return callback ['text','tags', 'uri', 'quote','created','user','limit'], {preserveOrder: true}
valueMatches: (facet, searchTerm, callback) -> valueMatches: (facet, searchTerm, callback) ->
switch facet switch facet
when 'limit' then callback [0, 10, 25, 50, 100, 250, 1000] when 'limit' then callback [0, 10, 25, 50, 100, 250, 1000]
when 'time' when 'created'
callback ['5 min', '30 min', '1 hour', '12 hours', '1 day', '1 week', '1 month', '1 year'], {preserveOrder: true} callback ['5 min', '30 min', '1 hour', '12 hours', '1 day', '1 week', '1 month', '1 year'], {preserveOrder: true}
clearSearch: (original) => clearSearch: (original) =>
# Execute clearSearch's internal method for resetting search # Execute clearSearch's internal method for resetting 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