Skip to content

Commit e705d6d

Browse files
meili-bors[bot]meili-botbidoubiwabrunoocasali
authored
Merge #733
733: Changes related to the next Meilisearch release (v0.27.0) r=brunoocasali a=meili-bot This PR gathers the changes related to the next Meilisearch release (v0.27.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.27.0) is out. - the [`meilisearch-js`](https://github.com/meilisearch/meilisearch-js) dependency has been released to be compatible with Meilisearch v0.27.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/190_ Co-authored-by: meili-bot <[email protected]> Co-authored-by: cvermand <[email protected]> Co-authored-by: Bruno Casali <[email protected]>
2 parents a2c31eb + 6c7e6e6 commit e705d6d

File tree

19 files changed

+276
-313
lines changed

19 files changed

+276
-313
lines changed

.github/workflows/pre-release-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ jobs:
7575
- name: Get the latest Meilisearch RC
7676
run: echo "MEILISEARCH_VERSION=$(curl https://raw.githubusercontent.com/meilisearch/integration-guides/main/scripts/get-latest-meilisearch-rc.sh | bash)" >> $GITHUB_ENV
7777
- name: Meilisearch (${{ env.MEILISEARCH_VERSION }}) setup with Docker
78-
run: docker run -d -p 7700:7700 getmeili/meilisearch:${{ env.MEILISEARCH_VERSION }} ./meilisearch --master-key=masterKey --no-analytics
78+
run: docker run -d -p 7700:7700 getmeili/meilisearch:${{ env.MEILISEARCH_VERSION }} meilisearch --master-key=masterKey --no-analytics
7979
- name: Install dependencies
8080
run: yarn install
8181
- name: Run tests

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ jobs:
7676
./node_modules
7777
key: ${{ hashFiles('yarn.lock') }}
7878
- name: Docker setup
79-
run: docker run -d -p 7700:7700 getmeili/meilisearch:latest ./meilisearch --no-analytics --master-key='masterKey'
79+
run: docker run -d -p 7700:7700 getmeili/meilisearch:latest meilisearch --no-analytics --master-key='masterKey'
8080
- name: Install dependencies
8181
run: yarn install
8282
- name: Run tests

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Each PR should pass the tests and the linter to be accepted.
3939
```bash
4040
# Tests with Jest
4141
docker pull getmeili/meilisearch:latest # Fetch the latest version of Meilisearch image from Docker Hub
42-
docker run -p 7700:7700 getmeili/meilisearch:latest ./meilisearch --master-key=masterKey --no-analytics
42+
docker run -p 7700:7700 getmeili/meilisearch:latest meilisearch --master-key=masterKey --no-analytics
4343
# Integration tests
4444
yarn test
4545
# End-to-end tests

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ This package only guarantees the compatibility with the [version v4 of InstantSe
253253

254254
**Supported Meilisearch versions**:
255255

256-
This package only guarantees the compatibility with the [version v0.26.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.26.0).
256+
This package only guarantees the compatibility with the [version v0.27.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.27.0).
257257

258258
**Node / NPM versions**:
259259

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"url": "https://github.com/meilisearch/instant-meilisearch.git"
5858
},
5959
"dependencies": {
60-
"meilisearch": "0.25.0"
60+
"meilisearch": "0.25.1"
6161
},
6262
"devDependencies": {
6363
"@babel/cli": "^7.17.6",

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ export function adaptSearchParams(
3131
meiliSearchParams.attributesToCrop = attributesToCrop
3232
}
3333

34+
// Attributes To Crop marker
35+
const cropMarker = searchContext?.snippetEllipsisText
36+
if (cropMarker != null) {
37+
meiliSearchParams.cropMarker = cropMarker
38+
}
39+
3440
// Attributes To Retrieve
3541
const attributesToRetrieve = searchContext?.attributesToRetrieve
3642
if (attributesToRetrieve) {
@@ -57,6 +63,22 @@ export function adaptSearchParams(
5763
'*',
5864
]
5965

66+
// Highlight pre tag
67+
const highlightPreTag = searchContext?.highlightPreTag
68+
if (highlightPreTag) {
69+
meiliSearchParams.highlightPreTag = highlightPreTag
70+
} else {
71+
meiliSearchParams.highlightPreTag = '__ais-highlight__'
72+
}
73+
74+
// Highlight post tag
75+
const highlightPostTag = searchContext?.highlightPostTag
76+
if (highlightPostTag) {
77+
meiliSearchParams.highlightPostTag = highlightPostTag
78+
} else {
79+
meiliSearchParams.highlightPostTag = '__/ais-highlight__'
80+
}
81+
6082
const placeholderSearch = searchContext.placeholderSearch
6183
const query = searchContext.query
6284

src/adapter/search-response-adapter/format-adapter/format-adapter.ts

Lines changed: 62 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,75 @@
1-
import { adaptHighlight } from './highlight-adapter'
2-
import { adaptSnippet } from './snippet-adapter'
3-
import { SearchContext } from '../../../types'
1+
import { isPureObject } from '../../../utils'
42

53
/**
6-
* Adapt Meilisearch formating to formating compliant with instantsearch.js.
4+
* Stringify values following instantsearch practices.
5+
*
6+
* @param {any} value - value that needs to be stringified
7+
*/
8+
function stringifyValue(value: any) {
9+
if (typeof value === 'string') {
10+
// String
11+
return value
12+
} else if (value === undefined) {
13+
// undefined
14+
return JSON.stringify(null)
15+
} else {
16+
return JSON.stringify(value)
17+
}
18+
}
19+
20+
/**
21+
* Recursif function wrap the deepest possible value
22+
* the following way: { value: "xx" }.
23+
*
24+
* For example:
25+
*
26+
* {
27+
* "rootField": { "value": "x" }
28+
* "nestedField": { child: { value: "y" } }
29+
* }
30+
*
31+
* recursivity continues until the value is not an array or an object.
32+
*
33+
* @param {any} value - value of a field
34+
*
35+
* @returns Record<string, any>
36+
*/
37+
function wrapValue(value: any): Record<string, any> {
38+
if (Array.isArray(value)) {
39+
// Array
40+
return value.map((elem) => wrapValue(elem))
41+
} else if (isPureObject(value)) {
42+
// Object
43+
return Object.keys(value).reduce<Record<string, any>>(
44+
(nested: Record<string, any>, key: string) => {
45+
nested[key] = wrapValue(value[key])
46+
47+
return nested
48+
},
49+
{}
50+
)
51+
} else {
52+
return { value: stringifyValue(value) }
53+
}
54+
}
55+
56+
/**
57+
* Adapt Meilisearch formatted fields to a format compliant to instantsearch.js.
758
*
859
* @param {Record<string} formattedHit
960
* @param {SearchContext} searchContext
1061
* @returns {Record}
1162
*/
12-
export function adaptFormating(
13-
hit: Record<string, any>,
14-
searchContext: SearchContext
63+
export function adaptFormattedFields(
64+
hit: Record<string, any>
1565
): Record<string, any> {
16-
const attributesToSnippet = searchContext?.attributesToSnippet
17-
const ellipsis = searchContext?.snippetEllipsisText
18-
const preTag = searchContext?.highlightPreTag
19-
const postTag = searchContext?.highlightPostTag
20-
21-
if (!hit._formatted) return {}
22-
const _highlightResult = adaptHighlight(hit, preTag, postTag)
23-
24-
// what is ellipsis by default
25-
const _snippetResult = adaptHighlight(
26-
adaptSnippet(hit, attributesToSnippet, ellipsis),
27-
preTag,
28-
postTag
29-
)
66+
if (!hit) return {}
67+
const _formattedResult = wrapValue(hit)
3068

3169
const highlightedHit = {
32-
_highlightResult,
33-
_snippetResult,
70+
// We could not determine what the differences are between those two fields.
71+
_highlightResult: _formattedResult,
72+
_snippetResult: _formattedResult,
3473
}
3574

3675
return highlightedHit

src/adapter/search-response-adapter/format-adapter/highlight-adapter.ts

Lines changed: 0 additions & 76 deletions
This file was deleted.

src/adapter/search-response-adapter/format-adapter/snippet-adapter.ts

Lines changed: 0 additions & 95 deletions
This file was deleted.

src/adapter/search-response-adapter/hits-adapter.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { PaginationContext, SearchContext } from '../../types'
22
import { adaptPagination } from './pagination-adapter'
3-
import { adaptFormating } from './format-adapter'
3+
import { adaptFormattedFields } from './format-adapter'
44
import { adaptGeoResponse } from './geo-reponse-adapter'
55

66
/**
@@ -18,19 +18,23 @@ export function adaptHits(
1818
const { hitsPerPage, page } = paginationContext
1919
const paginatedHits = adaptPagination(hits, page, hitsPerPage)
2020

21-
let formattedHits = paginatedHits.map((hit: Record<string, any>) => {
21+
let adaptedHits = paginatedHits.map((hit: Record<string, any>) => {
2222
// Creates Hit object compliant with InstantSearch
2323
if (Object.keys(hit).length > 0) {
24-
const { _formatted: formattedHit, _matchesInfo, ...restOfHit } = hit
24+
const { _formatted: formattedHit, _matchesInfo, ...documentFields } = hit
2525

26-
return {
27-
...restOfHit,
28-
...adaptFormating(hit, searchContext),
29-
...(primaryKey && { objectID: hit[primaryKey] }),
26+
const adaptedHit: Record<string, any> = Object.assign(
27+
documentFields,
28+
adaptFormattedFields(formattedHit)
29+
)
30+
31+
if (primaryKey) {
32+
adaptedHit.objectID = hit[primaryKey]
3033
}
34+
return adaptedHit
3135
}
3236
return hit
3337
})
34-
formattedHits = adaptGeoResponse(formattedHits)
35-
return formattedHits
38+
adaptedHits = adaptGeoResponse(adaptedHits)
39+
return adaptedHits
3640
}

0 commit comments

Comments
 (0)