Commit c5313dde authored by Randall Leeds's avatar Randall Leeds

Use new VS directive in streamsearch

For now. Soon we will merge this with the page search and make things
much more similar.
parent a7253208
...@@ -7,6 +7,12 @@ imports = [ ...@@ -7,6 +7,12 @@ imports = [
'h.streamfilter' 'h.streamfilter'
] ]
SEARCH_FACETS = ['text', 'tags', 'uri', 'quote', 'since', 'user', 'results']
SEARCH_VALUES =
group: ['Public', 'Private'],
since: ['5 min', '30 min', '1 hour', '12 hours',
'1 day', '1 week', '1 month', '1 year']
get_quote = (annotation) -> get_quote = (annotation) ->
if annotation.quote? then return annotation.quote if annotation.quote? then return annotation.quote
...@@ -168,63 +174,33 @@ class StreamSearch ...@@ -168,63 +174,33 @@ class StreamSearch
a_upd.getTime() - b_upd.getTime() a_upd.getTime() - b_upd.getTime()
# Read search params # Read search params
search_query = '' $scope.query = $location.search()
params = $location.search() $scope.searchFacets = SEARCH_FACETS
for param, values of params $scope.searchValues = SEARCH_VALUES
# Ignore non facet parameters
if param in @facets $scope.search = (searchCollection) =>
unless values instanceof Array then values = [values] # Assemble the filter json
for value in values filter =
search_query += param + ': "' + value + '" ' streamfilter
.setMatchPolicyIncludeAll()
# Initialize Visual search .noClauses()
@search = VS.init
container: $element.find('.visual-search') [filter, $scope.categories] =
query: search_query new SearchHelper().populateFilter filter, searchCollection.models, @rules
callbacks: $scope.initStream filter
search: (query, searchCollection) =>
# Assemble the filter json # Update the parameters
filter = $location.search $scope.categories
streamfilter
.setMatchPolicyIncludeAll() $scope.searchClear = ->
.noClauses() filter =
streamfilter
[filter, $scope.categories] = .resetFilter()
new SearchHelper().populateFilter filter, searchCollection.models, @rules .setPastDataHits(50)
$scope.initStream filter $scope.annotations = []
$scope.empty = false
# Update the parameters $scope.initStream filter.getFilter()
$location.search $scope.categories $location.search({})
facetMatches: (callback) =>
# Created and limit should be singleton.
add_limit = true
add_created = true
for facet in @search.searchQuery.facets()
if facet.hasOwnProperty 'results' then add_limit = false
if facet.hasOwnProperty 'since' then add_created = false
if add_limit and add_created then list = ['text','tags', 'uri', 'quote','since','user','results']
else
if add_limit then list = ['text','tags', 'uri', 'quote','user', 'results']
else
if add_created then list = ['text','tags', 'uri', 'quote','since','user']
else list = ['text','tags', 'uri', 'quote','user']
return callback list, {preserveOrder: true}
valueMatches: (facet, searchTerm, callback) ->
switch facet
when 'results'
callback ['0', '10', '25', '50', '100', '250', '1000']
when 'since'
callback ['5 min', '30 min', '1 hour', '12 hours', '1 day', '1 week', '1 month', '1 year'], {preserveOrder: true}
clearSearch: (original) =>
# Execute clearSearch's internal method for resetting search
original()
$scope.$apply ->
$scope.annotations = []
$scope.empty = false
$location.search {}
$scope.initStream = (filter) -> $scope.initStream = (filter) ->
if $scope.sock? then $scope.sock.close() if $scope.sock? then $scope.sock.close()
...@@ -304,9 +280,6 @@ class StreamSearch ...@@ -304,9 +280,6 @@ class StreamSearch
$scope.annotations = [] $scope.annotations = []
$timeout =>
@search.searchBox.app.options.callbacks.search @search.searchBox.value(), @search.searchBox.app.searchQuery
,500
configure = [ configure = [
......
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