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:
parent
59675a89ec
commit
56545cfed2
1 changed files with 45 additions and 15 deletions
|
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue