mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Merge pull request #2093 from omnivore-app/feature/nested-labels
Allow wildcards in label: filter
This commit is contained in:
commit
c3a7615d90
1 changed files with 34 additions and 3 deletions
|
|
@ -27,10 +27,24 @@ import {
|
|||
} from './types'
|
||||
|
||||
const appendQuery = (builder: ESBuilder, query: string): ESBuilder => {
|
||||
const fields = ['title', 'content', 'author', 'description', 'siteName']
|
||||
if (query.includes('*')) {
|
||||
// wildcard query
|
||||
fields.forEach((field) => {
|
||||
builder = builder.orQuery('wildcard', {
|
||||
[field]: {
|
||||
value: query,
|
||||
case_insensitive: true,
|
||||
},
|
||||
})
|
||||
})
|
||||
return builder.queryMinimumShouldMatch(1)
|
||||
}
|
||||
|
||||
return builder
|
||||
.orQuery('multi_match', {
|
||||
query,
|
||||
fields: ['title', 'content', 'author', 'description', 'siteName'],
|
||||
fields,
|
||||
operator: 'and',
|
||||
type: 'cross_fields',
|
||||
})
|
||||
|
|
@ -119,8 +133,25 @@ const appendIncludeLabelFilter = (
|
|||
builder = builder.query('nested', {
|
||||
path: 'labels',
|
||||
query: {
|
||||
terms: {
|
||||
'labels.name': filter.labels,
|
||||
bool: {
|
||||
should: filter.labels.map((label) => {
|
||||
if (label.includes('*')) {
|
||||
// Wildcard query
|
||||
return {
|
||||
wildcard: {
|
||||
'labels.name': {
|
||||
value: label,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
return {
|
||||
term: {
|
||||
'labels.name': label,
|
||||
},
|
||||
}
|
||||
}),
|
||||
minimum_should_match: 1,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue