Skip to content

Commit 8bb47f6

Browse files
meili-bors[bot]meili-botbidoubiwa
authored
Merge #1188
1188: Changes related to the next Meilisearch release (v0.27.0) r=curquiza a=meili-bot Related to this issue: meilisearch/integration-guides#190 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. - 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 v0.27.0 is out. ⚠️ This PR should NOT be merged until the next release of Meilisearch (v0.27.0) is out. _This PR is auto-generated for the [pre-release week](https://github.com/meilisearch/integration-guides/blob/master/guides/pre-release-week.md) purpose._ Co-authored-by: meili-bot <[email protected]> Co-authored-by: Charlotte Vermandel <[email protected]> Co-authored-by: cvermand <[email protected]>
2 parents c8539a2 + e5efa2b commit 8bb47f6

12 files changed

+769
-60
lines changed

.code-samples.meilisearch.yaml

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,15 @@ update_settings_1: |-
113113
synonyms: {
114114
'wolverine': ['xmen', 'logan'],
115115
'logan': ['wolverine']
116+
},
117+
typoTolerance: {
118+
'minWordSizeForTypos': {
119+
'oneTypo': 8,
120+
'twoTypos': 10
121+
},
122+
'disableOnAttributes': [
123+
'title'
124+
]
116125
}
117126
})
118127
reset_settings_1: |-
@@ -175,6 +184,20 @@ update_displayed_attributes_1: |-
175184
])
176185
reset_displayed_attributes_1: |-
177186
client.index('movies').resetDisplayedAttributes()
187+
get_typo_tolerance_1: |-
188+
client.index('books').getTypoTolerance()
189+
update_typo_tolerance_1: |-
190+
client.index('books').updateTypoTolerance({
191+
minWordSizeForTypos: {
192+
oneTypo: 4,
193+
twoTypos: 10
194+
},
195+
disableOnAttributes: [
196+
'title'
197+
]
198+
})
199+
reset_typo_tolerance_1: |-
200+
client.index('books').resetTypoTolerance()
178201
get_index_stats_1: |-
179202
client.index('movies').getStats()
180203
get_indexes_stats_1: |-
@@ -231,12 +254,23 @@ search_parameter_guide_retrieve_1: |-
231254
search_parameter_guide_crop_1: |-
232255
client.index('movies').search('shifu', {
233256
attributesToCrop: ['overview'],
234-
cropLength: 10
257+
cropLength: 5
258+
})
259+
search_parameter_guide_crop_marker_1: |-
260+
client.index('movies').search('shifu', {
261+
attributesToCrop: ['overview'],
262+
cropMarker: '[…]'
235263
})
236264
search_parameter_guide_highlight_1: |-
237265
client.index('movies').search('winter feast', {
238266
attributesToHighlight: ['overview']
239267
})
268+
search_parameter_guide_highlight_tag_1: |-
269+
client.index('movies').search('winter feast', {
270+
attributesToHighlight: ['overview'],
271+
highlightPreTag: '<span class="highlight">',
272+
highlightPostTag: '</span>'
273+
})
240274
search_parameter_guide_matches_1: |-
241275
client.index('movies').search('winter feast', {
242276
matches: true
@@ -296,6 +330,34 @@ settings_guide_sortable_1: |-
296330
'price'
297331
]
298332
})
333+
settings_guide_typo_tolerance_1: |-
334+
client.index('movies').updateTypoTolerance({
335+
minWordSizeForTypos: {
336+
twoTypos: 12
337+
},
338+
disableOnAttributes: [
339+
'title'
340+
]
341+
})
342+
typo_tolerance_guide_1: |-
343+
client.index('movies').updateTypoTolerance({
344+
enabled: false
345+
})
346+
typo_tolerance_guide_2: |-
347+
client.index('movies').updateTypoTolerance({
348+
disableOnAttributes: ['title']
349+
})
350+
typo_tolerance_guide_3: |-
351+
client.index('movies').updateTypoTolerance({
352+
disableOnWords: ['shrek']
353+
})
354+
typo_tolerance_guide_4: |-
355+
client.index('movies').updateTypoTolerance({
356+
minWordSizeForTypos: {
357+
oneTypo: 4,
358+
twoTypos: 10
359+
}
360+
})
299361
add_movies_json_1: |-
300362
const movies = require('./movies.json')
301363
client.index('movies').addDocuments(movies).then((res) => console.log(res))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
- name: Get the latest Meilisearch RC
3535
run: echo "MEILISEARCH_VERSION=$(curl https://raw.githubusercontent.com/meilisearch/integration-guides/main/scripts/get-latest-meilisearch-rc.sh | bash)" >> $GITHUB_ENV
3636
- name: Meilisearch (${{ env.MEILISEARCH_VERSION }}) setup with Docker
37-
run: docker run -d -p 7700:7700 getmeili/meilisearch:${{ env.MEILISEARCH_VERSION }} ./meilisearch --master-key=masterKey --no-analytics
37+
run: docker run -d -p 7700:7700 getmeili/meilisearch:${{ env.MEILISEARCH_VERSION }} meilisearch --master-key=masterKey --no-analytics
3838
- name: Run tests
3939
run: yarn test
4040
- name: Build project

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
- name: Install dependencies
3838
run: yarn --dev
3939
- name: Meilisearch (latest) setup with Docker
40-
run: docker run -d -p 7700:7700 getmeili/meilisearch:latest ./meilisearch --no-analytics --master-key='masterKey'
40+
run: docker run -d -p 7700:7700 getmeili/meilisearch:latest meilisearch --no-analytics --master-key='masterKey'
4141
- name: Run tests
4242
run: yarn test
4343
- name: Build project

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ controller.abort()
342342

343343
## 🤖 Compatibility with Meilisearch
344344

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

347347
## 💡 Learn More
348348

@@ -605,6 +605,17 @@ Using the index object:
605605
- [Reset Sortable Attributes](https://docs.meilisearch.com/reference/api/sortable_attributes.html#reset-sortable-attributes):
606606
`index.resetSortableAttributes(): Promise<EnqueuedTask>`
607607

608+
### Typo Tolerance <!-- omit in toc -->
609+
610+
- [Get Typo Tolerance](https://docs.meilisearch.com/reference/api/typo_tolerance.html#get-typo-tolerance):
611+
`index.getTypoTolerance(): Promise<TypoTolerance>`
612+
613+
- [Update Typo Tolerance](https://docs.meilisearch.com/reference/api/typo_tolerance.html#update-typo-tolerance):
614+
`index.updateTypoTolerance(typoTolerance: TypoTolerance | null): Promise<EnqueuedTask>`
615+
616+
- [Reset Typo Tolerance](https://docs.meilisearch.com/reference/api/typo_tolerance.html#reset-typo-tolerance):
617+
`index.resetTypoTolerance(): Promise<EnqueuedTask>`
618+
608619
### Keys <!-- omit in toc -->
609620

610621
- [Get keys](https://docs.meilisearch.com/reference/api/keys.html#get-all-keys):

src/lib/indexes.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
SortableAttributes,
3434
SearchableAttributes,
3535
DisplayedAttributes,
36+
TypoTolerance,
3637
Result,
3738
} from '../types'
3839
import { removeUndefinedFromObject } from './utils'
@@ -812,6 +813,46 @@ class Index<T = Record<string, any>> {
812813
const url = `indexes/${this.uid}/settings/displayed-attributes`
813814
return await this.httpRequest.delete<EnqueuedTask>(url)
814815
}
816+
817+
///
818+
/// TYPO TOLERANCE
819+
///
820+
821+
/**
822+
* Get the typo tolerance settings.
823+
* @memberof Index
824+
* @method getTypoTolerance
825+
* @returns {Promise<string[]>} Promise containing the typo tolerance settings.
826+
*/
827+
async getTypoTolerance(): Promise<string[]> {
828+
const url = `indexes/${this.uid}/settings/typo-tolerance`
829+
return await this.httpRequest.get<string[]>(url)
830+
}
831+
832+
/**
833+
* Update the typo tolerance settings.
834+
* @memberof Index
835+
* @method updateTypoTolerance
836+
* @param {TypoTolerance} typoTolerance Object containing the custom typo tolerance settings.
837+
* @returns {Promise<EnqueuedTask>} Promise containing object of the enqueued update
838+
*/
839+
async updateTypoTolerance(
840+
typoTolerance: TypoTolerance
841+
): Promise<EnqueuedTask> {
842+
const url = `indexes/${this.uid}/settings/typo-tolerance`
843+
return await this.httpRequest.post(url, typoTolerance)
844+
}
845+
846+
/**
847+
* Reset the typo tolerance settings.
848+
* @memberof Index
849+
* @method resetTypoTolerance
850+
* @returns {Promise<EnqueuedTask>} Promise containing object of the enqueued update
851+
*/
852+
async resetTypoTolerance(): Promise<EnqueuedTask> {
853+
const url = `indexes/${this.uid}/settings/typo-tolerance`
854+
return await this.httpRequest.delete<EnqueuedTask>(url)
855+
}
815856
}
816857

817858
export { Index }

src/types/types.ts

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ export type AddDocumentParams = {
3939
primaryKey?: string
4040
}
4141

42+
/*
43+
* SEARCH PARAMETERS
44+
*/
45+
4246
export type Filter = string | Array<string | string[]>
4347

4448
export type Pagination = {
@@ -50,30 +54,42 @@ export type Query = {
5054
q?: string | null
5155
}
5256

53-
export type SearchParams = Pagination & {
54-
filter?: Filter
55-
sort?: string[]
56-
facetsDistribution?: string[]
57-
attributesToRetrieve?: string[]
57+
export type Highlight = {
5858
attributesToHighlight?: string[]
59+
highlightPreTag?: string
60+
highlightPostTag?: string
61+
}
62+
63+
export type Crop = {
5964
attributesToCrop?: string[]
6065
cropLength?: number
61-
matches?: boolean
66+
cropMarker?: string
6267
}
6368

69+
export type SearchParams = Pagination &
70+
Highlight &
71+
Crop & {
72+
filter?: Filter
73+
sort?: string[]
74+
facetsDistribution?: string[]
75+
attributesToRetrieve?: string[]
76+
matches?: boolean
77+
}
78+
6479
export type SearchRequest = SearchParams & Query
6580

6681
// Search parameters for searches made with the GET method
6782
// Are different than the parameters for the POST method
6883
export type SearchRequestGET = Pagination &
69-
Query & {
84+
Query &
85+
Omit<Highlight, 'attributesToHighlight'> &
86+
Omit<Crop, 'attributesToCrop'> & {
7087
filter?: string
7188
sort?: string
7289
facetsDistribution?: string
7390
attributesToRetrieve?: string
7491
attributesToHighlight?: string
7592
attributesToCrop?: string
76-
cropLength?: number
7793
matches?: boolean
7894
}
7995

@@ -143,6 +159,15 @@ export type StopWords = string[] | null
143159
export type Synonyms = {
144160
[field: string]: string[]
145161
} | null
162+
export type TypoTolerance = {
163+
enabled?: boolean | null
164+
disabledOnAttributes?: string[] | null
165+
disableOnWords?: string[] | null
166+
minWordSizeForTypos?: {
167+
oneTypo?: number | null
168+
twoTypos?: number | null
169+
}
170+
} | null
146171

147172
export type Settings = {
148173
filterableAttributes?: FilterableAttributes
@@ -153,6 +178,7 @@ export type Settings = {
153178
rankingRules?: RankingRules
154179
stopWords?: StopWords
155180
synonyms?: Synonyms
181+
typoTolerance?: TypoTolerance
156182
}
157183

158184
/*

tests/get_search_tests.ts

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,52 @@ describe.each([
225225
expect(response.hits[0]).toHaveProperty('_formatted', expect.any(Object))
226226
expect(response.hits[0]._formatted).toHaveProperty(
227227
'title',
228-
'Petit <em>Prince</em>'
228+
'Le Petit <em>Prince</em>'
229229
)
230230
expect(response.hits[0]).toHaveProperty('_matchesInfo', expect.any(Object))
231231
})
232232

233+
test(`${permission} key: search on default cropping parameters`, async () => {
234+
const client = await getClient(permission)
235+
const response = await client.index(index.uid).searchGet('prince', {
236+
attributesToCrop: ['*'],
237+
cropLength: 6,
238+
})
239+
240+
expect(response.hits[0]._formatted).toHaveProperty(
241+
'comment',
242+
'…book about a prince that walks…'
243+
)
244+
})
245+
246+
test(`${permission} key: search on customized cropMarker`, async () => {
247+
const client = await getClient(permission)
248+
const response = await client.index(index.uid).searchGet('prince', {
249+
attributesToCrop: ['*'],
250+
cropLength: 6,
251+
cropMarker: '(ꈍᴗꈍ)',
252+
})
253+
254+
expect(response.hits[0]._formatted).toHaveProperty(
255+
'comment',
256+
'(ꈍᴗꈍ)book about a prince that walks(ꈍᴗꈍ)'
257+
)
258+
})
259+
260+
test(`${permission} key: search on customized highlight tags`, async () => {
261+
const client = await getClient(permission)
262+
const response = await client.index(index.uid).searchGet('prince', {
263+
attributesToHighlight: ['*'],
264+
highlightPreTag: '(⊃。•́‿•̀。)⊃ ',
265+
highlightPostTag: ' ⊂(´• ω •`⊂)',
266+
})
267+
268+
expect(response.hits[0]._formatted).toHaveProperty(
269+
'comment',
270+
'A french book about a (⊃。•́‿•̀。)⊃ prince ⊂(´• ω •`⊂) that walks on little cute planets'
271+
)
272+
})
273+
233274
test(`${permission} key: search with all options and all fields`, async () => {
234275
const client = await getClient(permission)
235276
const response = await client.index(index.uid).searchGet('prince', {
@@ -251,7 +292,7 @@ describe.each([
251292
expect(response.hits[0]).toHaveProperty('_formatted', expect.any(Object))
252293
expect(response.hits[0]._formatted).toHaveProperty(
253294
'title',
254-
'Petit <em>Prince</em>'
295+
'Le Petit <em>Prince</em>'
255296
)
256297
expect(response.hits[0]).toHaveProperty('_matchesInfo', expect.any(Object))
257298
})
@@ -284,7 +325,7 @@ describe.each([
284325
)
285326
expect(response.hits[0]._formatted).toHaveProperty(
286327
'title',
287-
'Petit <em>Prince</em>'
328+
'Le Petit <em>Prince</em>'
288329
)
289330
expect(response.hits[0]._formatted).not.toHaveProperty('comment')
290331
expect(response.hits[0]).toHaveProperty('_matchesInfo', expect.any(Object))

0 commit comments

Comments
 (0)