This PR adds channels into the index, this combined with the added ch… #94

Merged
filipnyquist merged 1 commit from add-channel-param into master 2018-07-24 11:05:40 +02:00
2 changed files with 139 additions and 117 deletions
server
controllers
utils/chainquery

View file

@ -34,6 +34,124 @@ function getResults (input) {
if (input.from + input.size > 10000) { if (input.from + input.size > 10000) {
input.from = 10000 - input.size; input.from = 10000 - input.size;
} }
// Search is split up into different parts, all search parts goes under this line.
let channelSearch;
if (input.channel !== undefined) { // If we got a channel argument, lets filter out only that channel
channelSearch = {
'bool': {
'must': {
'query_string': {
'fields': ['channel'],
'query' : input.channel,
},
},
},
};
}
const conBoost = { // Controlling claims should get higher placement in search results.
'match': {
'bid_state': {
'query': 'Controlling',
'boost': 20,
},
},
};
const matPhraseName = { // Match search text as phrase - Name
'match_phrase': {
'name': {
'query': input.s.trim(),
'boost': 10,
},
},
};
const matTextName = { // Match search text - Name
'match': {
'name': {
'query': input.s.trim(),
'boost': 5,
},
},
};
const conTermName = { // Contains search term - Name
'query_string': {
'query' : '*' + input.s.trim() + '*',
'fields': [
'name',
],
'boost': 3,
},
};
const atdSearch = { // ATD search(author, title, desc)
'nested': {
'path' : 'value',
'query': {
'bool': {
'should': [
{ // Contains search term in Author, Title, Description
'query_string': {
'query' : '*' + input.s.trim() + '*',
'fields': [
'value.stream.metadata.author',
'value.stream.metadata.title',
'value.stream.metadata.description',
],
'boost': 1,
},
},
{ // Match search term - Author
'match': {
'value.stream.metadata.author': {
'query': input.s.trim(),
'boost': 2,
},
},
},
{ // Match search text as phrase - Author
'match_phrase': {
'value.stream.metadata.author': {
'query': input.s.trim(),
'boost': 3,
},
},
},
{ // Match search term - Title
'match': {
'value.stream.metadata.title': {
'query': input.s.trim(),
'boost': 2,
},
},
},
{ // Match search text as phrase - Title
'match_phrase': {
'value.stream.metadata.title': {
'query': input.s.trim(),
'boost': 3,
},
},
},
{ // Match search term - Description
'match': {
'value.stream.metadata.description': {
'query': input.s.trim(),
'boost': 2,
},
},
},
{ // Match search text as phrase - Description
'match_phrase': {
'value.stream.metadata.description': {
'query': input.s.trim(),
'boost': 3,
},
},
},
],
},
},
},
};
// End of search parts
return eclient.search({ return eclient.search({
index : 'claims', index : 'claims',
_source: ['name', 'value', 'claimId'], _source: ['name', 'value', 'claimId'],
@ -41,115 +159,17 @@ function getResults (input) {
'query': { 'query': {
'bool': { 'bool': {
'should': [ 'should': [
{ conBoost,
'match': {
'bid_state': {
// Controlling claims should get higher placement in search results.
'query': 'Controlling',
'boost': 20,
},
},
},
], ],
'must': [ 'must': [
channelSearch,
{ {
'bool': { 'bool': {
'should': [ 'should': [
{ // Match search text as phrase - Name matPhraseName,
'match_phrase': { matTextName,
'name': { conTermName,
'query': input.s.trim(), atdSearch,
'boost': 10,
},
},
},
{ // Match search text - Name
'match': {
'name': {
'query': input.s.trim(),
'boost': 5,
},
},
},
{ // Contains search term - Name
'query_string': {
'query' : '*' + input.s.trim() + '*',
'fields': [
'name',
],
'boost': 3,
},
},
{
'nested': {
'path' : 'value',
'query': {
'bool': {
'should': [
{ // Contains search term in Author, Title, Description
'query_string': {
'query' : '*' + input.s.trim() + '*',
'fields': [
'value.stream.metadata.author',
'value.stream.metadata.title',
'value.stream.metadata.description',
],
'boost': 1,
},
},
{ // Match search term - Author
'match': {
'value.stream.metadata.author': {
'query': input.s.trim(),
'boost': 2,
},
},
},
{ // Match search text as phrase - Author
'match_phrase': {
'value.stream.metadata.author': {
'query': input.s.trim(),
'boost': 3,
},
},
},
{ // Match search term - Title
'match': {
'value.stream.metadata.title': {
'query': input.s.trim(),
'boost': 2,
},
},
},
{ // Match search text as phrase - Title
'match_phrase': {
'value.stream.metadata.title': {
'query': input.s.trim(),
'boost': 3,
},
},
},
{ // Match search term - Description
'match': {
'value.stream.metadata.description': {
'query': input.s.trim(),
'boost': 2,
},
},
},
{ // Match search text as phrase - Description
'match_phrase': {
'value.stream.metadata.description': {
'query': input.s.trim(),
'boost': 3,
},
},
},
],
},
},
},
},
], ],
}, },
}, },
@ -255,10 +275,10 @@ class LighthouseControllers {
}); });
} }
/** /**
* Autocomplete API Endpoint. * Autocomplete API Endpoint.
* @param {ctx} Koa Context * @param {ctx} Koa Context
*/ */
async autoComplete (ctx) { async autoComplete (ctx) {
await getAutoComplete(ctx.query).then(function (result) { await getAutoComplete(ctx.query).then(function (result) {
let results = result.hits.hits; let results = result.hits.hits;

View file

@ -156,15 +156,17 @@ function getClaimsSince (time) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let query = `` + let query = `` +
`SELECT ` + `SELECT ` +
`name, ` + `c.name,` +
`value_as_json as value, ` + `p.name as channel,` +
`bid_state, ` + `c.bid_state,` +
`effective_amount, ` + `c.effective_amount,` +
`claim_id as claimId ` + `c.claim_id as claimId,` +
// `,transaction_by_hash_id, ` + // txhash and vout needed to leverage old format for comparison. `c.value_as_json as value ` +
// `vout ` + // `,transaction_by_hash_id, ` + // txhash and vout needed to leverage old format for comparison.
`FROM claim ` + // `vout ` +
`WHERE modified >='` + time + `'`; `FROM claim c ` +
`LEFT JOIN claim p on p.claim_id = c.publisher_id ` +
`WHERE c.modified >='` + time + `'`;
// Outputs full query to console for copy/paste into chainquery (debugging) // Outputs full query to console for copy/paste into chainquery (debugging)
// console.log(query); // console.log(query);
rp(`https://chainquery.lbry.io/api/sql?query=` + query) rp(`https://chainquery.lbry.io/api/sql?query=` + query)