Skip to content

Changes related to the next Meilisearch release (v1.3.0) #1186

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

Merged
merged 2 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"@meilisearch/angular-playground",
"@meilisearch/vue3-ts-playground",
"@meilisearch/react-playground",
"@meilisearch/local-react-playground"
"@meilisearch/local-react-playground",
"@meilisearch/node-playground",
"@meilisearch/autocomplete-playground"
]
}
5 changes: 5 additions & 0 deletions .changeset/curly-elephants-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@meilisearch/instant-meilisearch": patch
---

Add compatibility with the `searchable` parameter of the [`RefinementList`](https://www.algolia.com/doc/api-reference/widgets/refinement-list/js/) widget
10 changes: 5 additions & 5 deletions packages/instant-meilisearch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -707,11 +707,11 @@ The `refinementList` widget is one of the most common widgets you can find in a
- ✅ limit: How many facet values to retrieve.
- ✅ showMore: Whether to display a button that expands the number of items.
- ✅ showMoreLimit: The maximum number of displayed items. Does not work when showMoreLimit > limit.
- searchable: Whether to add a search input to let the user search for more facet values. Not supported by Meilisearch. If you'd like to see it implemented [please vote](https://roadmap.meilisearch.com/c/64-search-for-facet-values?utm_medium=social&utm_source=portal_share).
- searchablePlaceholder: The value of the search input’s placeholder. Not supported, see `searchable`.
- searchableIsAlwaysActive: When false, disables the facet search input. Not supported, see `searchable`.
- ❌ searchableEscapeFacetValues: When true, escapes the facet values. Not supported, see `searchable`.
- ❌ sortBy: Not supported natively but can be implemented manually using `transformItems` options.
- searchable: Whether to add a search input to let the user search for more facet values. Not supported by Meilisearch. If you'd like to see it implemented [please vote](https://roadmap.meilisearch.com/c/64-search-for-facet-values?utm_medium=social&utm_source=portal_share).
- searchablePlaceholder: The value of the search input’s placeholder. Not supported, see `searchable`.
- searchableIsAlwaysActive: When false, disables the facet search input. Not supported, see `searchable`.
- ❌ searchableEscapeFacetValues: When true, escapes the facet values.
- ❌ sortBy: Not supported but can be implemented manually using `transformItems` options.
- ✅ transformItems: A function to transform the items passed to the templates.
- ✅ templates: The templates to use for the widget.
- ✅ cssClasses: The CSS classes to override.
Expand Down
2 changes: 1 addition & 1 deletion packages/instant-meilisearch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"templates"
],
"dependencies": {
"meilisearch": "^0.33.0"
"meilisearch": "0.35.0-v1.3.0-pre-release.1"
},
"devDependencies": {
"@babel/cli": "^7.21.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
FacetDistribution,
PaginationState,
MeilisearchConfig,
AlgoliaSearchForFacetValuesRequests,
AlgoliaSearchForFacetValuesResponse,
} from '../types'
import {
getApiKey,
Expand All @@ -19,7 +21,7 @@ import {
adaptSearchParams,
SearchResolver,
} from '../adapter'
import { createSearchContext } from '../contexts'
import { createSearchContext, createFacetSearchContext } from '../contexts'
import {
SearchCache,
initFacetDistribution,
Expand Down Expand Up @@ -132,13 +134,48 @@ export function instantMeiliSearch(
throw new Error(e)
}
},
searchForFacetValues: async function (_: any) {
return await new Promise((resolve, reject) => {
reject(
new Error('SearchForFacetValues is not compatible with Meilisearch')
searchForFacetValues: async function (
requests: AlgoliaSearchForFacetValuesRequests
): Promise<AlgoliaSearchForFacetValuesResponse[]> {
const results = []
for (const request of requests) {
const searchContext: SearchContext = createFacetSearchContext(
request,
instantMeiliSearchOptions
)
resolve([]) // added here to avoid compilation error
})

const meilisearchSearchQuery = adaptSearchParams(searchContext)

const index = request.indexName

const meilisearchRequest: any = {
...meilisearchSearchQuery,
facetQuery: request.params.facetQuery,
facetName: request.params.facetName,
}

delete meilisearchRequest.indexUid

const meilisearchResponse = await meilisearchClient
.index(index)
.searchForFacetValues(meilisearchRequest)

const facetHits = meilisearchResponse.facetHits.map((facetHit) => ({
...facetHit,
// not currently supported
highlighted: facetHit.value,
}))

const result = {
facetHits,
exhaustiveFacetsCount: false,
processingTimeMS: meilisearchResponse.processingTimeMs,
}

results.push(result)
}

return results
},
}
}
2 changes: 1 addition & 1 deletion packages/instant-meilisearch/src/contexts/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { createSearchContext } from './search-context'
export { createSearchContext, createFacetSearchContext } from './search-context'
34 changes: 34 additions & 0 deletions packages/instant-meilisearch/src/contexts/search-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
InstantMeiliSearchOptions,
AlgoliaMultipleQueriesQuery,
SearchContext,
AlgoliaSearchForFacetValuesRequest,
} from '../types'
import { splitSortString } from './sort-context'
import { createPaginationState } from './pagination-context'
Expand Down Expand Up @@ -54,3 +55,36 @@ export function createSearchContext(
}
return searchContext
}

/**
* @param {AlgoliaMultipleQueriesQuery} searchRequest
* @param {Context} options
* @returns {SearchContext}
*/
export function createFacetSearchContext(
searchRequest: AlgoliaSearchForFacetValuesRequest,
options: InstantMeiliSearchOptions
): SearchContext {
// Split index name and possible sorting rules
const [indexUid, ...sortByArray] = searchRequest.indexName.split(':')
const { params: instantSearchParams } = searchRequest

const paginationState = createPaginationState(
options.finitePagination,
instantSearchParams?.hitsPerPage,
instantSearchParams?.page
)

const sortState = splitSortString(sortByArray.join(':'))

const searchContext: SearchContext = {
...options,
...instantSearchParams,
sort: sortState,
indexUid,
pagination: paginationState,
placeholderSearch: options.placeholderSearch !== false, // true by default
keepZeroFacets: !!options.keepZeroFacets, // false by default
}
return searchContext
}
12 changes: 11 additions & 1 deletion packages/instant-meilisearch/src/types/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import type { SearchClient } from 'instantsearch.js'
import type { MultipleQueriesQuery as AlgoliaMultipleQueriesQuery } from '@algolia/client-search'
import type {
MultipleQueriesQuery as AlgoliaMultipleQueriesQuery,
multipleSearchForFacetValues,
} from '@algolia/client-search'
import type {
MultiSearchQuery as MeiliSearchMultiSearchParams,
MultiSearchResult,
Expand All @@ -12,6 +15,13 @@ export type {
SearchForFacetValuesResponse as AlgoliaSearchForFacetValuesResponse,
} from '@algolia/client-search'

export type AlgoliaSearchForFacetValuesRequests = Parameters<
ReturnType<typeof multipleSearchForFacetValues>
>[0]

export type AlgoliaSearchForFacetValuesRequest =
AlgoliaSearchForFacetValuesRequests[0]

export type {
Filter,
FacetDistribution,
Expand Down
9 changes: 7 additions & 2 deletions playgrounds/local-react/cypress/integration/search-ui.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ describe(`${playground} playground test`, () => {

it('Sort by recommendationCound ascending', () => {
const select = `.ais-SortBy-select`
cy.get(select).select('games:recommendationCount:asc')
cy.get(select)
.select('games:recommendationCount:asc')
.should('have.value', 'games:recommendationCount:asc')
cy.wait(1000)
cy.get(HIT_ITEM_CLASS).eq(0).contains('Deathmatch Classic')
})
Expand All @@ -61,7 +63,10 @@ describe(`${playground} playground test`, () => {
})

it('Search', () => {
cy.get('.ais-SearchBox-input').type('Half-Life')
cy.get('.right-panel')
.find('.ais-SearchBox-input')
.type('Half-Life')
.should('have.value', 'Half-Life')
cy.wait(1000)
cy.get(HIT_ITEM_CLASS).eq(0).contains('Half-Life')
})
Expand Down
4 changes: 2 additions & 2 deletions playgrounds/local-react/src/components/SingleIndex.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ const SingleIndex = () => (
]}
/>
<h2>Genres</h2>
<RefinementList attribute="genres" />
<RefinementList attribute="genres" searchable={true} />
<h2>Players</h2>
<RefinementList attribute="players" />
<RefinementList attribute="players" searchable={true} />
<h2>Platforms</h2>
<RefinementList attribute="platforms" />
<h2>Misc</h2>
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10269,10 +10269,10 @@ [email protected]:
resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748"
integrity sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==

meilisearch@^0.33.0:
version "0.33.0"
resolved "https://registry.yarnpkg.com/meilisearch/-/meilisearch-0.33.0.tgz#25982b193cdd22e9ec534a022dbde89c42951dc4"
integrity sha512-bYPb9WyITnJfzf92e7QFK8Rc50DmshFWxypXCs3ILlpNh8pT15A7KSu9Xgnnk/K3G/4vb3wkxxtFS4sxNkWB8w==
meilisearch@0.35.0-v1.3.0-pre-release.1:
version "0.35.0-v1.3.0-pre-release.1"
resolved "https://registry.yarnpkg.com/meilisearch/-/meilisearch-0.35.0-v1.3.0-pre-release.1.tgz#24fa735a25539a9de11b0e84a5e4455de003316b"
integrity sha512-rzWDGkuBByGnFjBsnzVNaHS+sXtshwumAYHq8zbkVmwpEwZLuM0bcguKJWcuXvTIkfRqS3u/BhQBtcJ/HWg7dw==
dependencies:
cross-fetch "^3.1.6"

Expand Down