Skip to content

Commit 4639c71

Browse files
meili-bors[bot]meili-botbidoubiwa
authored
Merge #1530
1530: Changes related to the next Meilisearch release (v1.3.0) r=bidoubiwa a=meili-bot Related to this issue: meilisearch/integration-guides#280 This PR: - gathers the changes related to the next Meilisearch release (v1.3.0) so that this package is ready when the official release is out. - should pass the tests against the [latest pre-release of Meilisearch](https://github.com/meilisearch/meilisearch/releases). - might eventually contain test failures until the Meilisearch v1.3.0 is out. ⚠️ This PR should NOT be merged until the next release of Meilisearch (v1.3.0) is out. _This PR is auto-generated for the [pre-release week](https://github.com/meilisearch/integration-guides/blob/main/resources/pre-release-week.md) purpose._ Co-authored-by: meili-bot <[email protected]> Co-authored-by: cvermand <[email protected]> Co-authored-by: Charlotte Vermandel <[email protected]>
2 parents 46a93c4 + e9f6865 commit 4639c71

14 files changed

+1584
-133
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,14 @@ client.multiSearch(queries?: MultiSearchParams, config?: Partial<Request>): Prom
418418

419419
`multiSearch` uses the `POST` method when performing its request to Meilisearch.
420420

421+
### Search For Facet Values
422+
423+
#### [Search for facet values](#)
424+
425+
```ts
426+
client.index<T>('myIndex').searchForFacetValues(params: SearchForFacetValuesParams, config?: Partial<Request>): Promise<SearchForFacetValuesResponse>
427+
```
428+
421429
### Documents <!-- omit in toc -->
422430

423431
#### [Add or replace multiple documents](https://www.meilisearch.com/docs/reference/api/documents#add-or-replace-documents)

src/indexes.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ import {
4545
ContentType,
4646
DocumentsIds,
4747
DocumentsDeletionQuery,
48+
SearchForFacetValuesParams,
49+
SearchForFacetValuesResponse,
4850
} from './types'
4951
import { removeUndefinedFromObject } from './utils'
5052
import { HttpRequests } from './http-requests'
@@ -137,6 +139,8 @@ class Index<T extends Record<string, any> = Record<string, any>> {
137139
attributesToRetrieve: options?.attributesToRetrieve?.join(','),
138140
attributesToCrop: options?.attributesToCrop?.join(','),
139141
attributesToHighlight: options?.attributesToHighlight?.join(','),
142+
vector: options?.vector?.join(','),
143+
attributesToSearchOn: options?.attributesToSearchOn?.join(','),
140144
}
141145

142146
return await this.httpRequest.get<SearchResponse<D, S>>(
@@ -146,6 +150,27 @@ class Index<T extends Record<string, any> = Record<string, any>> {
146150
)
147151
}
148152

153+
/**
154+
* Search for facet values
155+
*
156+
* @param params - Parameters used to search on the facets
157+
* @param config - Additional request configuration options
158+
* @returns Promise containing the search response
159+
*/
160+
async searchForFacetValues(
161+
params: SearchForFacetValuesParams,
162+
config?: Partial<Request>
163+
): Promise<SearchForFacetValuesResponse> {
164+
const url = `indexes/${this.uid}/facet-search`
165+
166+
return await this.httpRequest.post(
167+
url,
168+
removeUndefinedFromObject(params),
169+
undefined,
170+
config
171+
)
172+
}
173+
149174
///
150175
/// INDEX
151176
///

src/types/types.ts

Lines changed: 84 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,22 @@ export type Crop = {
7878
cropMarker?: string
7979
}
8080

81+
// `facetName` becomes mandatory when using `searchForFacetValues`
82+
export type SearchForFacetValuesParams = Omit<SearchParams, 'facetName'> & {
83+
facetName: string
84+
}
85+
86+
export type FacetHit = {
87+
value: string
88+
count: number
89+
}
90+
91+
export type SearchForFacetValuesResponse = {
92+
facetHits: FacetHit[]
93+
facetQuery: string | null
94+
processingTimeMs: number
95+
}
96+
8197
export type SearchParams = Query &
8298
Pagination &
8399
Highlight &
@@ -90,6 +106,12 @@ export type SearchParams = Query &
90106
matchingStrategy?: MatchingStrategies
91107
hitsPerPage?: number
92108
page?: number
109+
facetName?: string
110+
facetQuery?: string
111+
vector?: number[] | null
112+
showRankingScore?: boolean
113+
showRankingScoreDetails?: boolean
114+
attributesToSearchOn?: string[] | null
93115
}
94116

95117
// Search parameters for searches made with the GET method
@@ -105,6 +127,8 @@ export type SearchRequestGET = Pagination &
105127
attributesToHighlight?: string
106128
attributesToCrop?: string
107129
showMatchesPosition?: boolean
130+
vector?: string | null
131+
attributesToSearchOn?: string | null
108132
}
109133

110134
export type MultiSearchQuery = SearchParams & { indexUid: string }
@@ -126,6 +150,39 @@ export type MatchesPosition<T> = Partial<
126150
export type Hit<T = Record<string, any>> = T & {
127151
_formatted?: Partial<T>
128152
_matchesPosition?: MatchesPosition<T>
153+
_rankingScore?: number
154+
_rankingScoreDetails?: RakingScoreDetails
155+
}
156+
157+
export type RakingScoreDetails = {
158+
words?: {
159+
order: number
160+
matchingWords: number
161+
maxMatchingWords: number
162+
score: number
163+
}
164+
typo?: {
165+
order: number
166+
typoCount: number
167+
maxTypoCount: number
168+
score: number
169+
}
170+
proximity?: {
171+
order: number
172+
score: number
173+
}
174+
attribute?: {
175+
order: number
176+
attributes_ranking_order: number
177+
attributes_query_word_order: number
178+
score: number
179+
}
180+
exactness?: {
181+
order: number
182+
matchType: string
183+
score: number
184+
}
185+
[key: string]: Record<string, any> | undefined
129186
}
130187

131188
export type Hits<T = Record<string, any>> = Array<Hit<T>>
@@ -139,9 +196,10 @@ export type SearchResponse<
139196
> = {
140197
hits: Hits<T>
141198
processingTimeMs: number
142-
facetDistribution?: FacetDistribution
143199
query: string
200+
facetDistribution?: FacetDistribution
144201
facetStats?: FacetStats
202+
vector?: number[]
145203
} & (undefined extends S
146204
? Partial<FinitePagination & InfinitePagination>
147205
: true extends IsFinitePagination<NonNullable<S>>
@@ -255,9 +313,13 @@ export type TypoTolerance = {
255313
}
256314
} | null
257315

316+
export type FacetOrder = 'alpha' | 'count'
317+
258318
export type Faceting = {
259319
maxValuesPerFacet?: number | null
320+
sortFacetValuesBy?: Record<string, FacetOrder> | null
260321
}
322+
261323
export type PaginationSettings = {
262324
maxTotalHits?: number | null
263325
}
@@ -399,6 +461,7 @@ type CursorResults<T> = {
399461
limit: number
400462
from: number
401463
next: number
464+
total: number
402465
}
403466

404467
export type TasksResults = CursorResults<Task>
@@ -556,12 +619,15 @@ export const enum ErrorStatusCode {
556619
/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_document_offset */
557620
INVALID_DOCUMENT_OFFSET = 'invalid_document_offset',
558621

559-
/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_document_offset */
622+
/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_document_filter */
560623
INVALID_DOCUMENT_FILTER = 'invalid_document_filter',
561624

562-
/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_document_offset */
625+
/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#missing_document_filter */
563626
MISSING_DOCUMENT_FILTER = 'missing_document_filter',
564627

628+
/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_document_vectors_field */
629+
INVALID_DOCUMENT_VECTORS_FIELD = 'invalid_document_vectors_field',
630+
565631
/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#payload_too_large */
566632
PAYLOAD_TOO_LARGE = 'payload_too_large',
567633

@@ -637,6 +703,12 @@ export const enum ErrorStatusCode {
637703
/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_search_matching_strategy */
638704
INVALID_SEARCH_MATCHING_STRATEGY = 'invalid_search_matching_strategy',
639705

706+
/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_search_vector */
707+
INVALID_SEARCH_VECTOR = 'invalid_search_vector',
708+
709+
/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_search_attributes_to_search_on */
710+
INVALID_SEARCH_ATTRIBUTES_TO_SEARCH_ON = 'invalid_search_attributes_to_search_on',
711+
640712
/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#bad_request */
641713
BAD_REQUEST = 'bad_request',
642714

@@ -816,6 +888,15 @@ export const enum ErrorStatusCode {
816888

817889
/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_api_key_offset */
818890
INVALID_API_KEY_OFFSET = 'invalid_api_key_offset',
891+
892+
/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_facet_search_facet_name */
893+
INVALID_FACET_SEARCH_FACET_NAME = 'invalid_facet_search_facet_name',
894+
895+
/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#missing_facet_search_facet_name */
896+
MISSING_FACET_SEARCH_FACET_NAME = 'missing_facet_search_facet_name',
897+
898+
/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_facet_search_facet_query */
899+
INVALID_FACET_SEARCH_FACET_QUERY = 'invalid_facet_search_facet_query',
819900
}
820901

821902
export type TokenIndexRules = {

0 commit comments

Comments
 (0)