Commit 83e1f6cb authored by Ujvari Gergely's avatar Ujvari Gergely

StreamSearch uri formatter bugfix

parent 5c8b9aec
...@@ -13,6 +13,7 @@ get_quote = (annotation) -> ...@@ -13,6 +13,7 @@ get_quote = (annotation) ->
# It expects the following dict format as rules # It expects the following dict format as rules
# { facet_name : { # { facet_name : {
# formatter: to format the value (optional) # formatter: to format the value (optional)
# path: json path mapping to the annotation field
# 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)
...@@ -51,13 +52,14 @@ class SearchHelper ...@@ -51,13 +52,14 @@ class SearchHelper
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
and_or = if rule.and_or? then rule.and_or else 'or' and_or = if rule.and_or? then rule.and_or else 'or'
mapped_field = if rule.path? then rule.path else '/'+category
if values.length is 1 if values.length is 1
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'
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.addClause '/'+category, oper_part, value_part, case_sensitive filter.addClause mapped_field, oper_part, value_part, case_sensitive
else else
if and_or is 'or' if and_or is 'or'
val_list = '' val_list = ''
...@@ -65,18 +67,18 @@ class SearchHelper ...@@ -65,18 +67,18 @@ class SearchHelper
for val in values for val in values
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 val_list += value_part
oper_part = oper_part =
if rule.operator? then rule.operator if rule.operator? then rule.operator
else if exact_match then 'one_of' else 'match_of' else if exact_match then 'one_of' else 'match_of'
filter.addClause '/'+category, oper_part, value_part, case_sensitive filter.addClause mapped_field, oper_part, val_list, case_sensitive
else else
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 values
value_part = if rule.formatter then rule.formatter val else val value_part = if rule.formatter then rule.formatter val else val
filter.addClause '/'+category, oper_part, value_part, case_sensitive filter.addClause mapped_field, oper_part, value_part, case_sensitive
filter.getFilter() filter.getFilter()
...@@ -85,28 +87,33 @@ class StreamSearch ...@@ -85,28 +87,33 @@ class StreamSearch
user: user:
formatter: (user) -> formatter: (user) ->
'acct:' + user + '@' + window.location.hostname 'acct:' + user + '@' + window.location.hostname
path: '/user'
exact_match: true exact_match: true
case_sensitive: false case_sensitive: false
and_or: 'or' and_or: 'or'
text: text:
path: '/text'
exact_match: false exact_match: false
case_sensitive: false case_sensitive: false
and_or: 'and' and_or: 'and'
tags: tags:
path: '/tags'
exact_match: false exact_match: false
case_sensitive: false case_sensitive: false
and_or: 'or' and_or: 'or'
quote: quote:
path: "/quote"
exact_match: false exact_match: false
case_sensitive: false case_sensitive: false
and_or: 'and' and_or: 'and'
uri: uri:
formatter: (uri) -> formatter: (uri) ->
uri = uri.toLowerCase() uri = uri.toLowerCase()
if url.match(/http:\/\//) then url = url.substring(7) if uri.match(/http:\/\//) then uri = uri.substring(7)
if url.match(/https:\/\//) then url = url.substring(8) if uri.match(/https:\/\//) then uri = uri.substring(8)
if url.match(/^www\./) then url = url.substring(4) if uri.match(/^www\./) then uri = uri.substring(4)
uri uri
path: '/uri'
exact_match: false exact_match: false
case_sensitive: false case_sensitive: false
and_or: 'or' and_or: 'or'
...@@ -123,6 +130,7 @@ class StreamSearch ...@@ -123,6 +130,7 @@ class StreamSearch
when '1 month' then 30*24*60*60 when '1 month' then 30*24*60*60
when '1 year' then 365*24*60*60 when '1 year' then 365*24*60*60
new Date(new Date().valueOf() - seconds*1000) new Date(new Date().valueOf() - seconds*1000)
path: '/created'
exact_match: false exact_match: false
case_sensitive: true case_sensitive: true
and_or: 'and' and_or: 'and'
...@@ -165,6 +173,7 @@ class StreamSearch ...@@ -165,6 +173,7 @@ class StreamSearch
.noClauses() .noClauses()
filter = new SearchHelper().populateFilter filter, searchCollection.models, @rules filter = new SearchHelper().populateFilter filter, searchCollection.models, @rules
console.log filter
$scope.initStream filter $scope.initStream filter
# Update the parameters # Update the parameters
......
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