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) {
input.from = 10000 - input.size;
}
return eclient.search({
index : 'claims',
_source: ['name', 'value', 'claimId'],
body : {
'query': {
// 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': {
'should': [
{
'must': {
'query_string': {
'fields': ['channel'],
'query' : input.channel,
},
},
},
};
}
const conBoost = { // Controlling claims should get higher placement in search results.
'match': {
'bid_state': {
// Controlling claims should get higher placement in search results.
'query': 'Controlling',
'boost': 20,
},
},
},
],
'must': [
{
'bool': {
'should': [
{ // Match search text as phrase - Name
};
const matPhraseName = { // Match search text as phrase - Name
'match_phrase': {
'name': {
'query': input.s.trim(),
'boost': 10,
},
},
},
{ // Match search text - Name
};
const matTextName = { // Match search text - Name
'match': {
'name': {
'query': input.s.trim(),
'boost': 5,
},
},
},
{ // Contains search term - Name
};
const conTermName = { // Contains search term - Name
'query_string': {
'query' : '*' + input.s.trim() + '*',
'fields': [
@ -79,8 +80,8 @@ function getResults (input) {
],
'boost': 3,
},
},
{
};
const atdSearch = { // ATD search(author, title, desc)
'nested': {
'path' : 'value',
'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) => {
let query = `` +
`SELECT ` +
`name, ` +
`value_as_json as value, ` +
`bid_state, ` +
`effective_amount, ` +
`claim_id as claimId ` +
`c.name,` +
`p.name as channel,` +
`c.bid_state,` +
`c.effective_amount,` +
`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.
// `vout ` +
`FROM claim ` +
`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)
// console.log(query);
rp(`https://chainquery.lbry.io/api/sql?query=` + query)