Skip to content

Commit ecef2e8

Browse files
meili-bors[bot]meili-botbidoubiwa
authored
Merge #831
831: Changes related to the next Meilisearch release (v0.29.0) r=bidoubiwa a=meili-bot This PR gathers the changes related to the next Meilisearch release (v0.29.0) so that this package is ready when the official release is out. ⚠️ This PR should NOT be merged until: - the next release of Meilisearch (v0.29.0) is out. - the [`meilisearch-js`](https://github.com/meilisearch/meilisearch-js) dependency has been released to be compatible with Meilisearch v0.29.0. Once the release is out, the upgrade of the `meilisearch-js` dependency might be committed to this branch. _This PR is auto-generated for the [pre-release week](https://github.com/meilisearch/integration-guides/blob/master/guides/pre-release-week.md) purpose._ _Related to this issue: https://github.com/meilisearch/integration-guides/issues/211_ Co-authored-by: meili-bot <[email protected]> Co-authored-by: Charlotte Vermandel <[email protected]> Co-authored-by: cvermand <[email protected]>
2 parents 6578853 + 0284ae0 commit ecef2e8

File tree

8 files changed

+49
-20
lines changed

8 files changed

+49
-20
lines changed

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ const searchClient = instantMeiliSearch(
8383
- [`finitePagination`](#finite-pagination): Used to work with the [`pagination`](#-pagination) widget (default: `false`) .
8484
- [`primaryKey`](#primary-key): Specify the primary key of your documents (default `undefined`).
8585
- [`keepZeroFacets`](#keep-zero-facets): Show the facets value even when they have 0 matches (default `false`).
86+
- [`matchingStrategy`](#matching-strategy): Determine the search strategy on words matching (default `last`).
8687

8788
The options are added as the third parameter of the `instantMeilisearch` function.
8889

@@ -170,6 +171,20 @@ genres:
170171
{ keepZeroFacets : true } // default: false
171172
```
172173

174+
### Matching strategy
175+
176+
`matchingStrategy` gives you the possibility to choose how Meilisearch should handle the presence of multiple query words, see [documentation](https://docs.meilisearch.com/reference/api/search.html#matching-strategy).
177+
178+
For example, if your query is `hello world` by default Meilisearch returns documents containing either both `hello` and `world` or documents that only contain `hello`. This is the `last` strategy, where words are stripped from the right.
179+
The other strategy is `all`, where both `hello` and `world` **must** be present in a document for it to be returned.
180+
181+
182+
```js
183+
{
184+
matchingStrategy: 'all' // default last
185+
}
186+
```
187+
173188
## 🪡 Example with InstantSearch
174189

175190
The open-source [InstantSearch](https://www.algolia.com/doc/api-reference/widgets/js/) library powered by Algolia provides all the front-end tools you need to highly customize your search bar environment.
@@ -253,7 +268,7 @@ This package only guarantees the compatibility with the [version v4 of InstantSe
253268

254269
**Supported Meilisearch versions**:
255270

256-
This package only guarantees the compatibility with the [version v0.28.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.28.0).
271+
This package only guarantees the compatibility with the [version v0.29.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.29.0).
257272

258273
**Node / NPM versions**:
259274

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@meilisearch/instant-meilisearch",
3-
"version": "0.8.2",
3+
"version": "0.9.0",
44
"private": false,
55
"description": "The search client to use Meilisearch with InstantSearch.",
66
"scripts": {
@@ -57,7 +57,7 @@
5757
"url": "https://github.com/meilisearch/instant-meilisearch.git"
5858
},
5959
"dependencies": {
60-
"meilisearch": "^0.27.0"
60+
"meilisearch": "^0.28.0"
6161
},
6262
"devDependencies": {
6363
"@babel/cli": "^7.18.10",

src/adapter/search-request-adapter/__tests__/search-params.tests.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import { adaptSearchParams } from '../search-params-adapter'
2+
import { MatchingStrategies } from '../../../types'
23

34
const DEFAULT_CONTEXT = {
45
indexUid: 'test',
56
pagination: { paginationTotalHits: 20, page: 0, hitsPerPage: 6 },
67
defaultFacetDistribution: {},
8+
finitePagination: false,
79
}
810

911
describe('Parameters adapter', () => {
1012
test('adapting a basic searchContext ', () => {
1113
const searchParams = adaptSearchParams({
1214
...DEFAULT_CONTEXT,
13-
finitePagination: false,
1415
})
1516

1617
expect(searchParams.attributesToHighlight).toContain('*')
@@ -22,7 +23,6 @@ describe('Parameters adapter', () => {
2223
...DEFAULT_CONTEXT,
2324
facetFilters: [['genres:Drama', 'genres:Thriller'], ['title:Ariel']],
2425
sort: 'id < 1',
25-
finitePagination: false,
2626
})
2727

2828
expect(searchParams.filter).toStrictEqual([
@@ -33,6 +33,15 @@ describe('Parameters adapter', () => {
3333
expect(searchParams.attributesToHighlight).toContain('*')
3434
expect(searchParams.attributesToHighlight?.length).toBe(1)
3535
})
36+
37+
test('adapting a searchContext with matching strategy', () => {
38+
const searchParams = adaptSearchParams({
39+
...DEFAULT_CONTEXT,
40+
matchingStrategy: MatchingStrategies.ALL,
41+
})
42+
43+
expect(searchParams.matchingStrategy).toEqual('all')
44+
})
3645
})
3746

3847
describe('Geo rules adapter', () => {
@@ -42,7 +51,6 @@ describe('Geo rules adapter', () => {
4251
facetFilters: [['genres:Drama', 'genres:Thriller'], ['title:Ariel']],
4352
insideBoundingBox: '0,0,0,0',
4453
sort: 'id < 1',
45-
finitePagination: false,
4654
})
4755

4856
expect(searchParams.filter).toStrictEqual([
@@ -60,7 +68,6 @@ describe('Geo rules adapter', () => {
6068
...DEFAULT_CONTEXT,
6169
facetFilters: [['genres:Drama', 'genres:Thriller'], ['title:Ariel']],
6270
insideBoundingBox: '0,0,0,0',
63-
finitePagination: false,
6471
})
6572

6673
expect(searchParams.filter).toEqual([
@@ -77,7 +84,6 @@ describe('Geo rules adapter', () => {
7784
...DEFAULT_CONTEXT,
7885
insideBoundingBox: '0,0,0,0',
7986
sort: 'id < 1',
80-
finitePagination: false,
8187
})
8288

8389
expect(searchParams.filter).toEqual(['_geoRadius(0.00000, 0.00000, 0)'])
@@ -90,7 +96,6 @@ describe('Geo rules adapter', () => {
9096
const searchParams = adaptSearchParams({
9197
...DEFAULT_CONTEXT,
9298
insideBoundingBox: '0,0,0,0',
93-
finitePagination: false,
9499
})
95100

96101
expect(searchParams.filter).toEqual(['_geoRadius(0.00000, 0.00000, 0)'])
@@ -132,7 +137,6 @@ describe('Pagination adapter', () => {
132137
test('adapting a searchContext with no finite pagination', () => {
133138
const searchParams = adaptSearchParams({
134139
...DEFAULT_CONTEXT,
135-
finitePagination: false,
136140
})
137141

138142
expect(searchParams.limit).toBe(7)
@@ -142,7 +146,6 @@ describe('Pagination adapter', () => {
142146
const searchParams = adaptSearchParams({
143147
...DEFAULT_CONTEXT,
144148
pagination: { paginationTotalHits: 20, page: 1, hitsPerPage: 6 },
145-
finitePagination: false,
146149
})
147150

148151
expect(searchParams.limit).toBe(13)
@@ -152,7 +155,6 @@ describe('Pagination adapter', () => {
152155
const searchParams = adaptSearchParams({
153156
...DEFAULT_CONTEXT,
154157
pagination: { paginationTotalHits: 20, page: 40, hitsPerPage: 6 },
155-
finitePagination: false,
156158
})
157159

158160
expect(searchParams.limit).toBe(20)
@@ -162,7 +164,6 @@ describe('Pagination adapter', () => {
162164
const searchParams = adaptSearchParams({
163165
...DEFAULT_CONTEXT,
164166
pagination: { paginationTotalHits: 4, page: 0, hitsPerPage: 6 },
165-
finitePagination: false,
166167
})
167168

168169
expect(searchParams.limit).toBe(4)
@@ -173,7 +174,6 @@ describe('Pagination adapter', () => {
173174
...DEFAULT_CONTEXT,
174175
query: '',
175176
pagination: { paginationTotalHits: 4, page: 0, hitsPerPage: 6 },
176-
finitePagination: false,
177177
placeholderSearch: false,
178178
})
179179

@@ -185,7 +185,6 @@ describe('Pagination adapter', () => {
185185
...DEFAULT_CONTEXT,
186186
query: '',
187187
pagination: { paginationTotalHits: 200, page: 0, hitsPerPage: 6 },
188-
finitePagination: false,
189188
placeholderSearch: true,
190189
})
191190

src/adapter/search-request-adapter/search-params-adapter.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export function MeiliParamsCreator(searchContext: SearchContext) {
3232
finitePagination,
3333
sort,
3434
pagination,
35+
matchingStrategy,
3536
} = searchContext
3637

3738
return {
@@ -119,6 +120,11 @@ export function MeiliParamsCreator(searchContext: SearchContext) {
119120
}
120121
}
121122
},
123+
addMatchingStrategy() {
124+
if (matchingStrategy) {
125+
meiliSearchParams.matchingStrategy = matchingStrategy
126+
}
127+
},
122128
}
123129
}
124130

@@ -144,6 +150,7 @@ export function adaptSearchParams(
144150
meilisearchParams.addFilters()
145151
meilisearchParams.addSort()
146152
meilisearchParams.addGeoSearchRules()
153+
meilisearchParams.addMatchingStrategy()
147154

148155
return meilisearchParams.getParams()
149156
}

src/contexts/search-context.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
AlgoliaMultipleQueriesQuery,
44
SearchContext,
55
FacetDistribution,
6+
MatchingStrategies,
67
} from '../types'
78

89
import { createPaginationContext } from './pagination-context'

src/package-version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const PACKAGE_VERSION = '0.8.2'
1+
export const PACKAGE_VERSION = '0.9.0'

src/types/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,19 @@ export type ParsedFilter = {
2727
value: string
2828
}
2929

30+
export const enum MatchingStrategies {
31+
ALL = 'all',
32+
LAST = 'last',
33+
}
34+
3035
export type InstantMeiliSearchOptions = {
3136
paginationTotalHits?: number
3237
placeholderSearch?: boolean
3338
primaryKey?: string
3439
keepZeroFacets?: boolean
3540
finitePagination?: boolean
3641
clientAgents?: string[]
42+
matchingStrategy?: MatchingStrategies
3743
}
3844

3945
export type SearchCacheInterface = {
@@ -79,6 +85,7 @@ export type SearchContext = Omit<InstantSearchParams, 'insideBoundingBox'> &
7985
sort?: string
8086
placeholderSearch?: boolean
8187
primaryKey?: string
88+
matchingStrategy?: MatchingStrategies
8289
}
8390

8491
export type InstantMeiliSearchInstance = SearchClient & {

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5206,10 +5206,10 @@ [email protected]:
52065206
resolved "https://registry.yarnpkg.com/mdn-data/-/mdn-data-2.0.4.tgz#699b3c38ac6f1d728091a64650b65d388502fd5b"
52075207
integrity sha512-iV3XNKw06j5Q7mi6h+9vbx23Tv7JkjEVgKHW4pimwyDGWm0OIQntJJ+u1C6mg6mK1EaTv42XQ7w76yuzH7M2cA==
52085208

5209-
meilisearch@^0.27.0:
5210-
version "0.27.0"
5211-
resolved "https://registry.yarnpkg.com/meilisearch/-/meilisearch-0.27.0.tgz#8bd57ddb77b975f93e054cb977b951c488ece297"
5212-
integrity sha512-kZOZFIuSO7c6xRf+Y2/9/h6A9pl0sCl/G44X4KuaSwxGbruOZPhmxbeVEgLHBv4pUFvQ56rNVTA/2d/5GCU1YA==
5209+
meilisearch@^0.28.0:
5210+
version "0.28.0"
5211+
resolved "https://registry.yarnpkg.com/meilisearch/-/meilisearch-0.28.0.tgz#650f08a56ef0a989a41d13233f7a744cfa7f54df"
5212+
integrity sha512-zC50xLyPWBtfAIZiFTSJyYJp/a5bO+dSSigBKUEoShFkuv9+/KC4J3T3ZejNVHXG2DU0ohOMf8TZ3HAHXNd3EA==
52135213
dependencies:
52145214
cross-fetch "^3.1.5"
52155215

0 commit comments

Comments
 (0)