mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Update search query
This commit is contained in:
parent
a04bfbb83e
commit
195074fa49
1 changed files with 31 additions and 35 deletions
|
|
@ -164,39 +164,37 @@ export const searchHighlights = async (
|
|||
|
||||
const searchBody = {
|
||||
query: {
|
||||
nested: {
|
||||
path: 'highlights',
|
||||
query: {
|
||||
bool: {
|
||||
filter: [
|
||||
{
|
||||
bool: {
|
||||
filter: [
|
||||
{
|
||||
nested: {
|
||||
path: 'highlights',
|
||||
query: {
|
||||
term: {
|
||||
'highlights.userId': userId,
|
||||
},
|
||||
},
|
||||
],
|
||||
should: [
|
||||
{
|
||||
multi_match: {
|
||||
query: query || '',
|
||||
fields: [
|
||||
'highlights.quote^5',
|
||||
'title^3',
|
||||
'description^2',
|
||||
'content',
|
||||
],
|
||||
operator: 'and',
|
||||
type: 'cross_fields',
|
||||
},
|
||||
},
|
||||
],
|
||||
minimum_should_match: query ? 1 : 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
inner_hits: {},
|
||||
],
|
||||
should: [
|
||||
{
|
||||
multi_match: {
|
||||
query: query || '',
|
||||
fields: [
|
||||
'highlights.quote^5',
|
||||
'title^3',
|
||||
'description^2',
|
||||
'content',
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
minimum_should_match: query ? 1 : 0,
|
||||
},
|
||||
},
|
||||
sort: [
|
||||
'_score',
|
||||
{
|
||||
[sortField]: {
|
||||
order: sortOrder,
|
||||
|
|
@ -208,7 +206,7 @@ export const searchHighlights = async (
|
|||
],
|
||||
from,
|
||||
size,
|
||||
_source: ['title', 'slug', 'url', 'createdAt'],
|
||||
_source: ['title', 'slug', 'url', 'createdAt', 'highlights'],
|
||||
}
|
||||
|
||||
console.log('searching highlights in elastic', JSON.stringify(searchBody))
|
||||
|
|
@ -225,15 +223,13 @@ export const searchHighlights = async (
|
|||
const results: SearchItem[] = []
|
||||
response.body.hits.hits.forEach((hit) => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
||||
hit.inner_hits.highlights.hits.hits.forEach(
|
||||
(innerHit: { _source: Highlight }) => {
|
||||
results.push({
|
||||
...hit._source,
|
||||
...innerHit._source,
|
||||
pageId: hit._id,
|
||||
})
|
||||
}
|
||||
)
|
||||
hit._source.highlights?.forEach((highlight) => {
|
||||
results.push({
|
||||
...highlight,
|
||||
...hit._source,
|
||||
pageId: hit._id,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
return [results, response.body.hits.total.value]
|
||||
|
|
|
|||
Loading…
Reference in a new issue