Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
bidoubiwa committed Jul 10, 2023
2 parents d457ab3 + e9e1f00 commit 675ea17
Show file tree
Hide file tree
Showing 6 changed files with 269 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/indexes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ class Index<T extends Record<string, any> = Record<string, any>> {
attributesToRetrieve: options?.attributesToRetrieve?.join(','),
attributesToCrop: options?.attributesToCrop?.join(','),
attributesToHighlight: options?.attributesToHighlight?.join(','),
vector: options?.vector?.join(','),
}

return await this.httpRequest.get<SearchResponse<D, S>>(
Expand Down
22 changes: 12 additions & 10 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,7 @@ export type Crop = {
cropMarker?: string
}

export const SortFacetValuesBy = {
COUNT: 'error',
ALPHA: 'alpha',
}

export type SortFacetValuesBy = typeof SortFacetValuesBy[keyof typeof SortFacetValuesBy]

// `facetName` becomes mandatory when using `searchForFacetValues`
export type SearchForFacetValuesParams = Omit<SearchParams, 'facetName'> & {
facetName: string
}
Expand Down Expand Up @@ -112,9 +106,9 @@ export type SearchParams = Query &
matchingStrategy?: MatchingStrategies
hitsPerPage?: number
page?: number
sortFacetValuesBy?: SortFacetValuesBy
facetName?: string
facetQuery?: string
vector?: number[] | null
}

// Search parameters for searches made with the GET method
Expand All @@ -130,6 +124,7 @@ export type SearchRequestGET = Pagination &
attributesToHighlight?: string
attributesToCrop?: string
showMatchesPosition?: boolean
vector?: string | null
}

export type MultiSearchQuery = SearchParams & { indexUid: string }
Expand Down Expand Up @@ -167,6 +162,7 @@ export type SearchResponse<
facetDistribution?: FacetDistribution
query: string
facetStats?: FacetStats
vector: number[]
} & (undefined extends S
? Partial<FinitePagination & InfinitePagination>
: true extends IsFinitePagination<NonNullable<S>>
Expand Down Expand Up @@ -585,12 +581,15 @@ export const enum ErrorStatusCode {
/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_document_offset */
INVALID_DOCUMENT_OFFSET = 'invalid_document_offset',

/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_document_offset */
/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_document_filter */
INVALID_DOCUMENT_FILTER = 'invalid_document_filter',

/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_document_offset */
/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#missing_document_filter */
MISSING_DOCUMENT_FILTER = 'missing_document_filter',

/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_document_vectors_field */
INVALID_DOCUMENT_VECTORS_FIELD = 'invalid_document_vectors_field',

/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#payload_too_large */
PAYLOAD_TOO_LARGE = 'payload_too_large',

Expand Down Expand Up @@ -666,6 +665,9 @@ export const enum ErrorStatusCode {
/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_search_matching_strategy */
INVALID_SEARCH_MATCHING_STRATEGY = 'invalid_search_matching_strategy',

/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_search_vector */
INVALID_SEARCH_VECTOR = 'invalid_search_vector',

/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#bad_request */
BAD_REQUEST = 'bad_request',

Expand Down
205 changes: 205 additions & 0 deletions tests/__snapshots__/facet_search.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Test on POST search Admin key: basic facet value search 1`] = `
Object {
"facetHits": Array [
Object {
"count": 1,
"value": "action",
},
Object {
"count": 2,
"value": "adventure",
},
],
"facetQuery": "a",
"processingTimeMs": 0,
}
`;

exports[`Test on POST search Admin key: facet value search with filter 1`] = `
Object {
"facetHits": Array [
Object {
"count": 1,
"value": "action",
},
],
"facetQuery": "a",
"processingTimeMs": 0,
}
`;

exports[`Test on POST search Admin key: facet value search with no facet query 1`] = `
Object {
"facetHits": Array [
Object {
"count": 1,
"value": "action",
},
Object {
"count": 2,
"value": "adventure",
},
Object {
"count": 1,
"value": "comedy",
},
Object {
"count": 2,
"value": "romance",
},
],
"facetQuery": null,
"processingTimeMs": 0,
}
`;

exports[`Test on POST search Admin key: facet value search with search query 1`] = `
Object {
"facetHits": Array [
Object {
"count": 1,
"value": "adventure",
},
],
"facetQuery": "a",
"processingTimeMs": 0,
}
`;

exports[`Test on POST search Master key: basic facet value search 1`] = `
Object {
"facetHits": Array [
Object {
"count": 1,
"value": "action",
},
Object {
"count": 2,
"value": "adventure",
},
],
"facetQuery": "a",
"processingTimeMs": 0,
}
`;

exports[`Test on POST search Master key: facet value search with filter 1`] = `
Object {
"facetHits": Array [
Object {
"count": 1,
"value": "action",
},
],
"facetQuery": "a",
"processingTimeMs": 0,
}
`;

exports[`Test on POST search Master key: facet value search with no facet query 1`] = `
Object {
"facetHits": Array [
Object {
"count": 1,
"value": "action",
},
Object {
"count": 2,
"value": "adventure",
},
Object {
"count": 1,
"value": "comedy",
},
Object {
"count": 2,
"value": "romance",
},
],
"facetQuery": null,
"processingTimeMs": 0,
}
`;

exports[`Test on POST search Master key: facet value search with search query 1`] = `
Object {
"facetHits": Array [
Object {
"count": 1,
"value": "adventure",
},
],
"facetQuery": "a",
"processingTimeMs": 0,
}
`;

exports[`Test on POST search Search key: basic facet value search 1`] = `
Object {
"facetHits": Array [
Object {
"count": 1,
"value": "action",
},
Object {
"count": 2,
"value": "adventure",
},
],
"facetQuery": "a",
"processingTimeMs": 0,
}
`;

exports[`Test on POST search Search key: facet value search with filter 1`] = `
Object {
"facetHits": Array [
Object {
"count": 1,
"value": "action",
},
],
"facetQuery": "a",
"processingTimeMs": 0,
}
`;

exports[`Test on POST search Search key: facet value search with no facet query 1`] = `
Object {
"facetHits": Array [
Object {
"count": 1,
"value": "action",
},
Object {
"count": 2,
"value": "adventure",
},
Object {
"count": 1,
"value": "comedy",
},
Object {
"count": 2,
"value": "romance",
},
],
"facetQuery": null,
"processingTimeMs": 0,
}
`;

exports[`Test on POST search Search key: facet value search with search query 1`] = `
Object {
"facetHits": Array [
Object {
"count": 1,
"value": "adventure",
},
],
"facetQuery": "a",
"processingTimeMs": 0,
}
`;
10 changes: 4 additions & 6 deletions tests/facet_search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ describe.each([
}
const response = await client.index(index.uid).searchForFacetValues(params)

expect(response.facetHits.length).toEqual(2)
expect(response.facetQuery).toEqual('a')
expect(response).toMatchSnapshot()
})

test(`${permission} key: facet value search with no facet query`, async () => {
Expand All @@ -69,8 +68,7 @@ describe.each([
}
const response = await client.index(index.uid).searchForFacetValues(params)

expect(response.facetHits.length).toEqual(4)
expect(response.facetQuery).toEqual(null)
expect(response).toMatchSnapshot()
})

test(`${permission} key: facet value search with filter`, async () => {
Expand All @@ -84,7 +82,7 @@ describe.each([

const response = await client.index(index.uid).searchForFacetValues(params)

expect(response.facetHits.length).toEqual(1)
expect(response).toMatchSnapshot()
})

test(`${permission} key: facet value search with search query`, async () => {
Expand All @@ -97,7 +95,7 @@ describe.each([
}
const response = await client.index(index.uid).searchForFacetValues(params)

expect(response.facetHits.length).toEqual(1)
expect(response).toMatchSnapshot()
})
})

Expand Down
21 changes: 21 additions & 0 deletions tests/get_search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
BAD_HOST,
MeiliSearch,
getClient,
HOST,
getKey,
} from './utils/meilisearch-test-utils'

const index = {
Expand Down Expand Up @@ -423,6 +425,25 @@ describe.each([
'The filter query parameter should be in string format when using searchGet'
)
})
test(`${permission} key: search with vectors`, async () => {
const client = await getClient(permission)
const key = await getKey(permission)

await fetch(`${HOST}/experimental-features`, {
body: JSON.stringify({ vectorStore: true }),
headers: {
Authorization: `Bearer ${key}`,
'Content-Type': 'application/json',
},
method: 'PATCH',
})

const response = await client
.index(emptyIndex.uid)
.searchGet('', { vector: [1] })

expect(response.vector).toEqual([1])
})

test(`${permission} key: Try to search on deleted index and fail`, async () => {
const client = await getClient(permission)
Expand Down
26 changes: 26 additions & 0 deletions tests/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ import {
MeiliSearch,
getClient,
datasetWithNests,
HOST,
getKey,
} from './utils/meilisearch-test-utils'

if (typeof fetch === 'undefined') {
require('cross-fetch/polyfill')
}

const index = {
uid: 'movies_test',
}
Expand Down Expand Up @@ -767,6 +773,26 @@ describe.each([
expect(response.hits.length).toEqual(0)
})

test(`${permission} key: search with vectors`, async () => {
const client = await getClient(permission)
const key = await getKey(permission)

await fetch(`${HOST}/experimental-features`, {
body: JSON.stringify({ vectorStore: true }),
headers: {
Authorization: `Bearer ${key}`,
'Content-Type': 'application/json',
},
method: 'PATCH',
})

const response = await client
.index(emptyIndex.uid)
.search('', { vector: [1] })

expect(response.vector).toEqual([1])
})

test(`${permission} key: Try to search on deleted index and fail`, async () => {
const client = await getClient(permission)
const masterClient = await getClient('Master')
Expand Down

0 comments on commit 675ea17

Please sign in to comment.