This PR adds channels into the index, this combined with the added channel filtering parameter allows us to search specific channels for content.

While adding the code for filtering I split the search query into individual parts so it easier can be edited and read.
This commit is contained in:
filipnyquist 2018-07-23 12:06:47 +02:00
parent cf3cac7b79
commit 4423fc2cfc
2 changed files with 139 additions and 117 deletions

View file

@ -34,44 +34,45 @@ 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;
} }
return eclient.search({ // Search is split up into different parts, all search parts goes under this line.
index : 'claims', let channelSearch;
_source: ['name', 'value', 'claimId'], if (input.channel !== undefined) { // If we got a channel argument, lets filter out only that channel
body : { channelSearch = {
'query': {
'bool': { 'bool': {
'should': [ 'must': {
{ 'query_string': {
'fields': ['channel'],
'query' : input.channel,
},
},
},
};
}
const conBoost = { // Controlling claims should get higher placement in search results.
'match': { 'match': {
'bid_state': { 'bid_state': {
// Controlling claims should get higher placement in search results.
'query': 'Controlling', 'query': 'Controlling',
'boost': 20, 'boost': 20,
}, },
}, },
}, };
], const matPhraseName = { // Match search text as phrase - Name
'must': [
{
'bool': {
'should': [
{ // Match search text as phrase - Name
'match_phrase': { 'match_phrase': {
'name': { 'name': {
'query': input.s.trim(), 'query': input.s.trim(),
'boost': 10, 'boost': 10,
}, },
}, },
}, };
{ // Match search text - Name const matTextName = { // Match search text - Name
'match': { 'match': {
'name': { 'name': {
'query': input.s.trim(), 'query': input.s.trim(),
'boost': 5, 'boost': 5,
}, },
}, },
}, };
{ // Contains search term - Name const conTermName = { // Contains search term - Name
'query_string': { 'query_string': {
'query' : '*' + input.s.trim() + '*', 'query' : '*' + input.s.trim() + '*',
'fields': [ 'fields': [
@ -79,8 +80,8 @@ function getResults (input) {
], ],
'boost': 3, 'boost': 3,
}, },
}, };
{ const atdSearch = { // ATD search(author, title, desc)
'nested': { 'nested': {
'path' : 'value', 'path' : 'value',
'query': { 'query': {
@ -149,7 +150,26 @@ function getResults (input) {
}, },
}, },
}, },
}, };
// End of search parts
return eclient.search({
index : 'claims',
_source: ['name', 'value', 'claimId'],
body : {
'query': {
'bool': {
'should': [
conBoost,
],
'must': [
channelSearch,
{
'bool': {
'should': [
matPhraseName,
matTextName,
conTermName,
atdSearch,
], ],
}, },
}, },

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,` +
`c.value_as_json as value ` +
// `,transaction_by_hash_id, ` + // txhash and vout needed to leverage old format for comparison. // `,transaction_by_hash_id, ` + // txhash and vout needed to leverage old format for comparison.
// `vout ` + // `vout ` +
`FROM claim ` + `FROM claim c ` +
`WHERE modified >='` + time + `'`; `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)