Commit 9ffe1bbc authored by Randall Leeds's avatar Randall Leeds

Consistently use q as the search query parameter

This unifies the stream and page_search query parameter usage. Both now
use the 'q' parameter. Additionally, the search string is passed to
`simpleSearch` directive and the `QueryParser` instead of an object
with a "query" or "q" key.

The clump of conditionals in the route update event handler is removed.
Instead, the viewer and page search redirect to one another and the
stream can be totally ignorant of the involvement of the location.

The views are updated to use ?q= for /u and /t shortcuts.
parent f038c8d2
......@@ -10,6 +10,7 @@ class App
frame:
visible: false
ongoingHighlightSwitch: false
search: {}
sheet: {}
sorts: [
'Newest'
......@@ -40,7 +41,7 @@ class App
socialView: annotator.socialView
ongoingHighlightSwitch: false
search:
query: $location.search()
query: $location.search()['q']
session: session
_reset()
......@@ -212,38 +213,23 @@ class App
$rootScope.applySort "Location"
$scope.query = $location.search()
$scope.search = {}
$scope.search.update = angular.noop
$scope.search.clear = angular.noop
$rootScope.$on '$routeChangeSuccess', (event, next, current) ->
unless next.$$route? then return
$scope.search.query = $location.search()
if next.$$route.originalPath is '/viewer'
$rootScope.viewState.show = true
else
$rootScope.viewState.show = false
$scope.search.query = $location.search()['q']
$rootScope.viewState.show = next.$$route.originalPath is '/viewer'
unless next.$$route.originalPath is '/stream'
if current and next.$$route.originalPath is '/a/:id'
$scope.reloadAnnotations()
$scope.search.update = (searchCollection) ->
return unless annotator.discardDrafts()
query = {query: searchCollection}
unless angular.equals $location.search(), query
if $location.path() == '/viewer' or $location.path() == '/page_search'
$location.path('/page_search').search(query)
else
$location.path('/stream').search(query)
$scope.search.clear = ->
$location.url('/viewer')
$location.search('q', null)
$scope.search.update = (query) ->
unless angular.equals $location.search()['q'], query
if annotator.discardDrafts()
$location.search('q', query or null)
$scope.reloadAnnotations = ->
Store = plugins.Store
......@@ -720,6 +706,9 @@ class Viewer
$location, $rootScope, $routeParams, $scope,
annotator
) ->
if $routeParams.q
return $location.path('/page_search').replace()
{providers, threading} = annotator
$scope.activate = (annotation) ->
......@@ -746,12 +735,14 @@ class Search
'annotator', 'viewFilter']
constructor: ($filter, $location, $rootScope, $routeParams, $sce, $scope,
annotator, viewFilter) ->
unless $routeParams.q
return $location.path('/viewer').replace()
{providers, threading} = annotator
$scope.highlighter = '<span class="search-hl-active">$&</span>'
$scope.filter_orderBy = $filter('orderBy')
$scope.matches = []
$scope.search.query = $location.search()
$scope.render_order = {}
$scope.render_pos = {}
$scope.ann_info =
......@@ -823,7 +814,8 @@ class Search
refresh()
refresh = =>
[$scope.matches, $scope.filters] = viewFilter.filter $rootScope.annotations, $routeParams
query = $routeParams.q
[$scope.matches, $scope.filters] = viewFilter.filter $rootScope.annotations, query
# Create the regexps for highlighting the matches inside the annotations' bodies
$scope.text_tokens = $scope.filters.text.terms.slice()
$scope.text_regexp = []
......
......@@ -412,8 +412,8 @@ simpleSearch = ['$parse', ($parse) ->
_clear(scope) if attr.onclear
scope.$watch attr.query, (query) ->
if query.query?
scope.searchtext = query.query
if query?
scope.searchtext = query
_search(scope, {"this": scope.searchtext})
restrict: 'C'
......
......@@ -788,7 +788,7 @@ class ViewFilter
# the faceted filters
# ]
filter: (annotations, query) =>
filters = @searchfilter.generateFacetedFilter query.query
filters = @searchfilter.generateFacetedFilter query
results = []
# Check for given limit
......
......@@ -11,11 +11,11 @@ imports = [
class StreamSearch
this.inject = [
'$location', '$scope', '$rootScope',
'$scope', '$rootScope',
'queryparser', 'session', 'searchfilter', 'streamfilter'
]
constructor: (
$location, $scope, $rootScope,
$scope, $rootScope,
queryparser, session, searchfilter, streamfilter
) ->
# Initialize the base filter
......@@ -25,8 +25,7 @@ class StreamSearch
.setPastDataHits(50)
# Apply query clauses
$scope.query = $location.search()['query']
terms = searchfilter.generateFacetedFilter $scope.query
terms = searchfilter.generateFacetedFilter $scope.search.query
queryparser.populateFilter streamfilter, terms
$scope.updater?.then (sock) ->
......@@ -37,15 +36,6 @@ class StreamSearch
$rootScope.applyView "Document" # Non-sensical, but best for the moment
$rootScope.applySort "Newest"
$scope.search.query = $location.search()
$scope.search.update = (query) ->
unless angular.equals $location.search(query), query
$location.search {query:query}
$scope.search.clear = ->
$location.search({})
$scope.openDetails = (annotation) ->
$scope.loadMore = (number) =>
# TODO: debounce
......
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