feat: allow searching by note:

This commit is contained in:
Hongbo Wu 2023-06-30 16:02:49 +08:00
parent 53b854b69f
commit 6be9afb619
2 changed files with 27 additions and 2 deletions

View file

@ -201,6 +201,19 @@ const appendMatchFilters = (
filters: FieldFilter[]
): ESBuilder => {
filters.forEach((filter) => {
if (filter.nested) {
// nested query
builder = builder.query('nested', {
path: filter.field.split('.')[0], // get the nested field name
query: {
match: {
[filter.field]: filter.value,
},
},
})
return
}
builder = builder.query('match', {
[filter.field]: filter.value,
})

View file

@ -82,6 +82,7 @@ export interface SortParams {
}
export interface FieldFilter {
nested?: boolean
field: string
value: string
}
@ -260,10 +261,19 @@ const parseFieldFilter = (
return undefined
}
let nested = false
// normalize the term to lower case
const value = str.toLowerCase()
if (field === 'note') {
field = 'highlights.annotation'
nested = true
}
return {
nested,
field,
// normalize the term to lower case
value: str.toLowerCase(),
value,
}
}
@ -343,6 +353,7 @@ export const parseSearchQuery = (query: string | undefined): SearchFilter => {
'no',
'mode',
'site',
'note',
],
tokenize: true,
})
@ -414,6 +425,7 @@ export const parseSearchQuery = (query: string | undefined): SearchFilter => {
case 'author':
case 'title':
case 'description':
case 'note':
case 'content': {
const fieldFilter = parseFieldFilter(keyword.keyword, keyword.value)
fieldFilter && result.matchFilters.push(fieldFilter)