dramatically improve search
This commit is contained in:
parent
7cb3a7ad64
commit
3499f92436
@ -1,4 +1,3 @@
|
|||||||
import { ITEM_FILTER_THRESHOLD } from '../../lib/constants'
|
|
||||||
import { decodeCursor, LIMIT, nextCursorEncoded } from '../../lib/cursor'
|
import { decodeCursor, LIMIT, nextCursorEncoded } from '../../lib/cursor'
|
||||||
import { whenToFrom } from '../../lib/time'
|
import { whenToFrom } from '../../lib/time'
|
||||||
import { getItem } from './item'
|
import { getItem } from './item'
|
||||||
@ -121,27 +120,16 @@ export default {
|
|||||||
whatArr.push({ match: { 'sub.name': sub } })
|
whatArr.push({ match: { 'sub.name': sub } })
|
||||||
}
|
}
|
||||||
|
|
||||||
const sortArr = []
|
let sortField
|
||||||
switch (sort) {
|
switch (sort) {
|
||||||
case 'recent':
|
|
||||||
sortArr.push({ createdAt: 'desc' })
|
|
||||||
sortArr.push('_score')
|
|
||||||
break
|
|
||||||
case 'comments':
|
case 'comments':
|
||||||
sortArr.push({ ncomments: 'desc' })
|
sortField = 'ncomments'
|
||||||
sortArr.push('_score')
|
|
||||||
break
|
break
|
||||||
case 'sats':
|
case 'sats':
|
||||||
sortArr.push({ sats: 'desc' })
|
sortField = 'sats'
|
||||||
sortArr.push('_score')
|
|
||||||
break
|
|
||||||
case 'match':
|
|
||||||
sortArr.push('_score')
|
|
||||||
sortArr.push({ wvotes: 'desc' })
|
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
sortArr.push({ wvotes: 'desc' })
|
sortField = 'wvotes'
|
||||||
sortArr.push('_score')
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,21 +142,21 @@ export default {
|
|||||||
multi_match: {
|
multi_match: {
|
||||||
query,
|
query,
|
||||||
type: 'most_fields',
|
type: 'most_fields',
|
||||||
fields: ['title^100', 'text'],
|
fields: ['title^1000', 'text'],
|
||||||
minimum_should_match: '100%',
|
minimum_should_match: '100%',
|
||||||
boost: 400
|
boost: 1000
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// all terms are matched in fields
|
// all terms are matched in fields fuzzily
|
||||||
multi_match: {
|
multi_match: {
|
||||||
query,
|
query,
|
||||||
type: 'most_fields',
|
type: 'most_fields',
|
||||||
fields: ['title^100', 'text'],
|
fields: ['title^1000', 'text'],
|
||||||
fuzziness: 'AUTO',
|
fuzziness: 'AUTO',
|
||||||
prefix_length: 3,
|
prefix_length: 3,
|
||||||
minimum_should_match: '100%',
|
minimum_should_match: '100%',
|
||||||
boost: 20
|
boost: 10
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -176,10 +164,10 @@ export default {
|
|||||||
multi_match: {
|
multi_match: {
|
||||||
query,
|
query,
|
||||||
type: 'most_fields',
|
type: 'most_fields',
|
||||||
fields: ['title^100', 'text'],
|
fields: ['title^1000', 'text'],
|
||||||
fuzziness: 'AUTO',
|
fuzziness: 'AUTO',
|
||||||
prefix_length: 3,
|
prefix_length: 3,
|
||||||
minimum_should_match: sortArr.length > 1 ? '100%' : '60%'
|
minimum_should_match: '60%'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@ -204,40 +192,49 @@ export default {
|
|||||||
from: decodedCursor.offset,
|
from: decodedCursor.offset,
|
||||||
body: {
|
body: {
|
||||||
query: {
|
query: {
|
||||||
bool: {
|
function_score: {
|
||||||
must: [
|
query: {
|
||||||
...whatArr,
|
bool: {
|
||||||
me
|
must: [
|
||||||
? {
|
...whatArr,
|
||||||
bool: {
|
me
|
||||||
should: [
|
? {
|
||||||
{ match: { status: 'ACTIVE' } },
|
bool: {
|
||||||
{ match: { status: 'NOSATS' } },
|
should: [
|
||||||
{ match: { userId: me.id } }
|
{ match: { status: 'ACTIVE' } },
|
||||||
]
|
{ match: { status: 'NOSATS' } },
|
||||||
|
{ match: { userId: me.id } }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
bool: {
|
||||||
|
should: [
|
||||||
|
{ match: { status: 'ACTIVE' } },
|
||||||
|
{ match: { status: 'NOSATS' } }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
filter: [
|
||||||
|
{
|
||||||
|
range:
|
||||||
|
{
|
||||||
|
createdAt: whenRange
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
: {
|
{ range: { wvotes: { gte: 0 } } }
|
||||||
bool: {
|
]
|
||||||
should: [
|
}
|
||||||
{ match: { status: 'ACTIVE' } },
|
},
|
||||||
{ match: { status: 'NOSATS' } }
|
field_value_factor: {
|
||||||
]
|
field: sortField,
|
||||||
}
|
modifier: sort === 'comments' ? 'square' : 'log2p',
|
||||||
}
|
factor: 1.2
|
||||||
],
|
},
|
||||||
filter: [
|
boost_mode: 'multiply'
|
||||||
{
|
|
||||||
range:
|
|
||||||
{
|
|
||||||
createdAt: whenRange
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{ range: { wvotes: { gt: -1 * ITEM_FILTER_THRESHOLD } } }
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
sort: sortArr,
|
|
||||||
highlight: {
|
highlight: {
|
||||||
fields: {
|
fields: {
|
||||||
title: { number_of_fragments: 0, pre_tags: ['***'], post_tags: ['***'] },
|
title: { number_of_fragments: 0, pre_tags: ['***'], post_tags: ['***'] },
|
||||||
|
@ -97,7 +97,7 @@ export default function Search ({ sub }) {
|
|||||||
name='sort'
|
name='sort'
|
||||||
size='sm'
|
size='sm'
|
||||||
overrideValue={sort}
|
overrideValue={sort}
|
||||||
items={['zaprank', 'match', 'recent', 'comments', 'sats']}
|
items={['zaprank', 'comments', 'sats']}
|
||||||
/>
|
/>
|
||||||
for
|
for
|
||||||
<Select
|
<Select
|
||||||
|
Loading…
x
Reference in New Issue
Block a user