Skip to content

Commit bc9b833

Browse files
Merge #1306
1306: instant-meilisearch: Fix _matchesPosition not being included in hits r=brunoocasali a=mavcook # Pull Request ## Related issue Fixes #1305 ## What does this PR do? Corrects _matchesPosition field not being included in each hit when meiliSearchParam.showMatchesPosition=true ### Regression This bug was introduced in PR #739, release [0.7.1](https://github.com/meilisearch/meilisearch-js-plugins/releases/tag/v0.7.1), which just seems to have been a typo/forgetting to include _matchesPosition, as you can see it was included in the destructured assignment, but not used. ## PR checklist Please check if your PR fulfills the following requirements: - [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [x] Have you read the contributing guidelines? - [x] Have you made sure that the title is accurate and descriptive of the changes? Co-authored-by: mavcook <[email protected]>
2 parents c4230d9 + 114aece commit bc9b833

File tree

3 files changed

+213
-0
lines changed

3 files changed

+213
-0
lines changed

.changeset/sharp-ways-argue.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+
Fix \_matchesPosition not being included in hits
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
import { adaptHits } from '../hits-adapter'
2+
3+
const searchResponsePositionMatchesFalse = {
4+
indexUid: 'steam-video-games',
5+
hits: [
6+
{
7+
name: 'Half-Life: Opposing Force',
8+
description:
9+
'Return to the Black Mesa Research Facility as one of the military specialists assigned to eliminate Gordon Freeman. Experience an entirely new episode of single player action. Meet fierce alien opponents and experiment with new weaponry. Named Game of the Year by the Academy of Interactive Arts and Sciences.',
10+
id: '50',
11+
price: '4.99 $',
12+
image:
13+
'http://steam.meilisearch.dev/steam/apps/50/header.jpg?t=1447350813',
14+
releaseDate: 'Nov 1 1999',
15+
recommendationCount: 2934,
16+
platforms: ['MacOS', 'Linux', 'Windows'],
17+
players: ['Single player', 'Multiplayer'],
18+
genres: ['Action'],
19+
misc: [],
20+
_formatted: {
21+
name: '__ais-highlight__Half__/ais-highlight__-Life: Opposing Force',
22+
description:
23+
'Return to the Black Mesa Research Facility as one of the military specialists assigned to eliminate Gordon Freeman. Experience an entirely new episode of single player action. Meet fierce alien opponents and experiment with new weaponry. Named Game of the Year by the Academy of Interactive Arts and Sciences.',
24+
id: '50',
25+
price: '4.99 $',
26+
image:
27+
'http://steam.meilisearch.dev/steam/apps/50/header.jpg?t=1447350813',
28+
releaseDate: 'Nov 1 1999',
29+
recommendationCount: '2934',
30+
platforms: ['MacOS', 'Linux', 'Windows'],
31+
players: ['Single player', 'Multiplayer'],
32+
genres: ['Action'],
33+
misc: [],
34+
},
35+
},
36+
],
37+
query: 'half',
38+
processingTimeMs: 2,
39+
hitsPerPage: 6,
40+
page: 1,
41+
totalPages: 39,
42+
totalHits: 232,
43+
facetDistribution: {
44+
genres: {
45+
Action: 118,
46+
Adventure: 76,
47+
Casual: 39,
48+
RPG: 44,
49+
Racing: 2,
50+
Simulation: 35,
51+
Sports: 10,
52+
Strategy: 47,
53+
},
54+
misc: {
55+
'Early access': 33,
56+
'Free to play': 20,
57+
'VR support': 11,
58+
},
59+
platforms: {
60+
Linux: 68,
61+
MacOS: 96,
62+
Windows: 232,
63+
},
64+
players: {
65+
Coop: 32,
66+
MMO: 5,
67+
Multiplayer: 76,
68+
'Single player': 206,
69+
},
70+
},
71+
facetStats: {},
72+
pagination: {
73+
hitsPerPage: 6,
74+
page: 0,
75+
finite: true,
76+
},
77+
}
78+
79+
const searchResponsePositionMatchesTrue = {
80+
indexUid: 'steam-video-games',
81+
hits: [
82+
{
83+
name: 'Half-Life: Opposing Force',
84+
description:
85+
'Return to the Black Mesa Research Facility as one of the military specialists assigned to eliminate Gordon Freeman. Experience an entirely new episode of single player action. Meet fierce alien opponents and experiment with new weaponry. Named Game of the Year by the Academy of Interactive Arts and Sciences.',
86+
id: '50',
87+
price: '4.99 $',
88+
image:
89+
'http://steam.meilisearch.dev/steam/apps/50/header.jpg?t=1447350813',
90+
releaseDate: 'Nov 1 1999',
91+
recommendationCount: 2934,
92+
platforms: ['MacOS', 'Linux', 'Windows'],
93+
players: ['Single player', 'Multiplayer'],
94+
genres: ['Action'],
95+
misc: [],
96+
_formatted: {
97+
name: '__ais-highlight__Half__/ais-highlight__-Life: Opposing Force',
98+
description:
99+
'Return to the Black Mesa Research Facility as one of the military specialists assigned to eliminate Gordon Freeman. Experience an entirely new episode of single player action. Meet fierce alien opponents and experiment with new weaponry. Named Game of the Year by the Academy of Interactive Arts and Sciences.',
100+
id: '50',
101+
price: '4.99 $',
102+
image:
103+
'http://steam.meilisearch.dev/steam/apps/50/header.jpg?t=1447350813',
104+
releaseDate: 'Nov 1 1999',
105+
recommendationCount: '2934',
106+
platforms: ['MacOS', 'Linux', 'Windows'],
107+
players: ['Single player', 'Multiplayer'],
108+
genres: ['Action'],
109+
misc: [],
110+
},
111+
_matchesPosition: {
112+
name: [
113+
{
114+
start: 0,
115+
length: 4,
116+
},
117+
],
118+
},
119+
},
120+
],
121+
query: 'half',
122+
processingTimeMs: 2,
123+
hitsPerPage: 6,
124+
page: 1,
125+
totalPages: 39,
126+
totalHits: 232,
127+
facetDistribution: {
128+
genres: {
129+
Action: 118,
130+
Adventure: 76,
131+
Casual: 39,
132+
RPG: 44,
133+
Racing: 2,
134+
Simulation: 35,
135+
Sports: 10,
136+
Strategy: 47,
137+
},
138+
misc: {
139+
'Early access': 33,
140+
'Free to play': 20,
141+
'VR support': 11,
142+
},
143+
platforms: {
144+
Linux: 68,
145+
MacOS: 96,
146+
Windows: 232,
147+
},
148+
players: {
149+
Coop: 32,
150+
MMO: 5,
151+
Multiplayer: 76,
152+
'Single player': 206,
153+
},
154+
},
155+
facetStats: {},
156+
pagination: {
157+
hitsPerPage: 6,
158+
page: 0,
159+
finite: true,
160+
},
161+
}
162+
163+
describe('Hit adapter', () => {
164+
test('_matchesPosition should be created in hit object with meiliSearchParams.showMatchesPosition=true', () => {
165+
const expectedPositionMatch = {
166+
name: [
167+
{
168+
start: 0,
169+
length: 4,
170+
},
171+
],
172+
}
173+
174+
const config = {
175+
placeholderSearch: true,
176+
keepZeroFacets: false,
177+
clientAgents: [],
178+
finitePagination: true,
179+
meiliSearchParams: {
180+
showMatchesPosition: true,
181+
},
182+
}
183+
184+
const adaptedHits = adaptHits(searchResponsePositionMatchesTrue, config)
185+
186+
expect(adaptedHits[0]._matchesPosition).toEqual(expectedPositionMatch)
187+
})
188+
189+
test('_matchesPosition should NOT be created in hit object with meiliSearchParams.showMatchesPosition=false', () => {
190+
const config = {
191+
placeholderSearch: true,
192+
keepZeroFacets: false,
193+
clientAgents: [],
194+
finitePagination: true,
195+
meiliSearchParams: {
196+
showMatchesPosition: false,
197+
},
198+
}
199+
200+
const adaptedHits = adaptHits(searchResponsePositionMatchesFalse, config)
201+
202+
expect(adaptedHits[0]).not.toHaveProperty('_matchesPosition')
203+
})
204+
})

packages/instant-meilisearch/src/adapter/search-response-adapter/hits-adapter.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ export function adaptHits(
4242
adaptFormattedFields(formattedHit)
4343
)
4444

45+
if (config?.meiliSearchParams?.showMatchesPosition) {
46+
adaptedHit._matchesPosition = _matchesPosition
47+
}
48+
4549
if (primaryKey) {
4650
adaptedHit.objectID = hit[primaryKey]
4751
}

0 commit comments

Comments
 (0)