Search results + suggestions

This commit is contained in:
NGPixel
2016-09-05 14:11:51 -04:00
parent 7945d024ad
commit dca6b71610
12 changed files with 171 additions and 65 deletions

View File

@@ -50,16 +50,43 @@ module.exports = {
.toLower()
.trim()
.replace(/[^a-z0-9 ]/g, '')
.split(' ')
.filter((f) => { return !_.isEmpty(f); })
.value();
let arrTerms = _.chain(terms)
.split(' ')
.filter((f) => { return !_.isEmpty(f); })
.value();
return self._si.searchAsync({
query: {
AND: [{ '*': terms }]
AND: [{ '*': arrTerms }]
},
pageSize: 10
}).get('hits');
}).get('hits').then((hits) => {
if(hits.length < 5) {
return self._si.matchAsync({
beginsWith: terms,
threshold: 3,
limit: 5,
type: 'simple'
}).then((matches) => {
return {
match: hits,
suggest: matches
};
});
} else {
return {
match: hits,
suggest: []
};
}
});
},