-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
instant-meilisearch: Fix _matchesPosition not being included in hits #1306
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@meilisearch/instant-meilisearch": patch | ||
--- | ||
|
||
Fix \_matchesPosition not being included in hits |
204 changes: 204 additions & 0 deletions
204
...ges/instant-meilisearch/src/adapter/search-response-adapter/__tests__/hit-adapter.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
import { adaptHits } from '../hits-adapter' | ||
|
||
const searchResponsePositionMatchesFalse = { | ||
indexUid: 'steam-video-games', | ||
hits: [ | ||
{ | ||
name: 'Half-Life: Opposing Force', | ||
description: | ||
'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.', | ||
id: '50', | ||
price: '4.99 $', | ||
image: | ||
'http://steam.meilisearch.dev/steam/apps/50/header.jpg?t=1447350813', | ||
releaseDate: 'Nov 1 1999', | ||
recommendationCount: 2934, | ||
platforms: ['MacOS', 'Linux', 'Windows'], | ||
players: ['Single player', 'Multiplayer'], | ||
genres: ['Action'], | ||
misc: [], | ||
_formatted: { | ||
name: '__ais-highlight__Half__/ais-highlight__-Life: Opposing Force', | ||
description: | ||
'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.', | ||
id: '50', | ||
price: '4.99 $', | ||
image: | ||
'http://steam.meilisearch.dev/steam/apps/50/header.jpg?t=1447350813', | ||
releaseDate: 'Nov 1 1999', | ||
recommendationCount: '2934', | ||
platforms: ['MacOS', 'Linux', 'Windows'], | ||
players: ['Single player', 'Multiplayer'], | ||
genres: ['Action'], | ||
misc: [], | ||
}, | ||
}, | ||
], | ||
query: 'half', | ||
processingTimeMs: 2, | ||
hitsPerPage: 6, | ||
page: 1, | ||
totalPages: 39, | ||
totalHits: 232, | ||
facetDistribution: { | ||
genres: { | ||
Action: 118, | ||
Adventure: 76, | ||
Casual: 39, | ||
RPG: 44, | ||
Racing: 2, | ||
Simulation: 35, | ||
Sports: 10, | ||
Strategy: 47, | ||
}, | ||
misc: { | ||
'Early access': 33, | ||
'Free to play': 20, | ||
'VR support': 11, | ||
}, | ||
platforms: { | ||
Linux: 68, | ||
MacOS: 96, | ||
Windows: 232, | ||
}, | ||
players: { | ||
Coop: 32, | ||
MMO: 5, | ||
Multiplayer: 76, | ||
'Single player': 206, | ||
}, | ||
}, | ||
facetStats: {}, | ||
pagination: { | ||
hitsPerPage: 6, | ||
page: 0, | ||
finite: true, | ||
}, | ||
} | ||
|
||
const searchResponsePositionMatchesTrue = { | ||
indexUid: 'steam-video-games', | ||
hits: [ | ||
{ | ||
name: 'Half-Life: Opposing Force', | ||
description: | ||
'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.', | ||
id: '50', | ||
price: '4.99 $', | ||
image: | ||
'http://steam.meilisearch.dev/steam/apps/50/header.jpg?t=1447350813', | ||
releaseDate: 'Nov 1 1999', | ||
recommendationCount: 2934, | ||
platforms: ['MacOS', 'Linux', 'Windows'], | ||
players: ['Single player', 'Multiplayer'], | ||
genres: ['Action'], | ||
misc: [], | ||
_formatted: { | ||
name: '__ais-highlight__Half__/ais-highlight__-Life: Opposing Force', | ||
description: | ||
'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.', | ||
id: '50', | ||
price: '4.99 $', | ||
image: | ||
'http://steam.meilisearch.dev/steam/apps/50/header.jpg?t=1447350813', | ||
releaseDate: 'Nov 1 1999', | ||
recommendationCount: '2934', | ||
platforms: ['MacOS', 'Linux', 'Windows'], | ||
players: ['Single player', 'Multiplayer'], | ||
genres: ['Action'], | ||
misc: [], | ||
}, | ||
_matchesPosition: { | ||
name: [ | ||
{ | ||
start: 0, | ||
length: 4, | ||
}, | ||
], | ||
}, | ||
}, | ||
], | ||
query: 'half', | ||
processingTimeMs: 2, | ||
hitsPerPage: 6, | ||
page: 1, | ||
totalPages: 39, | ||
totalHits: 232, | ||
facetDistribution: { | ||
genres: { | ||
Action: 118, | ||
Adventure: 76, | ||
Casual: 39, | ||
RPG: 44, | ||
Racing: 2, | ||
Simulation: 35, | ||
Sports: 10, | ||
Strategy: 47, | ||
}, | ||
misc: { | ||
'Early access': 33, | ||
'Free to play': 20, | ||
'VR support': 11, | ||
}, | ||
platforms: { | ||
Linux: 68, | ||
MacOS: 96, | ||
Windows: 232, | ||
}, | ||
players: { | ||
Coop: 32, | ||
MMO: 5, | ||
Multiplayer: 76, | ||
'Single player': 206, | ||
}, | ||
}, | ||
facetStats: {}, | ||
pagination: { | ||
hitsPerPage: 6, | ||
page: 0, | ||
finite: true, | ||
}, | ||
} | ||
|
||
describe('Hit adapter', () => { | ||
test('_matchesPosition should be created in hit object with meiliSearchParams.showMatchesPosition=true', () => { | ||
const expectedPositionMatch = { | ||
name: [ | ||
{ | ||
start: 0, | ||
length: 4, | ||
}, | ||
], | ||
} | ||
|
||
const config = { | ||
placeholderSearch: true, | ||
keepZeroFacets: false, | ||
clientAgents: [], | ||
finitePagination: true, | ||
meiliSearchParams: { | ||
showMatchesPosition: true, | ||
}, | ||
} | ||
|
||
const adaptedHits = adaptHits(searchResponsePositionMatchesTrue, config) | ||
|
||
expect(adaptedHits[0]._matchesPosition).toEqual(expectedPositionMatch) | ||
}) | ||
|
||
test('_matchesPosition should NOT be created in hit object with meiliSearchParams.showMatchesPosition=false', () => { | ||
const config = { | ||
placeholderSearch: true, | ||
keepZeroFacets: false, | ||
clientAgents: [], | ||
finitePagination: true, | ||
meiliSearchParams: { | ||
showMatchesPosition: false, | ||
}, | ||
} | ||
|
||
const adaptedHits = adaptHits(searchResponsePositionMatchesFalse, config) | ||
|
||
expect(adaptedHits[0]).not.toHaveProperty('_matchesPosition') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure the best way to test this, or if a test was needed, but took a stab at it. Happy to remove it or (under guidance) improve it