Implements a search
This commit is contained in:
@@ -35,12 +35,41 @@ services.factory('albumService',['$http','$log','$q', function($http,$log,$q) {
|
||||
});
|
||||
}
|
||||
|
||||
function search(terms) {
|
||||
var defer = $q.defer();
|
||||
defer.reject('Search is not implemented');
|
||||
return defer.promise;
|
||||
var keywordRegexp = /(\s+)|$/g;
|
||||
|
||||
function fuzzifyTerms(terms) {
|
||||
return terms.replace(keywordRegexp,"~2 ");
|
||||
}
|
||||
|
||||
function processResult(res, timeOffset) {
|
||||
res.took += timeOffset;
|
||||
return res;
|
||||
}
|
||||
|
||||
function search(terms,from,fuzzify, previousTime) {
|
||||
if (typeof fuzzify == 'undefined' ) {
|
||||
fuzzify = true;
|
||||
}
|
||||
if (typeof previousTime == 'undefined' ) {
|
||||
previousTime = 0;
|
||||
}
|
||||
|
||||
return $http.post('/api/search', {
|
||||
"size" : 10,
|
||||
"from": from || 0,
|
||||
"explain": false,
|
||||
"highlight":{},
|
||||
"fields": ["ID","série","collection","titre","éditeur","ref","description","Note"],
|
||||
"query": {
|
||||
"query": terms
|
||||
}
|
||||
}).then(function(response) {
|
||||
if ( fuzzify == true && response.data.total_hits == 0) {
|
||||
return search(fuzzifyTerms(terms),from,false,response.data.took);
|
||||
}
|
||||
return processResult(response.data,previousTime);
|
||||
});
|
||||
}
|
||||
return {
|
||||
get: get,
|
||||
search: search
|
||||
|
||||
Reference in New Issue
Block a user