-
Notifications
You must be signed in to change notification settings - Fork 66
Add multi index and disjunctive facet search #888
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
Changes from 3 commits
3302604
29bda1f
bb0ef01
07760b6
073adf0
7b4fc20
ee46536
560763d
a224d1a
8179471
4e1fbb2
b33b7d9
4547b56
238ee58
43a3dac
9f06d09
da79ff1
6f79266
0b130d0
e7b7ca8
2daa5c2
c833807
b1f785d
1bf47bf
42edcde
a6ab3fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,172 @@ | ||||||
| import { instantMeiliSearch } from '../src' | ||||||
| import { Movies, meilisearchClient } from './assets/utils' | ||||||
| import movies from './assets/movies.json' | ||||||
| import games from './assets/games.json' | ||||||
|
|
||||||
| describe('Multi-index search test', () => { | ||||||
| beforeAll(async () => { | ||||||
| const moviesIndex = meilisearchClient.index('movies') | ||||||
| const gamesIndex = meilisearchClient.index('games') | ||||||
|
|
||||||
| await moviesIndex.delete() | ||||||
| await gamesIndex.delete() | ||||||
|
|
||||||
| await moviesIndex.updateSettings({ | ||||||
| filterableAttributes: ['genres', 'color', 'platforms'], | ||||||
| }) | ||||||
| await gamesIndex.updateSettings({ | ||||||
| filterableAttributes: ['genres', 'color', 'platforms'], | ||||||
| }) | ||||||
|
|
||||||
| await moviesIndex.addDocuments(movies) | ||||||
| const response = await gamesIndex.addDocuments(games) | ||||||
|
|
||||||
| await meilisearchClient.waitForTask(response.taskUid) | ||||||
| }) | ||||||
|
|
||||||
| test('searching on two indexes', async () => { | ||||||
| const customClient = instantMeiliSearch( | ||||||
| 'http://localhost:7700', | ||||||
| 'masterKey' | ||||||
| ) | ||||||
|
|
||||||
| const response = await customClient.search<Movies>([ | ||||||
| { | ||||||
| indexName: 'movies', | ||||||
| params: { | ||||||
| query: 'c', | ||||||
| }, | ||||||
| }, | ||||||
| { | ||||||
| indexName: 'games', | ||||||
| params: { | ||||||
| query: 'c', | ||||||
| }, | ||||||
| }, | ||||||
| ]) | ||||||
|
|
||||||
| const movieHits = response.results[0].hits | ||||||
| const gameHits = response.results[1].hits | ||||||
|
|
||||||
| expect(movieHits.length).toBe(1) | ||||||
| expect(gameHits.length).toBe(14) | ||||||
| }) | ||||||
|
|
||||||
| test('searching on two indexes with scroll pagination', async () => { | ||||||
| const customClient = instantMeiliSearch( | ||||||
| 'http://localhost:7700', | ||||||
| 'masterKey' | ||||||
| ) | ||||||
|
|
||||||
| const response = await customClient.search<Movies>([ | ||||||
| { | ||||||
| indexName: 'movies', | ||||||
| params: { | ||||||
| hitsPerPage: 1, | ||||||
| page: 1, | ||||||
| }, | ||||||
| }, | ||||||
| { | ||||||
| indexName: 'games', | ||||||
| params: { | ||||||
| hitsPerPage: 1, | ||||||
| page: 1, | ||||||
| }, | ||||||
| }, | ||||||
| ]) | ||||||
|
|
||||||
| const movies = response.results[0] | ||||||
| const games = response.results[1] | ||||||
|
|
||||||
| expect(movies.hits.length).toBe(1) | ||||||
| expect(movies.page).toBe(1) | ||||||
| expect(movies.nbPages).toBe(3) | ||||||
|
|
||||||
| expect(games.hits.length).toBe(1) | ||||||
| expect(games.page).toBe(1) | ||||||
| expect(games.nbPages).toBe(3) | ||||||
| }) | ||||||
|
|
||||||
| test('searching on two indexes with page selection pagination', async () => { | ||||||
| const customClient = instantMeiliSearch( | ||||||
| 'http://localhost:7700', | ||||||
| 'masterKey', | ||||||
| { | ||||||
| finitePagination: true, | ||||||
| } | ||||||
| ) | ||||||
|
|
||||||
| const response = await customClient.search<Movies>([ | ||||||
| { | ||||||
| indexName: 'movies', | ||||||
| params: { | ||||||
| hitsPerPage: 1, | ||||||
| page: 1, | ||||||
| }, | ||||||
| }, | ||||||
| { | ||||||
| indexName: 'games', | ||||||
| params: { | ||||||
| hitsPerPage: 1, | ||||||
| page: 1, | ||||||
| }, | ||||||
| }, | ||||||
| ]) | ||||||
|
|
||||||
| const movies = response.results[0] | ||||||
| const games = response.results[1] | ||||||
|
|
||||||
| expect(movies.hits.length).toBe(1) | ||||||
| expect(movies.page).toBe(1) | ||||||
| expect(movies.nbPages).toBe(6) | ||||||
|
|
||||||
| expect(games.hits.length).toBe(1) | ||||||
| expect(games.page).toBe(1) | ||||||
| expect(games.nbPages).toBe(15) | ||||||
| }) | ||||||
|
|
||||||
| test('searching on two indexes with no placeholder search', async () => { | ||||||
| const customClient = instantMeiliSearch( | ||||||
| 'http://localhost:7700', | ||||||
| 'masterKey', | ||||||
| { | ||||||
| placeholderSearch: false, | ||||||
| } | ||||||
| ) | ||||||
|
|
||||||
| const emptyResponse = await customClient.search<Movies>([ | ||||||
| { | ||||||
| indexName: 'movies', | ||||||
| }, | ||||||
| { | ||||||
| indexName: 'games', | ||||||
| }, | ||||||
| ]) | ||||||
|
|
||||||
| const emptyMovies = emptyResponse.results[0] | ||||||
| const emptyGames = emptyResponse.results[1] | ||||||
|
|
||||||
| expect(emptyMovies.hits.length).toBe(0) | ||||||
| expect(emptyGames.hits.length).toBe(0) | ||||||
|
|
||||||
| const response = await customClient.search<Movies>([ | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I want to understand this signature better since now you'll return two different types. What do these
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instantsearch requires a search method with a generic. Nonetheless, you are right that it makes no sense as there are multiple indexes now. I looked at the code of algoliasearch and it seems the issue is at their side as well. |
||||||
| { | ||||||
| indexName: 'movies', | ||||||
| params: { | ||||||
| query: 'a', | ||||||
| }, | ||||||
| }, | ||||||
| { | ||||||
| indexName: 'games', | ||||||
| params: { | ||||||
| query: 'a', | ||||||
| }, | ||||||
| }, | ||||||
| ]) | ||||||
| const movies = response.results[0] | ||||||
| const games = response.results[1] | ||||||
|
|
||||||
| expect(movies.hits.length).toBe(4) | ||||||
| expect(games.hits.length).toBe(15) | ||||||
| }) | ||||||
| }) | ||||||
Uh oh!
There was an error while loading. Please reload this page.