improve related search querying
This commit is contained in:
parent
faa3b87aa3
commit
ca87bf56b3
@ -14,23 +14,30 @@ const STOP_WORDS = ['a', 'an', 'and', 'are', 'as', 'at', 'be', 'but',
|
|||||||
'levels', 'from', 'cryptocurrencies', 'confirmed', 'news', 'network',
|
'levels', 'from', 'cryptocurrencies', 'confirmed', 'news', 'network',
|
||||||
'about', 'sources', 'vote', 'considerations', 'hope',
|
'about', 'sources', 'vote', 'considerations', 'hope',
|
||||||
'keep', 'keeps', 'including', 'we', 'brings', "don't", 'do',
|
'keep', 'keeps', 'including', 'we', 'brings', "don't", 'do',
|
||||||
'interesting', 'us', 'welcome']
|
'interesting', 'us', 'welcome', 'thoughts', 'results']
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
Query: {
|
Query: {
|
||||||
related: async (parent, { title, id, cursor, limit, minMatch }, { me, models, search }) => {
|
related: async (parent, { title, id, cursor, limit, minMatch }, { me, models, search }) => {
|
||||||
const decodedCursor = decodeCursor(cursor)
|
const decodedCursor = decodeCursor(cursor)
|
||||||
if (!title || title.trim().split(/\s+/).length < 1) {
|
|
||||||
if (id) {
|
if (!id && (!title || title.trim().split(/\s+/).length < 1)) {
|
||||||
const item = await getItem(parent, { id }, { me, models })
|
|
||||||
title = item?.title
|
|
||||||
}
|
|
||||||
if (!title) {
|
|
||||||
return {
|
return {
|
||||||
items: [],
|
items: [],
|
||||||
cursor: null
|
cursor: null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const like = []
|
||||||
|
if (id) {
|
||||||
|
like.push({
|
||||||
|
_index: 'item',
|
||||||
|
_id: id
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (title) {
|
||||||
|
like.push(title)
|
||||||
}
|
}
|
||||||
|
|
||||||
const mustNot = []
|
const mustNot = []
|
||||||
@ -43,19 +50,61 @@ export default {
|
|||||||
size: limit || LIMIT,
|
size: limit || LIMIT,
|
||||||
from: decodedCursor.offset,
|
from: decodedCursor.offset,
|
||||||
body: {
|
body: {
|
||||||
|
query: {
|
||||||
|
function_score: {
|
||||||
query: {
|
query: {
|
||||||
bool: {
|
bool: {
|
||||||
must: [
|
should: [
|
||||||
{
|
{
|
||||||
more_like_this: {
|
more_like_this: {
|
||||||
fields: ['title'],
|
fields: ['title'],
|
||||||
like: title,
|
like,
|
||||||
|
min_term_freq: 1,
|
||||||
|
min_doc_freq: 1,
|
||||||
|
min_word_length: 2,
|
||||||
|
max_query_terms: 12,
|
||||||
|
minimum_should_match: minMatch || '80%',
|
||||||
|
stop_words: STOP_WORDS,
|
||||||
|
boost: 10000
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
more_like_this: {
|
||||||
|
fields: ['title'],
|
||||||
|
like,
|
||||||
|
min_term_freq: 1,
|
||||||
|
min_doc_freq: 1,
|
||||||
|
min_word_length: 2,
|
||||||
|
max_query_terms: 12,
|
||||||
|
minimum_should_match: minMatch || '60%',
|
||||||
|
stop_words: STOP_WORDS,
|
||||||
|
boost: 1000
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
more_like_this: {
|
||||||
|
fields: ['title'],
|
||||||
|
like,
|
||||||
|
min_term_freq: 1,
|
||||||
|
min_doc_freq: 1,
|
||||||
|
min_word_length: 2,
|
||||||
|
max_query_terms: 12,
|
||||||
|
minimum_should_match: minMatch || '30%',
|
||||||
|
stop_words: STOP_WORDS,
|
||||||
|
boost: 100
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
more_like_this: {
|
||||||
|
fields: ['text'],
|
||||||
|
like,
|
||||||
min_term_freq: 1,
|
min_term_freq: 1,
|
||||||
min_doc_freq: 1,
|
min_doc_freq: 1,
|
||||||
min_word_length: 2,
|
min_word_length: 2,
|
||||||
max_query_terms: 25,
|
max_query_terms: 25,
|
||||||
minimum_should_match: minMatch || '20%',
|
minimum_should_match: minMatch || '30%',
|
||||||
stop_words: STOP_WORDS
|
stop_words: STOP_WORDS,
|
||||||
|
boost: 10
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@ -65,7 +114,15 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
sort: ['_score', { wvotes: 'desc' }, { sats: 'desc' }]
|
field_value_factor: {
|
||||||
|
field: 'wvotes',
|
||||||
|
modifier: 'log1p',
|
||||||
|
factor: 1.2,
|
||||||
|
missing: 0
|
||||||
|
},
|
||||||
|
boost_mode: 'multiply'
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user