add url and nym search
This commit is contained in:
parent
79af550168
commit
032c04959a
@ -7,6 +7,31 @@ export default {
|
|||||||
const decodedCursor = decodeCursor(cursor)
|
const decodedCursor = decodeCursor(cursor)
|
||||||
let sitems
|
let sitems
|
||||||
|
|
||||||
|
const whatArr = []
|
||||||
|
switch (what) {
|
||||||
|
case 'posts':
|
||||||
|
whatArr.push({ bool: { must_not: { exists: { field: 'parentId' } } } })
|
||||||
|
break
|
||||||
|
case 'comments':
|
||||||
|
whatArr.push({ bool: { must: { exists: { field: 'parentId' } } } })
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
const queryArr = query.trim().split(/\s+/)
|
||||||
|
const url = queryArr.find(word => word.startsWith('url:'))
|
||||||
|
const nym = queryArr.find(word => word.startsWith('nym:'))
|
||||||
|
query = queryArr.filter(word => !word.startsWith('url:') && !word.startsWith('nym:')).join(' ')
|
||||||
|
|
||||||
|
if (url) {
|
||||||
|
whatArr.push({ wildcard: { url: `*${url.slice(4).toLowerCase()}*` } })
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nym) {
|
||||||
|
whatArr.push({ wildcard: { 'user.name': `*${nym.slice(4).toLowerCase()}*` } })
|
||||||
|
}
|
||||||
|
|
||||||
const sortArr = []
|
const sortArr = []
|
||||||
switch (sort) {
|
switch (sort) {
|
||||||
case 'recent':
|
case 'recent':
|
||||||
@ -26,16 +51,46 @@ export default {
|
|||||||
}
|
}
|
||||||
sortArr.push('_score')
|
sortArr.push('_score')
|
||||||
|
|
||||||
const whatArr = []
|
if (query.length) {
|
||||||
switch (what) {
|
whatArr.push({
|
||||||
case 'posts':
|
bool: {
|
||||||
whatArr.push({ bool: { must_not: { exists: { field: 'parentId' } } } })
|
should: [
|
||||||
break
|
{
|
||||||
case 'comments':
|
// all terms are matched in fields
|
||||||
whatArr.push({ bool: { must: { exists: { field: 'parentId' } } } })
|
multi_match: {
|
||||||
break
|
query,
|
||||||
default:
|
type: 'most_fields',
|
||||||
break
|
fields: ['title^20', 'text'],
|
||||||
|
minimum_should_match: '100%',
|
||||||
|
boost: 400
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// all terms are matched in fields
|
||||||
|
multi_match: {
|
||||||
|
query,
|
||||||
|
type: 'most_fields',
|
||||||
|
fields: ['title^20', 'text'],
|
||||||
|
fuzziness: 'AUTO',
|
||||||
|
prefix_length: 3,
|
||||||
|
minimum_should_match: '100%',
|
||||||
|
boost: 20
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// only some terms must match unless we're sorting
|
||||||
|
multi_match: {
|
||||||
|
query,
|
||||||
|
type: 'most_fields',
|
||||||
|
fields: ['title^20', 'text'],
|
||||||
|
fuzziness: 'AUTO',
|
||||||
|
prefix_length: 3,
|
||||||
|
minimum_should_match: sortArr.length > 1 ? '100%' : '60%'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
let whenGte
|
let whenGte
|
||||||
@ -86,47 +141,6 @@ export default {
|
|||||||
{ match: { status: 'NOSATS' } }
|
{ match: { status: 'NOSATS' } }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
|
||||||
{
|
|
||||||
bool: {
|
|
||||||
should: [
|
|
||||||
{
|
|
||||||
// all terms are matched in fields
|
|
||||||
multi_match: {
|
|
||||||
query,
|
|
||||||
type: 'most_fields',
|
|
||||||
fields: ['title^20', 'text'],
|
|
||||||
minimum_should_match: '100%',
|
|
||||||
boost: 400
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// all terms are matched in fields
|
|
||||||
multi_match: {
|
|
||||||
query,
|
|
||||||
type: 'most_fields',
|
|
||||||
fields: ['title^20', 'text'],
|
|
||||||
fuzziness: 'AUTO',
|
|
||||||
prefix_length: 3,
|
|
||||||
minimum_should_match: '100%',
|
|
||||||
boost: 20
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// only some terms must match unless we're sorting
|
|
||||||
multi_match: {
|
|
||||||
query,
|
|
||||||
type: 'most_fields',
|
|
||||||
fields: ['title^20', 'text'],
|
|
||||||
fuzziness: 'AUTO',
|
|
||||||
prefix_length: 3,
|
|
||||||
minimum_should_match: sortArr.length > 1 ? '100%' : '60%'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// TODO: add wildcard matches for
|
|
||||||
// user.name and url
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
filter: {
|
filter: {
|
||||||
@ -161,8 +175,8 @@ export default {
|
|||||||
// this is super inefficient but will suffice until we do something more generic
|
// this is super inefficient but will suffice until we do something more generic
|
||||||
const item = await getItem(parent, { id: e._source.id }, { me, models })
|
const item = await getItem(parent, { id: e._source.id }, { me, models })
|
||||||
|
|
||||||
item.searchTitle = (e.highlight.title && e.highlight.title[0]) || item.title
|
item.searchTitle = (e.highlight?.title && e.highlight.title[0]) || item.title
|
||||||
item.searchText = (e.highlight.text && e.highlight.text[0]) || item.text
|
item.searchText = (e.highlight?.text && e.highlight.text[0]) || item.text
|
||||||
|
|
||||||
return item
|
return item
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user