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:
parent
cf3cac7b79
commit
4423fc2cfc
2 changed files with 139 additions and 117 deletions
|
@ -34,6 +34,124 @@ function getResults (input) {
|
|||
if (input.from + input.size > 10000) {
|
||||
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({
|
||||
index : 'claims',
|
||||
_source: ['name', 'value', 'claimId'],
|
||||
|
@ -41,115 +159,17 @@ function getResults (input) {
|
|||
'query': {
|
||||
'bool': {
|
||||
'should': [
|
||||
{
|
||||
'match': {
|
||||
'bid_state': {
|
||||
// Controlling claims should get higher placement in search results.
|
||||
'query': 'Controlling',
|
||||
'boost': 20,
|
||||
},
|
||||
},
|
||||
},
|
||||
conBoost,
|
||||
],
|
||||
'must': [
|
||||
channelSearch,
|
||||
{
|
||||
'bool': {
|
||||
'should': [
|
||||
{ // Match search text as phrase - Name
|
||||
'match_phrase': {
|
||||
'name': {
|
||||
'query': input.s.trim(),
|
||||
'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,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
matPhraseName,
|
||||
matTextName,
|
||||
conTermName,
|
||||
atdSearch,
|
||||
],
|
||||
},
|
||||
},
|
||||
|
@ -255,10 +275,10 @@ class LighthouseControllers {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Autocomplete API Endpoint.
|
||||
* @param {ctx} Koa Context
|
||||
*/
|
||||
/**
|
||||
* Autocomplete API Endpoint.
|
||||
* @param {ctx} Koa Context
|
||||
*/
|
||||
async autoComplete (ctx) {
|
||||
await getAutoComplete(ctx.query).then(function (result) {
|
||||
let results = result.hits.hits;
|
||||
|
|
|
@ -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 ` +
|
||||
// `,transaction_by_hash_id, ` + // txhash and vout needed to leverage old format for comparison.
|
||||
// `vout ` +
|
||||
`FROM claim ` +
|
||||
`WHERE modified >='` + time + `'`;
|
||||
`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 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)
|
||||
|
|
Loading…
Reference in a new issue