Improved shown search result of extended search.

This commit is contained in:
Martin Edenhofer 2016-07-08 01:34:21 +02:00
parent 80a9fd5dab
commit 05cf8c208a
2 changed files with 5 additions and 1 deletions

View file

@ -122,6 +122,7 @@ class App.Search extends App.Controller
App.GlobalSearch.execute( App.GlobalSearch.execute(
query: @query query: @query
render: @renderResult render: @renderResult
limit: 50
) )
renderResult: (result = []) => renderResult: (result = []) =>

View file

@ -15,12 +15,13 @@ class _globalSearchSingleton extends Spine.Module
execute: (params) -> execute: (params) ->
query = params.query query = params.query
render = params.render render = params.render
limit = params.limit || 10
# use cache for search result # use cache for search result
if @searchResultCache[query] if @searchResultCache[query]
render(@searchResultCache[query].result) render(@searchResultCache[query].result)
currentTime = new Date currentTime = new Date
return if @searchResultCache[query].time > currentTime.setSeconds(currentTime.getSeconds() - 20) return if @searchResultCache[query].limit is limit && @searchResultCache[query].time > currentTime.setSeconds(currentTime.getSeconds() - 20)
App.Ajax.request( App.Ajax.request(
id: 'search' id: 'search'
@ -28,6 +29,7 @@ class _globalSearchSingleton extends Spine.Module
url: "#{@apiPath}/search" url: "#{@apiPath}/search"
data: data:
query: query query: query
limit: limit
processData: true, processData: true,
success: (data, status, xhr) => success: (data, status, xhr) =>
App.Collection.loadAssets(data.assets) App.Collection.loadAssets(data.assets)
@ -53,6 +55,7 @@ class _globalSearchSingleton extends Spine.Module
@searchResultCache[query] = @searchResultCache[query] =
result: result result: result
resultRaw: data.result resultRaw: data.result
limit: limit
time: new Date time: new Date
# if result hasn't changed, do not rerender # if result hasn't changed, do not rerender