Skip to content

Commit 2d8296a

Browse files
meili-bors[bot]meili-botbidoubiwa
authored
Merge #1030
1030: Changes related to the next Meilisearch release (v1.1.0) r=bidoubiwa a=meili-bot Related to this issue: meilisearch/integration-guides#251 This PR: - gathers the changes related to the next Meilisearch release (v1.1.0) so that this package is ready when the official release is out. - should pass the tests against the [latest pre-release of Meilisearch](https://github.com/meilisearch/meilisearch/releases). - might eventually contain test failures until the Meilisearch v1.1.0 is out. ⚠️ This PR should NOT be merged until the next release of Meilisearch (v1.1.0) is out. _This PR is auto-generated for the [pre-release week](https://github.com/meilisearch/integration-guides/blob/main/resources/pre-release-week.md) purpose._ Co-authored-by: meili-bot <[email protected]> Co-authored-by: cvermand <[email protected]> Co-authored-by: Charlotte Vermandel <[email protected]>
2 parents 1bd7e3e + c4abafb commit 2d8296a

31 files changed

+612
-526
lines changed

.changeset/fresh-countries-move.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@meilisearch/instant-meilisearch": minor
3+
---
4+
5+
Replaces search with multiSearch API.

.changeset/small-masks-tease.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@meilisearch/instant-meilisearch": patch
3+
---
4+
5+
Use the `_geoBoundingBox` filter to adapt the `insideBoundingBox`parameter

.changeset/stupid-mirrors-itch.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@meilisearch/instant-meilisearch": patch
3+
---
4+
5+
Add the facetStats of numeric facets, giving access to the min and max value of these facets.
6+
The following widgets are now compatible with Meilisearch: `RangeSlider` and `RangeInput`

README.md

Lines changed: 3 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,6 @@ const search = instantsearch({
350350

351351
`Index` is the component that lets you apply widgets to a dedicated index. It’s useful if you want to build an interface that targets multiple indices.
352352

353-
Using this component, instant-meilisearch does an http-request for each different `Index` widget added. More http requests are made when using the [`RefinementList`](#✅-refinementlist) widget.
354-
355353
### ✅ SearchBox
356354

357355
[SearchBox references](https://www.algolia.com/doc/api-reference/widgets/search-box/js/)
@@ -675,9 +673,6 @@ The `refinementList` widget is one of the most common widgets you can find in a
675673
- ✅ templates: The templates to use for the widget.
676674
- ✅ cssClasses: The CSS classes to override.
677675

678-
The `RefinementList` widget uses the `disjunctive facet search` principle when using the `or` operator. For each different facet category used, an additional http call is made.
679-
For example, if I ask for `color=green` and `size=2`, three http requests are made. One for the hits, one for the `color` facet distribution, and one for the `size` facet distribution. To provide feedback on the subject, refer to [this discussion](https://github.com/meilisearch/product/issues/54).
680-
681676
The following example will create a UI component with the a list of genres on which you will be able to facet.
682677

683678
```js
@@ -746,54 +741,14 @@ The `rangeSlider` widget provides a user-friendly way to filter the results, bas
746741
- ✅ attribute: The name of the attribute in the document. _required_.
747742
- ✅ min: The minimum value for the input. _required_
748743
- ✅ max: The maximum value for the input. _required_
749-
- precision: The number of digits after the decimal point to use. Not compatible as only integers work with `rangeSlider`.
744+
- precision: The number of digits after the decimal point to use. Not compatible as only integers work with `rangeSlider`.
750745
- ✅ step: The number of steps between each handle move.
751746
- ✅ pips: Whether to show slider pips (ruler marks).
752747
- ✅ tooltips: Whether to show tooltips. The default tooltips show the raw value.
753748
- ✅ cssClasses: The CSS classes to override.
754749

755-
#### ⚠️ The component is compatible but only by applying the following requirements:
756-
757-
#### 1. Manual Min Max
758-
759-
Min and max of attributes are not returned from Meilisearch and thus **must be set manually**.
760-
761-
```js
762-
instantsearch.widgets.rangeSlider({
763-
// ...
764-
min: 0,
765-
max: 100000,
766-
}),
767-
```
768-
769-
#### 2. Attribute must be in `filterableAttributes`
770-
771-
If the attribute is not in the [`filterableAttributes`](https://docs.meilisearch.com/reference/features/filtering_and_faceted_search.html#configuring-filters) setting list, filtering on this attribute is not possible.
772-
773-
Example:
774-
Given the attribute `id` that has not been added in `filterableAttributes`:
775-
776-
```js
777-
instantsearch.widgets.rangeSlider({
778-
attribute: 'id',
779-
// ...
780-
}),
781-
```
782-
783-
The widget throws the following error:
784-
785-
```json
786-
{
787-
"message": " .. attribute `id` is not filterable, available filterable attributes are: author, price, genres",
788-
"errorCode": "bad_request",
789-
"errorType": "invalid_request_error",
790-
"errorLink": "https://docs.meilisearch.com/errors#bad_request"
791-
}
792-
```
793-
794-
To avoid this error, the attribute must be added to the [`filterableAttributes` setting](https://docs.meilisearch.com/reference/api/filterable_attributes.html#get-filterable-attributes).
750+
To be able to use the `rangeSlider` on an attribute, the attribute must be in the[`filterableAttributes`](https://docs.meilisearch.com/reference/features/filtering_and_faceted_search.html#configuring-filters) and must contain numeric values.
795751

796-
After these steps, `rangeSlider` becomes compatible.
797752

798753
### ✅ Menu
799754

@@ -837,7 +792,7 @@ The `rangeInput` widget allows a user to select a numeric range using a minimum
837792
- ✅ templates: The templates to use for the widget.
838793
- ✅ cssClasses: The CSS classes to override.
839794

840-
⚠️ Not compatible with Meilisearch by default, needs a workaround. See workaround in [RangeSlider](#-rangeslider) section.
795+
To be able to use the `RangeInput` on an attribute, the attribute must be in the[`filterableAttributes`](https://docs.meilisearch.com/reference/features/filtering_and_faceted_search.html#configuring-filters) and must contain numeric values.
841796

842797
### ✅ MenuSelect
843798

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { searchClient, dataset, meilisearchClient } from './assets/utils'
2+
3+
describe('Facet stats tests', () => {
4+
beforeAll(async () => {
5+
const deleteTask = await meilisearchClient.deleteIndex('movies')
6+
await meilisearchClient.waitForTask(deleteTask.taskUid)
7+
await meilisearchClient
8+
.index('movies')
9+
.updateFilterableAttributes(['genres', 'release_date', 'id'])
10+
const documentsTask = await meilisearchClient
11+
.index('movies')
12+
.addDocuments(dataset)
13+
await meilisearchClient.index('movies').waitForTask(documentsTask.taskUid)
14+
})
15+
16+
test('Facet stats on an empty facets array', async () => {
17+
const response = await searchClient.search([
18+
{
19+
indexName: 'movies',
20+
params: {
21+
query: '',
22+
facets: [],
23+
},
24+
},
25+
])
26+
27+
expect(response.results[0].facets_stats?.release_date).toEqual(undefined)
28+
})
29+
30+
test('Facet stats on a facet with no numeric values', async () => {
31+
const response = await searchClient.search([
32+
{
33+
indexName: 'movies',
34+
params: {
35+
query: '',
36+
facets: ['genres'],
37+
},
38+
},
39+
])
40+
41+
expect(response.results[0].facets_stats?.genres).toEqual(undefined)
42+
})
43+
44+
test('Facet stats on two facet', async () => {
45+
const response = await searchClient.search([
46+
{
47+
indexName: 'movies',
48+
params: {
49+
query: '',
50+
facets: ['release_date', 'id'],
51+
},
52+
},
53+
])
54+
55+
expect(response.results[0].facets_stats?.release_date).toEqual({
56+
avg: 0,
57+
max: 1065744000,
58+
min: 233366400,
59+
sum: 0,
60+
})
61+
expect(response.results[0].facets_stats?.id).toEqual({
62+
avg: 0,
63+
max: 30,
64+
min: 2,
65+
sum: 0,
66+
})
67+
})
68+
})

packages/instant-meilisearch/__tests__/geosearch.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe('Instant Meilisearch Browser test', () => {
5151
])
5252

5353
const hits = response.results[0].hits
54-
expect(hits.length).toEqual(7)
54+
expect(hits.length).toEqual(5)
5555
expect(hits[0].city).toEqual('Lille')
5656
})
5757

@@ -68,8 +68,8 @@ describe('Instant Meilisearch Browser test', () => {
6868
])
6969

7070
const hits = response.results[0].hits
71-
expect(hits.length).toEqual(4)
72-
expect(hits[0].city).toEqual('Ghent')
71+
expect(hits.length).toEqual(2)
72+
expect(hits[0].city).toEqual('Brussels')
7373
})
7474

7575
test('insideBoundingBox and aroundRadius in geo search', async () => {
@@ -86,8 +86,8 @@ describe('Instant Meilisearch Browser test', () => {
8686
])
8787

8888
const hits = response.results[0].hits
89-
expect(hits.length).toEqual(4)
90-
expect(hits[0].city).toEqual('Ghent')
89+
expect(hits.length).toEqual(2)
90+
expect(hits[0].city).toEqual('Brussels')
9191
})
9292

9393
test('insideBoundingBox and aroundLatLng in geo search', async () => {
@@ -104,7 +104,7 @@ describe('Instant Meilisearch Browser test', () => {
104104
])
105105

106106
const hits = response.results[0].hits
107-
expect(hits.length).toEqual(4)
108-
expect(hits[0].city).toEqual('Ghent')
107+
expect(hits.length).toEqual(2)
108+
expect(hits[0].city).toEqual('Brussels')
109109
})
110110
})

packages/instant-meilisearch/__tests__/search-resolver.test.ts

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { instantMeiliSearch } from '../src'
33
import { MeiliSearch } from 'meilisearch'
44
import { mocked } from 'ts-jest/utils'
55
import { PACKAGE_VERSION } from '../src/package-version'
6+
import { MeiliSearchMultiSearchParams } from '../src/types'
67

78
jest.mock('meilisearch')
89

@@ -18,19 +19,22 @@ export const searchResponse = {
1819

1920
// Mocking of Meilisearch package
2021
const mockedMeilisearch = mocked(MeiliSearch, true)
21-
const mockedSearch = jest.fn(() => searchResponse)
22-
const mockedIndex = jest.fn(() => {
22+
const mockedMultiSearch = jest.fn((request) => {
23+
const response = request.queries.map((req: MeiliSearchMultiSearchParams) => ({
24+
...searchResponse,
25+
indexUid: req.indexUid,
26+
}))
2327
return {
24-
search: mockedSearch,
28+
results: response,
2529
}
2630
})
2731

2832
mockedMeilisearch.mockReturnValue({
2933
// @ts-ignore
30-
index: mockedIndex,
34+
multiSearch: mockedMultiSearch,
3135
})
3236

33-
describe('Pagination browser test', () => {
37+
describe('Cached search tests', () => {
3438
afterEach(() => {
3539
jest.clearAllMocks()
3640
})
@@ -51,7 +55,7 @@ describe('Pagination browser test', () => {
5155
apiKey: '',
5256
clientAgents: [`Meilisearch instant-meilisearch (v${PACKAGE_VERSION})`],
5357
})
54-
expect(mockedSearch).toHaveBeenCalledTimes(2)
58+
expect(mockedMultiSearch).toHaveBeenCalledTimes(2)
5559
})
5660

5761
test('two different search parameters', async () => {
@@ -77,7 +81,7 @@ describe('Pagination browser test', () => {
7781
apiKey: '',
7882
clientAgents: [`Meilisearch instant-meilisearch (v${PACKAGE_VERSION})`],
7983
})
80-
expect(mockedSearch).toHaveBeenCalledTimes(3)
84+
expect(mockedMultiSearch).toHaveBeenCalledTimes(3)
8185
})
8286

8387
test('two identical and one different search parameters', async () => {
@@ -104,7 +108,7 @@ describe('Pagination browser test', () => {
104108
apiKey: '',
105109
clientAgents: [`Meilisearch instant-meilisearch (v${PACKAGE_VERSION})`],
106110
})
107-
expect(mockedSearch).toHaveBeenCalledTimes(3)
111+
expect(mockedMultiSearch).toHaveBeenCalledTimes(3)
108112
})
109113

110114
test('two same and two different search parameter', async () => {
@@ -132,6 +136,43 @@ describe('Pagination browser test', () => {
132136
apiKey: '',
133137
clientAgents: [`Meilisearch instant-meilisearch (v${PACKAGE_VERSION})`],
134138
})
135-
expect(mockedSearch).toHaveBeenCalledTimes(3)
139+
expect(mockedMultiSearch).toHaveBeenCalledTimes(3)
140+
})
141+
142+
test('Multiple search parameters on different index uids', async () => {
143+
const searchParameters1 = [
144+
{
145+
indexName: 'movies',
146+
params: {
147+
query: '',
148+
},
149+
},
150+
{
151+
indexName: 'game',
152+
params: {
153+
query: '',
154+
},
155+
},
156+
]
157+
158+
const searchParameters2 = {
159+
indexName: 'movies',
160+
params: {
161+
query: 'other query',
162+
},
163+
}
164+
const searchClient = instantMeiliSearch('http://localhost:7700')
165+
await searchClient.search<Movies>(searchParameters1)
166+
await searchClient.search<Movies>([searchParameters2])
167+
await searchClient.search<Movies>(searchParameters1)
168+
await searchClient.search<Movies>([searchParameters2])
169+
170+
expect(mockedMeilisearch).toHaveBeenCalledWith({
171+
host: 'http://localhost:7700',
172+
apiKey: '',
173+
clientAgents: [`Meilisearch instant-meilisearch (v${PACKAGE_VERSION})`],
174+
})
175+
176+
expect(mockedMultiSearch).toHaveBeenCalledTimes(3)
136177
})
137178
})

packages/instant-meilisearch/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"templates"
4848
],
4949
"dependencies": {
50-
"meilisearch": "^0.31.1"
50+
"meilisearch": "^0.32.1"
5151
},
5252
"devDependencies": {
5353
"@babel/cli": "^7.21.0",

0 commit comments

Comments
 (0)