Advanced search JS: avoid re-querying for the same thing
This commit is contained in:
parent
af69b4fa58
commit
a574a75610
@ -12,6 +12,7 @@ var elasticSearcher = (function() {
|
||||
newhits: [],
|
||||
terms: {},
|
||||
page: 0,
|
||||
last_params: null, // to prevent re-querying for the same thing.
|
||||
|
||||
setQuery: (function(q, _url){
|
||||
deze.query=q;
|
||||
@ -66,6 +67,12 @@ var elasticSearcher = (function() {
|
||||
q: deze.query,
|
||||
page: deze.page,
|
||||
};
|
||||
|
||||
if (deze.last_params != null && deze.last_params.q == params.q && deze.last_params.page == params.page) {
|
||||
// We're requesting exactly the same thing as before, don't bother.
|
||||
return;
|
||||
}
|
||||
|
||||
//add term filters
|
||||
Object.assign(params, deze.terms);
|
||||
|
||||
@ -80,6 +87,7 @@ var elasticSearcher = (function() {
|
||||
|
||||
deze.newhits = newhits.slice(0);
|
||||
//cb(newhits.slice(0));
|
||||
deze.last_params = params;
|
||||
deze.results({
|
||||
'count': data.hits.total,
|
||||
'hits': newhits.slice(0),
|
||||
@ -90,6 +98,7 @@ var elasticSearcher = (function() {
|
||||
})
|
||||
.fail(function(err) {
|
||||
toastr.error(xhrErrorResponseMessage(err), 'Unable to perform search:');
|
||||
deze.last_params = null;
|
||||
})
|
||||
;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user