reintroduce searching by most recent

This commit is contained in:
keyan 2023-11-13 18:17:45 -06:00
parent 84b5475270
commit 7b58edb77b
2 changed files with 69 additions and 51 deletions

View File

@ -177,23 +177,7 @@ export default {
whatArr.push({ match: { 'sub.name': sub } }) whatArr.push({ match: { 'sub.name': sub } })
} }
let sortField const should = [
switch (sort) {
case 'comments':
sortField = 'ncomments'
break
case 'sats':
sortField = 'sats'
break
default:
sortField = 'wvotes'
break
}
if (query.length) {
whatArr.push({
bool: {
should: [
{ {
// all terms are matched in fields // all terms are matched in fields
multi_match: { multi_match: {
@ -213,8 +197,44 @@ export default {
minimum_should_match: '60%', minimum_should_match: '60%',
boost: 1000 boost: 1000
} }
}, }
]
let boostMode = 'multiply'
let sortField
let sortMod = 'log1p'
switch (sort) {
case 'comments':
sortField = 'ncomments'
sortMod = 'square'
break
case 'sats':
sortField = 'sats'
break
case 'recent':
sortField = 'createdAt'
sortMod = 'square'
boostMode = 'replace'
break
default:
sortField = 'wvotes'
sortMod = 'none'
break
}
const functions = [
{ {
field_value_factor: {
field: sortField,
modifier: sortMod,
factor: 1.2
}
}
]
// allow fuzzy matching for single terms
if (sort !== 'recent') {
should.push({
// only some terms must match unless we're sorting // only some terms must match unless we're sorting
multi_match: { multi_match: {
query, query,
@ -224,8 +244,21 @@ export default {
prefix_length: 3, prefix_length: 3,
minimum_should_match: '60%' minimum_should_match: '60%'
} }
})
// small bias toward posts with comments
functions.push({
field_value_factor: {
field: 'ncomments',
modifier: 'ln1p',
factor: 1
} }
] })
}
if (query.length) {
whatArr.push({
bool: {
should
} }
}) })
} }
@ -282,23 +315,8 @@ export default {
] ]
} }
}, },
functions: [ functions,
{ boost_mode: boostMode
field_value_factor: {
field: sortField,
modifier: sort === 'comments' ? 'square' : 'log2p',
factor: 1.2
}
},
{
field_value_factor: {
field: 'ncomments',
modifier: 'ln1p',
factor: 1
}
}
],
boost_mode: 'multiply'
} }
}, },
highlight: { highlight: {

View File

@ -97,7 +97,7 @@ export default function Search ({ sub }) {
name='sort' name='sort'
size='sm' size='sm'
overrideValue={sort} overrideValue={sort}
items={['zaprank', 'comments', 'sats']} items={['zaprank', 'recent', 'comments', 'sats']}
/> />
for for
<Select <Select