Fixed the auto-complete query to leverage the nested structure and to return only relevant claims and the text that triggered the auto-complete.

This commit is contained in:
Mark Beamer Jr 2018-09-16 00:53:24 -04:00
parent 59675a89ec
commit 56545cfed2
No known key found for this signature in database
GPG key ID: 1C314FB89AD76973

View file

@ -208,20 +208,41 @@ function getRoutingKey () {
function getAutoCompleteQuery (query) { function getAutoCompleteQuery (query) {
return { return {
multi_match: { bool: {
query : query.s.trim(), should: [
type : 'phrase_prefix', { // Author, Title, Description
slop : 5, nested: {
max_expansions: 50, path : 'value',
fields : [ query: {
'name', multi_match: {
'value.stream.metadata.author', query : query.s.trim(),
'value.stream.metadata.title', type : 'phrase_prefix',
'value.stream.metadata.description', slop : 5,
max_expansions: 50,
fields : [
'value.stream.metadata.author^3',
'value.stream.metadata.title^5',
'value.stream.metadata.description^2',
],
},
},
},
},
{ // Name
multi_match: {
query : query.s.trim(),
type : 'phrase_prefix',
slop : 5,
max_expansions: 50,
fields : [
'name^4',
],
},
},
], ],
}, },
}; };
} };
function getFilter (query) { function getFilter (query) {
// this is the best place for putting things like filtering on the type of content // this is the best place for putting things like filtering on the type of content
@ -235,7 +256,7 @@ function getAutoComplete (query) {
routing : getRoutingKey(query), routing : getRoutingKey(query),
ignore_unavailable: true, // ignore error when date index does not exist ignore_unavailable: true, // ignore error when date index does not exist
body : { body : {
size : query.size || 5, size : query.size || 10,
from : query.from || 0, from : query.from || 0,
query: { query: {
bool: { bool: {
@ -316,10 +337,19 @@ class LighthouseControllers {
let results = result.hits.hits; let results = result.hits.hits;
let cResults = []; let cResults = [];
for (let pResult of results) { for (let pResult of results) {
cResults.push(pResult._source.name); var name = pResult._source.name;
if (name.indexOf(ctx.query.s.trim()) > -1 && name.indexOf('http') === -1) {
cResults.push(name);
}
if (pResult._source.value && pResult._source.value.stream !== undefined) { if (pResult._source.value && pResult._source.value.stream !== undefined) {
cResults.push(pResult._source.value.stream.metadata.title); var title = pResult._source.value.stream.metadata.title;
cResults.push(pResult._source.value.stream.metadata.author); var author = pResult._source.value.stream.metadata.author;
if (title.indexOf(ctx.query.s.trim()) > -1 && title.indexOf('http') === -1) {
cResults.push(title);
}
if (author.indexOf(ctx.query.s.trim()) > -1 && author.indexOf('http') === -1) {
cResults.push(author);
}
} }
} }