Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3302604
Add disjunctive facet search
bidoubiwa Nov 23, 2022
29bda1f
Add condition on filtering caching
bidoubiwa Nov 23, 2022
bb0ef01
Add multi index search
bidoubiwa Nov 24, 2022
07760b6
Add datasets in tests assets
bidoubiwa Nov 24, 2022
073adf0
Update src/client/instant-meilisearch-client.ts
bidoubiwa Nov 24, 2022
7b4fc20
Improve filters
bidoubiwa Nov 24, 2022
ee46536
Improve readme
bidoubiwa Nov 24, 2022
560763d
Merge branch 'bump-meilisearch-v0.30.0-add_multi_index_search' of htt…
bidoubiwa Nov 24, 2022
a224d1a
fix merge conflicts
bidoubiwa Nov 24, 2022
8179471
Remove console logs from client
bidoubiwa Nov 24, 2022
4e1fbb2
Remove comments
bidoubiwa Nov 24, 2022
b33b7d9
Add tests on disjunctive facet search
bidoubiwa Nov 29, 2022
4547b56
remove console log
bidoubiwa Nov 29, 2022
238ee58
Update playground
bidoubiwa Nov 29, 2022
43a3dac
Add logging on react setup
bidoubiwa Nov 29, 2022
9f06d09
Improve README
bidoubiwa Nov 29, 2022
da79ff1
Roll back .gitignore
bidoubiwa Nov 29, 2022
6f79266
Fix readme errors
bidoubiwa Nov 29, 2022
0b130d0
Fix refinement list typo error
bidoubiwa Nov 29, 2022
e7b7ca8
Merge branch 'main' of github.com:meilisearch/instant-meilisearch int…
bidoubiwa Dec 7, 2022
2daa5c2
Fix end to end tests
bidoubiwa Dec 7, 2022
c833807
Fix linting error
bidoubiwa Dec 7, 2022
b1f785d
Update selectors in cypress to improve tests
bidoubiwa Dec 7, 2022
1bf47bf
Add json module resolver for tests
bidoubiwa Dec 7, 2022
42edcde
Add a wait in cypress method resolving to fast
bidoubiwa Dec 7, 2022
a6ab3fa
Remove useless wait in search-ui specs
bidoubiwa Dec 7, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/adapter/search-request-adapter/search-params-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ export function MeiliParamsCreator(searchContext: SearchContext) {
return meiliSearchParams
},
addFacets() {
if (facets?.length) {
if (Array.isArray(facets)) {
meiliSearchParams.facets = facets
} else if (typeof facets === 'string') {
meiliSearchParams.facets = [facets]
}
},
addAttributesToCrop() {
Expand Down
15 changes: 8 additions & 7 deletions src/adapter/search-request-adapter/search-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,19 @@ export function SearchResolver(
// Check if specific request is already cached with its associated search response.
if (cachedResponse) return cachedResponse

const cachedFacets = extractFacets(searchContext, searchParams)

// Make search request
const searchResponse = await client
.index(searchContext.indexUid)
.search(searchContext.query, searchParams)

// Add missing facets back into facetDistribution
searchResponse.facetDistribution = addMissingFacets(
cachedFacets,
searchResponse.facetDistribution
)
if (searchContext.keepZeroFacets) {
const cachedFacets = extractFacets(searchContext, searchParams)
// Add missing facets back into facetDistribution
searchResponse.facetDistribution = addMissingFacets(
cachedFacets,
searchResponse.facetDistribution
)
}

// query can be: empty string, undefined or null
// all of them are falsy's
Expand Down
64 changes: 36 additions & 28 deletions src/client/instant-meilisearch-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,40 +67,48 @@ export function instantMeiliSearch(
instantSearchRequests: readonly AlgoliaMultipleQueriesQuery[]
): Promise<{ results: Array<AlgoliaSearchResponse<T>> }> {
try {
const searchRequest = instantSearchRequests[0]
const searchContext: SearchContext = createSearchContext(
searchRequest,
instantMeiliSearchOptions,
defaultFacetDistribution
)
const searchResponses: { results: Array<AlgoliaSearchResponse<T>> } = {
results: [],
}

// Adapt search request to Meilisearch compliant search request
const adaptedSearchRequest = adaptSearchParams(searchContext)
const requests = instantSearchRequests
for (const searchRequest of requests) {
const searchContext: SearchContext = createSearchContext(
searchRequest,
instantMeiliSearchOptions,
defaultFacetDistribution
)

// Cache first facets distribution of the instantMeilisearch instance
// Needed to add in the facetDistribution the fields that were not returned
// When the user sets `keepZeroFacets` to true.
if (defaultFacetDistribution === undefined) {
defaultFacetDistribution = await cacheFirstFacetDistribution(
searchResolver,
searchContext
const adaptedSearchRequest = adaptSearchParams(searchContext)


// Cache first facets distribution of the instantMeilisearch instance
// Needed to add in the facetDistribution the fields that were not returned
// When the user sets `keepZeroFacets` to true.
if (defaultFacetDistribution === undefined) {
defaultFacetDistribution = await cacheFirstFacetDistribution(
searchResolver,
searchContext
)
searchContext.defaultFacetDistribution = defaultFacetDistribution
}

// Search response from Meilisearch
const searchResponse = await searchResolver.searchResponse(
searchContext,
adaptedSearchRequest
)
searchContext.defaultFacetDistribution = defaultFacetDistribution
}

// Search response from Meilisearch
const searchResponse = await searchResolver.searchResponse(
searchContext,
adaptedSearchRequest
)
// Adapt the Meilisearch response to a compliant instantsearch.js response
const adaptedSearchResponse = adaptSearchResponse<T>(
searchResponse,
searchContext
)

// Adapt the Meilisearch responsne to a compliant instantsearch.js response
const adaptedSearchResponse = adaptSearchResponse<T>(
searchResponse,
searchContext
)
searchResponses.results.push(adaptedSearchResponse.results[0])
}

return adaptedSearchResponse
return searchResponses
} catch (e: any) {
console.error(e)
throw new Error(e)
Expand Down
Loading