Skip to content

Commit aeea496

Browse files
feat: minimum should match parameter
1 parent 47dd4e5 commit aeea496

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export type MinimumShouldMatchParameter = {
2+
minimum_should_match?: number | string
3+
}
4+
5+
export const getMinimumShouldMatchParameter = (value: number | string): MinimumShouldMatchParameter => ({
6+
// eslint-disable-next-line camelcase
7+
minimum_should_match: value
8+
})

src/lib/parameters/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './get-minimum-should-match'

src/lib/queries/get-bool.spec.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import { faker } from '@faker-js/faker'
2+
import { getMinimumShouldMatchParameter } from 'lib/parameters'
23
import { HomeDocument, PropertyType } from 'test/module'
34
import { getBoolQuery } from './get-bool'
45
import { getRangeQuery } from './get-range'
6+
import { getShouldQuery } from './get-should'
57
import { getTermQuery } from './get-term'
68
import { getTermsQuery } from './get-terms'
79

810
describe('getBoolQuery', () => {
911
it('accepts optional must query', () => {
1012
const id = faker.string.uuid()
1113
const query = getBoolQuery<HomeDocument>({
12-
should: [
14+
...getMinimumShouldMatchParameter(1),
15+
...getShouldQuery([
1316
getTermQuery('id.keyword', id),
1417
getTermQuery('id', id),
1518
getTermsQuery('propertyType', [PropertyType.Apartment]),
@@ -22,7 +25,7 @@ describe('getBoolQuery', () => {
2225
gte: 500,
2326
lte: 1000
2427
})
25-
]
28+
])
2629
})
2730

2831
expect(query).toEqual({
@@ -41,7 +44,9 @@ describe('getBoolQuery', () => {
4144
propertyAreaSquared: { gte: 500, lte: 1000 }
4245
}
4346
}
44-
]
47+
],
48+
// eslint-disable-next-line camelcase
49+
minimum_should_match: 1
4550
}
4651
})
4752
})

src/lib/queries/get-bool.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@ import { Document } from 'lib/types'
22
import { ShouldQuery } from './get-should'
33
import { MustQuery } from './get-must'
44
import { MustNotQuery } from './get-must-not'
5+
import { MinimumShouldMatchParameter } from 'lib/parameters'
56

6-
export type BoolQueryBody<TDocument extends Document> = MustQuery<TDocument> & ShouldQuery<TDocument> & MustNotQuery<TDocument>
7+
export type BoolQueryBody<TDocument extends Document> =
8+
MustQuery<TDocument> &
9+
ShouldQuery<TDocument> &
10+
MustNotQuery<TDocument> &
11+
MinimumShouldMatchParameter
712

813
export type BoolQuery<TDocument extends Document> = {
914
bool: BoolQueryBody<TDocument> | Array<BoolQueryBody<TDocument>>

0 commit comments

Comments
 (0)