Merge pull request #54 from lbryio/search_updates

I modified the query to be more complex so that relevancy is considered.
This commit is contained in:
filipnyquist 2018-03-17 01:02:21 +01:00 committed by GitHub
commit 429fa8b3c2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -28,33 +28,94 @@ function getResults (input) {
'query': { 'query': {
'bool': { 'bool': {
'should': [ 'should': [
{ { // Match search text as phrase - Name
'match_phrase': {
'name': {
'query': input.s.trim(),
'boost': 10,
},
},
},
{ // Match search text - Name
'match': { 'match': {
'name': { 'name': {
'query': '*' + input.s.trim() + '*', 'query': input.s.trim(),
'boost': 5, 'boost': 5,
}, },
}, },
}, },
{ // Contains search term - Name
'query_string': {
'query' : '*' + input.s.trim() + '*',
'fields': [
'name',
],
'boost': 3,
},
},
{ {
'nested': { // Need nested query because value is a nested object on the elastic document 'nested': {
'path' : 'value', 'path' : 'value',
'query': { 'query': {
'bool': { 'bool': {
'should': [ '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': { 'match': {
'value.stream.metadata.title': '*' + input.s.trim() + '*', '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': { 'match': {
'value.stream.metadata.author': '*' + input.s.trim() + '*', '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': { 'match': {
'value.stream.metadata.description': '*' + input.s.trim() + '*', '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,
},
}, },
}, },
], ],