Merge pull request #42 from BelfordZ/feature/auto-complete

fix(search) Update getAutoComplete
This commit is contained in:
filipnyquist 2017-10-31 12:00:08 +01:00 committed by GitHub
commit bdfeee4a9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 24 deletions

View file

@ -2,7 +2,7 @@
"name": "lighthouse",
"description": "Lighthouse is a lightning-fast advanced search engine API for publications on the lbrycrd with autocomplete capabilities.",
"version": "0.0.1",
"author": "filipnyquist <filip@lbry.io>,
"author": "filipnyquist <filip@lbry.io>",
"keywords": [
"lbry",
"search",

View file

@ -18,6 +18,7 @@ const eclient = new elasticsearch.Client({
},
});
function getResults (input) {
if (input.size === undefined) input.size = 10;
if (input.from === undefined) input.from = 0;
@ -46,30 +47,57 @@ function getResults (input) {
});
}
function getAutoComplete (input) {
if (input.size === undefined) input.size = 10;
if (input.from === undefined) input.from = 0;
function getIndex() {
// 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.
return;
}
function getRoutingKey() {
// 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) {
return {
multi_match: {
query: query.s.trim(),
type: 'phrase_prefix',
slop: 5,
max_expansions: 50,
fields: [
'name',
'value.stream.metadata.author',
'value.stream.metadata.title',
'value.stream.metadata.description'
]
}
};
}
function getFilter(query) {
// 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
return;
}
function getAutoComplete(query) {
return eclient.search({
index : 'claims',
_source: ['name', 'value.stream.metadata.title', 'value.stream.metadata.author'],
body : {
'query': {
'bool': {
'must': {
'query_string': {
'query' : '*' + input.s.trim() + '*',
'fields': [
'name',
'value.stream.metadata.title',
'value.stream.metadata.author',
],
},
},
},
},
size: input.size,
from: input.from,
index: getIndex(query) || 'claims',
routing: getRoutingKey(query),
ignore_unavailable: true, // ignore error when date index does not exist
body: {
size: query.size || 5,
from: query.from || 0,
query: {
bool: {
must: getAutoCompleteQuery(query),
filter: getFilter(query)
}
}
},
size: query.size,
from: query.from,
});
}

View file

@ -124,7 +124,7 @@ export async function sync () {
// Done adding, update our claimTrie cache to latest and wait a bit...
await saveJSON(path.join(appRoot.path, 'claimTrieCache.json'), latestClaimTrie);
status.info = 'upToDate';
await sleep(300000);
await sleep(600000);
sync();
} catch (err) {
winston.log(err);