Merge pull request #53 from lbryio/search_updates
using ^n on a field is only valid syntax for lycene. This caused the …
This commit is contained in:
commit
14bfde88b9
1 changed files with 29 additions and 27 deletions
|
@ -18,7 +18,6 @@ const eclient = new elasticsearch.Client({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
function getResults (input) {
|
function getResults (input) {
|
||||||
if (input.size === undefined) input.size = 10;
|
if (input.size === undefined) input.size = 10;
|
||||||
if (input.from === undefined) input.from = 0;
|
if (input.from === undefined) input.from = 0;
|
||||||
|
@ -31,7 +30,10 @@ function getResults (input) {
|
||||||
'should': [
|
'should': [
|
||||||
{
|
{
|
||||||
'match': {
|
'match': {
|
||||||
'name^100': '*' + input.s.trim() + '*',
|
'name': {
|
||||||
|
'query': '*' + input.s.trim() + '*',
|
||||||
|
'boost': 5,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -86,54 +88,54 @@ function getResults (input) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function getIndex() {
|
function getIndex () {
|
||||||
// ideally, data is inserted into elastic search with an index that helps us query it faster/better results
|
// ideally, data is inserted into elastic search with an index that helps us query it faster/better results
|
||||||
// A simple start is to default queries to be within the n months, and to make a new index each month.
|
// A simple start is to default queries to be within the n months, and to make a new index each month.
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getRoutingKey() {
|
function getRoutingKey () {
|
||||||
// This is the most important field for performance. Being able to route the queries ahead of time can make typedowns insanely good.
|
// This is the most important field for performance. Being able to route the queries ahead of time can make typedowns insanely good.
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAutoCompleteQuery(query) {
|
function getAutoCompleteQuery (query) {
|
||||||
return {
|
return {
|
||||||
multi_match: {
|
multi_match: {
|
||||||
query: query.s.trim(),
|
query : query.s.trim(),
|
||||||
type: 'phrase_prefix',
|
type : 'phrase_prefix',
|
||||||
slop: 5,
|
slop : 5,
|
||||||
max_expansions: 50,
|
max_expansions: 50,
|
||||||
fields: [
|
fields : [
|
||||||
'name',
|
'name',
|
||||||
'value.stream.metadata.author',
|
'value.stream.metadata.author',
|
||||||
'value.stream.metadata.title',
|
'value.stream.metadata.title',
|
||||||
'value.stream.metadata.description'
|
'value.stream.metadata.description',
|
||||||
]
|
],
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
// Perhaps we can add search param that will filter on how people have categorized / tagged their content
|
// Perhaps we can add search param that will filter on how people have categorized / tagged their content
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAutoComplete(query) {
|
function getAutoComplete (query) {
|
||||||
return eclient.search({
|
return eclient.search({
|
||||||
index: getIndex(query) || 'claims',
|
index : getIndex(query) || 'claims',
|
||||||
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 || 5,
|
||||||
from: query.from || 0,
|
from : query.from || 0,
|
||||||
query: {
|
query: {
|
||||||
bool: {
|
bool: {
|
||||||
must: getAutoCompleteQuery(query),
|
must : getAutoCompleteQuery(query),
|
||||||
filter: getFilter(query)
|
filter: getFilter(query),
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
size: query.size,
|
size: query.size,
|
||||||
from: query.from,
|
from: query.from,
|
||||||
|
@ -191,7 +193,7 @@ class LighthouseControllers {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var clean = new Array();
|
var clean = [];
|
||||||
for (var i = 0; i < cResults.length; i++) {
|
for (var i = 0; i < cResults.length; i++) {
|
||||||
if (cResults[i] && cResults[i].length > 3 && clean.indexOf(cResults[i]) === -1) {
|
if (cResults[i] && cResults[i].length > 3 && clean.indexOf(cResults[i]) === -1) {
|
||||||
clean.push(cResults[i]);
|
clean.push(cResults[i]);
|
||||||
|
|
Loading…
Reference in a new issue