Advanced search JS: avoid re-querying for the same thing
This commit is contained in:
@@ -12,6 +12,7 @@ var elasticSearcher = (function() {
|
|||||||
newhits: [],
|
newhits: [],
|
||||||
terms: {},
|
terms: {},
|
||||||
page: 0,
|
page: 0,
|
||||||
|
last_params: null, // to prevent re-querying for the same thing.
|
||||||
|
|
||||||
setQuery: (function(q, _url){
|
setQuery: (function(q, _url){
|
||||||
deze.query=q;
|
deze.query=q;
|
||||||
@@ -66,6 +67,12 @@ var elasticSearcher = (function() {
|
|||||||
q: deze.query,
|
q: deze.query,
|
||||||
page: deze.page,
|
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
|
//add term filters
|
||||||
Object.assign(params, deze.terms);
|
Object.assign(params, deze.terms);
|
||||||
|
|
||||||
@@ -80,6 +87,7 @@ var elasticSearcher = (function() {
|
|||||||
|
|
||||||
deze.newhits = newhits.slice(0);
|
deze.newhits = newhits.slice(0);
|
||||||
//cb(newhits.slice(0));
|
//cb(newhits.slice(0));
|
||||||
|
deze.last_params = params;
|
||||||
deze.results({
|
deze.results({
|
||||||
'count': data.hits.total,
|
'count': data.hits.total,
|
||||||
'hits': newhits.slice(0),
|
'hits': newhits.slice(0),
|
||||||
@@ -90,6 +98,7 @@ var elasticSearcher = (function() {
|
|||||||
})
|
})
|
||||||
.fail(function(err) {
|
.fail(function(err) {
|
||||||
toastr.error(xhrErrorResponseMessage(err), 'Unable to perform search:');
|
toastr.error(xhrErrorResponseMessage(err), 'Unable to perform search:');
|
||||||
|
deze.last_params = null;
|
||||||
})
|
})
|
||||||
;
|
;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user