Skip to content

Commit d506846

Browse files
authored
Add crop marker support (#738)
* Fix tests related to changes in Meilisearch * Update tests based on placeholder search resolution * Add crop marker support
1 parent 7c49bda commit d506846

File tree

9 files changed

+167
-199
lines changed

9 files changed

+167
-199
lines changed

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.26.0-beta.0"
6161
},
6262
"devDependencies": {
6363
"@babel/cli": "^7.17.6",

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

Lines changed: 6 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) {

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

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { adaptHighlight } from './highlight-adapter'
2-
import { adaptSnippet } from './snippet-adapter'
32
import { SearchContext } from '../../../types'
43

54
/**
@@ -13,24 +12,16 @@ export function adaptFormating(
1312
hit: Record<string, any>,
1413
searchContext: SearchContext
1514
): Record<string, any> {
16-
const attributesToSnippet = searchContext?.attributesToSnippet
17-
const ellipsis = searchContext?.snippetEllipsisText
1815
const preTag = searchContext?.highlightPreTag
1916
const postTag = searchContext?.highlightPostTag
2017

2118
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-
)
19+
const _formattedResult = adaptHighlight(hit, preTag, postTag)
3020

3121
const highlightedHit = {
32-
_highlightResult,
33-
_snippetResult,
22+
// We could not determine what the differences are between those two fields.
23+
_highlightResult: _formattedResult,
24+
_snippetResult: _formattedResult,
3425
}
3526

3627
return highlightedHit

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

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

src/types/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export type SearchContext = Omit<
8181
> & {
8282
insideBoundingBox?: InsideBoundingBox
8383
keepZeroFacets?: boolean
84+
cropMarker?: string
8485
defaultFacetDistribution: FacetsDistribution
8586
pagination: PaginationContext
8687
}

tests/assets/utils.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ const dataset = [
1313
undefinedArray: [undefined, undefined, undefined],
1414
nullArray: [null, null, null],
1515
objectArray: [
16-
{ name: 'charlotte' },
17-
{ name: 'charlotte' },
18-
{ name: 'charlotte' },
16+
{ name: 'hello world' },
17+
{ name: 'hello world' },
18+
{ name: 'hello world' },
1919
],
2020
object: {
2121
id: 1,
22-
name: 'Nader',
22+
name: 'One two',
2323
},
2424
nullField: null,
2525
},
@@ -34,13 +34,13 @@ const dataset = [
3434
undefinedArray: [undefined, undefined, undefined],
3535
nullArray: [null, null, null],
3636
objectArray: [
37-
{ name: 'charlotte' },
38-
{ name: 'charlotte' },
39-
{ name: 'charlotte' },
37+
{ name: 'hello world' },
38+
{ name: 'hello world' },
39+
{ name: 'hello world' },
4040
],
4141
object: {
4242
id: 1,
43-
name: 'Nader',
43+
name: 'One two',
4444
},
4545
nullField: null,
4646
},
@@ -55,13 +55,13 @@ const dataset = [
5555
undefinedArray: [undefined, undefined, undefined],
5656
nullArray: [null, null, null],
5757
objectArray: [
58-
{ name: 'charlotte' },
59-
{ name: 'charlotte' },
60-
{ name: 'charlotte' },
58+
{ name: 'hello world' },
59+
{ name: 'hello world' },
60+
{ name: 'hello world' },
6161
],
6262
object: {
6363
id: 1,
64-
name: 'Nader',
64+
name: 'One two',
6565
},
6666
nullField: null,
6767
},

tests/highlight.tests.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,14 +261,14 @@ describe('Highlight Browser test', () => {
261261

262262
if (hit?.objectArray) {
263263
// @ts-ignore
264-
expect(hit?.objectArray[0]?.value).toEqual('{"name":"charlotte"}')
264+
expect(hit?.objectArray[0]?.value).toEqual('{"name":"hello world"}')
265265
// @ts-ignore
266-
expect(hit?.objectArray[1]?.value).toEqual('{"name":"charlotte"}')
266+
expect(hit?.objectArray[1]?.value).toEqual('{"name":"hello world"}')
267267
}
268268

269269
if (hit?.object) {
270270
// @ts-ignore
271-
expect(hit?.object?.value).toEqual('{"id":"1","name":"Nader"}')
271+
expect(hit?.object?.value).toEqual('{"id":"1","name":"One two"}')
272272
}
273273

274274
if (hit?.nullField) {

0 commit comments

Comments
 (0)