Skip to content

Feature prototype: pagination feature compatibility #1305

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

Closed
wants to merge 10 commits into from
Closed
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
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ Here are the steps to release a beta version of this package:
```bash
git checkout -b my-feature-beta
```
- During the Meilisearch pre-release, create a branch originating from `bump-meilisearch-v*.*.*` named `meilisearch-v*.*.*-beta`. <br>
- During the Meilisearch pre-release, create a branch originating from `bump-meilisearch-v*.*.*` named `bump-meilisearch-v*.*.*-beta`. <br>
`v*.*.*` is the next version of the package, NOT the version of Meilisearch!

```bash
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "meilisearch",
"version": "0.27.0",
"version": "0.28.0-pagination-beta.0",
"description": "The Meilisearch JS client for Node.js and the browser.",
"keywords": [
"meilisearch",
Expand Down
2 changes: 1 addition & 1 deletion src/package-version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const PACKAGE_VERSION = '0.27.0'
export const PACKAGE_VERSION = '0.28.0-pagination-beta.0'
12 changes: 9 additions & 3 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ export type SearchParams = Query &
facets?: string[]
attributesToRetrieve?: string[]
showMatchesPosition?: boolean
hitsPerPage?: number
page?: number
}

// Search parameters for searches made with the GET method
Expand Down Expand Up @@ -113,12 +115,16 @@ export type Hits<T = Record<string, any>> = Array<Hit<T>>

export type SearchResponse<T = Record<string, any>> = {
hits: Hits<T>
offset: number
limit: number
processingTimeMs: number
facetDistribution?: FacetDistribution
query: string
estimatedTotalHits: number
totalHits?: number
hitsPerPage?: number
page?: number
totalPages?: number
offset?: number
limit?: number
estimatedTotalHits?: number
}

export type FieldDistribution = {
Expand Down
22 changes: 13 additions & 9 deletions tests/get_search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ describe.each([
const client = await getClient(permission)
const response = await client.index(index.uid).searchGet('prince', {})
expect(response).toHaveProperty('hits', expect.any(Array))
expect(response).toHaveProperty('offset', 0)
expect(response).toHaveProperty('limit', 20)
expect(response).toHaveProperty('hitsPerPage', 20)
expect(response).toHaveProperty('page', 1)
expect(response).toHaveProperty('totalPages', 1)
expect(response).toHaveProperty('processingTimeMs', expect.any(Number))
expect(response).toHaveProperty('query', 'prince')
expect(response.hits.length).toEqual(2)
Expand Down Expand Up @@ -128,8 +129,9 @@ describe.each([
attributesToRetrieve: ['*'],
})
expect(response).toHaveProperty('hits', expect.any(Array))
expect(response).toHaveProperty('offset', 0)
expect(response).toHaveProperty('limit', 20)
expect(response).toHaveProperty('hitsPerPage', 20)
expect(response).toHaveProperty('page', 1)
expect(response).toHaveProperty('totalPages', 1)
expect(response).toHaveProperty('processingTimeMs', expect.any(Number))
expect(response).toHaveProperty('query', 'prince')
expect(response.hits.length).toEqual(2)
Expand All @@ -141,8 +143,9 @@ describe.each([
attributesToRetrieve: ['*'],
})
expect(response).toHaveProperty('hits', expect.any(Array))
expect(response).toHaveProperty('offset', 0)
expect(response).toHaveProperty('limit', 20)
expect(response).toHaveProperty('hitsPerPage', 20)
expect(response).toHaveProperty('page', 1)
expect(response).toHaveProperty('totalPages', 1)
expect(response).toHaveProperty('processingTimeMs', expect.any(Number))
expect(response).toHaveProperty('query', 'prince')
expect(response.hits.length).toEqual(2)
Expand Down Expand Up @@ -191,8 +194,9 @@ describe.each([
showMatchesPosition: true,
})
expect(response).toHaveProperty('hits', expect.any(Array))
expect(response).toHaveProperty('offset', 0)
expect(response).toHaveProperty('limit', 20)
expect(response).toHaveProperty('hitsPerPage', 20)
expect(response).toHaveProperty('page', 1)
expect(response).toHaveProperty('totalPages', 1)
expect(response).toHaveProperty('processingTimeMs', expect.any(Number))
expect(response).toHaveProperty('query', 'prince')
expect(response.hits.length).toEqual(1)
Expand Down Expand Up @@ -410,7 +414,7 @@ describe.each([
genre: { fantasy: 2 },
})
expect(response.hits.length).toEqual(2)
expect(response.estimatedTotalHits).toEqual(2)
expect(response.totalHits).toEqual(2)
})

test(`${permission} key: search with multiple filter and empty string query (placeholder)`, async () => {
Expand Down
164 changes: 145 additions & 19 deletions tests/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,12 @@ describe.each([
const client = await getClient(permission)
const response = await client.index(index.uid).search('prince', {})
expect(response).toHaveProperty('hits', expect.any(Array))
expect(response).toHaveProperty('offset', 0)
expect(response).toHaveProperty('limit', 20)
expect(response).toHaveProperty('hitsPerPage', 20)
expect(response).toHaveProperty('page', 1)
expect(response).toHaveProperty('totalPages', 1)
expect(response).toHaveProperty('processingTimeMs', expect.any(Number))
expect(response).toHaveProperty('query', 'prince')
expect(response).toHaveProperty('totalHits', 2)
expect(response.hits.length).toEqual(2)
})

Expand All @@ -102,10 +104,12 @@ describe.each([
.search('other', { q: 'prince' })

expect(response).toHaveProperty('hits', expect.any(Array))
expect(response).toHaveProperty('offset', 0)
expect(response).toHaveProperty('limit', 20)
expect(response).toHaveProperty('hitsPerPage', 20)
expect(response).toHaveProperty('page', 1)
expect(response).toHaveProperty('totalPages', 1)
expect(response).toHaveProperty('processingTimeMs', expect.any(Number))
expect(response).toHaveProperty('query', 'prince')
expect(response).toHaveProperty('totalHits', 2)
expect(response.hits.length).toEqual(2)
})

Expand All @@ -114,10 +118,12 @@ describe.each([
const response = await client.index(index.uid).search(null, { q: 'prince' })

expect(response).toHaveProperty('hits', expect.any(Array))
expect(response).toHaveProperty('offset', 0)
expect(response).toHaveProperty('limit', 20)
expect(response).toHaveProperty('hitsPerPage', 20)
expect(response).toHaveProperty('page', 1)
expect(response).toHaveProperty('totalPages', 1)
expect(response).toHaveProperty('processingTimeMs', expect.any(Number))
expect(response).toHaveProperty('query', 'prince')
expect(response).toHaveProperty('totalHits', 2)
expect(response.hits.length).toEqual(2)
})

Expand All @@ -127,8 +133,9 @@ describe.each([
.index(index.uid)
.search('"french book" about', {})
expect(response).toHaveProperty('hits', expect.any(Array))
expect(response).toHaveProperty('offset', 0)
expect(response).toHaveProperty('limit', 20)
expect(response).toHaveProperty('hitsPerPage', 20)
expect(response).toHaveProperty('page', 1)
expect(response).toHaveProperty('totalPages', 1)
expect(response).toHaveProperty('processingTimeMs', expect.any(Number))
expect(response).toHaveProperty('query', '"french book" about')
expect(response.hits.length).toEqual(2)
Expand All @@ -142,6 +149,7 @@ describe.each([
expect(response).toHaveProperty('hits', expect.any(Array))
expect(response).toHaveProperty('offset', 0)
expect(response).toHaveProperty('limit', 1)
expect(response.estimatedTotalHits).toEqual(2)
expect(response).toHaveProperty('processingTimeMs', expect.any(Number))
expect(response).toHaveProperty('query', 'prince')
expect(response.hits.length).toEqual(1)
Expand All @@ -163,10 +171,12 @@ describe.each([
attributesToRetrieve: ['*'],
})
expect(response).toHaveProperty('hits', expect.any(Array))
expect(response).toHaveProperty('offset', 0)
expect(response).toHaveProperty('limit', 20)
expect(response).toHaveProperty('hitsPerPage', 20)
expect(response).toHaveProperty('page', 1)
expect(response).toHaveProperty('totalPages', 1)
expect(response).toHaveProperty('processingTimeMs', expect.any(Number))
expect(response).toHaveProperty('query', 'prince')
expect(response).toHaveProperty('totalHits', 2)
expect(response.hits.length).toEqual(2)
})

Expand All @@ -176,10 +186,12 @@ describe.each([
attributesToRetrieve: ['*'],
})
expect(response).toHaveProperty('hits', expect.any(Array))
expect(response).toHaveProperty('offset', 0)
expect(response).toHaveProperty('limit', 20)
expect(response).toHaveProperty('hitsPerPage', 20)
expect(response).toHaveProperty('page', 1)
expect(response).toHaveProperty('totalPages', 1)
expect(response).toHaveProperty('processingTimeMs', expect.any(Number))
expect(response).toHaveProperty('query', 'prince')
expect(response).toHaveProperty('totalHits', 2)
expect(response.hits.length).toEqual(2)
})

Expand All @@ -191,6 +203,7 @@ describe.each([
expect(response).toHaveProperty('hits', expect.any(Array))
expect(response).toHaveProperty('offset', 0)
expect(response).toHaveProperty('limit', 1)
expect(response.estimatedTotalHits).toEqual(2)
expect(response).toHaveProperty('processingTimeMs', expect.any(Number))
expect(response).toHaveProperty('query', 'prince')
expect(response.hits.length).toEqual(1)
Expand All @@ -212,6 +225,7 @@ describe.each([
])
expect(response).toHaveProperty('offset', 1)
expect(response).toHaveProperty('limit', 1)
expect(response.estimatedTotalHits).toEqual(2)
expect(response).toHaveProperty('processingTimeMs', expect.any(Number))
expect(response).toHaveProperty('query', 'prince')
expect(response.hits.length).toEqual(1)
Expand All @@ -226,10 +240,12 @@ describe.each([
showMatchesPosition: true,
})
expect(response).toHaveProperty('hits', expect.any(Array))
expect(response).toHaveProperty('offset', 0)
expect(response).toHaveProperty('limit', 20)
expect(response).toHaveProperty('hitsPerPage', 20)
expect(response).toHaveProperty('page', 1)
expect(response).toHaveProperty('totalPages', 1)
expect(response).toHaveProperty('processingTimeMs', expect.any(Number))
expect(response).toHaveProperty('query', 'prince')
expect(response).toHaveProperty('totalHits', 1)
expect(response.hits.length).toEqual(1)
expect(response.hits[0]).toHaveProperty('_matchesPosition', {
comment: [{ start: 22, length: 6 }],
Expand All @@ -252,6 +268,7 @@ describe.each([
expect(response).toHaveProperty('hits', expect.any(Array))
expect(response).toHaveProperty('offset', 0)
expect(response).toHaveProperty('limit', 5)
expect(response.estimatedTotalHits).toEqual(1)
expect(response).toHaveProperty('processingTimeMs', expect.any(Number))
expect(response).toHaveProperty('query', 'prince')
expect(response.hits[0]._formatted).toHaveProperty('title')
Expand Down Expand Up @@ -425,6 +442,7 @@ describe.each([
const response = await client.index(index.uid).search('h', {
filter: ['genre = "sci fi"'],
})

expect(response).toHaveProperty('hits', expect.any(Array))
expect(response.hits.length).toEqual(1)
})
Expand Down Expand Up @@ -464,7 +482,6 @@ describe.each([
genre: { fantasy: 2 },
})
expect(response.hits.length).toEqual(2)
expect(response.estimatedTotalHits).toEqual(2)
})

test(`${permission} key: search with multiple filter and empty string query (placeholder)`, async () => {
Expand All @@ -479,12 +496,119 @@ describe.each([
expect(response.hits.length).toEqual(2)
})

test(`${permission} key: search with pagination parameters: hitsPerPage and page`, async () => {
const client = await getClient(permission)

const response = await client.index(index.uid).search('', {
hitsPerPage: 1,
page: 1,
})

expect(response.hits.length).toEqual(1)
expect(response.totalPages).toEqual(7)
expect(response.hitsPerPage).toEqual(1)
expect(response.page).toEqual(1)
expect(response.totalHits).toEqual(7)
})

test(`${permission} key: search with pagination parameters: hitsPerPage at 0 and page at 1`, async () => {
const client = await getClient(permission)

const response = await client.index(index.uid).search('', {
hitsPerPage: 0,
page: 1,
})

expect(response.hits.length).toEqual(0)
expect(response.hitsPerPage).toEqual(0)
expect(response.page).toEqual(1)
expect(response.totalPages).toEqual(0)
expect(response.totalHits).toEqual(7)
})

test(`${permission} key: search with pagination parameters: hitsPerPage at 1 and page at 0`, async () => {
const client = await getClient(permission)

const response = await client.index(index.uid).search('', {
hitsPerPage: 1,
page: 0,
})

expect(response.hits.length).toEqual(0)
expect(response.hitsPerPage).toEqual(1)
expect(response.page).toEqual(0)
expect(response.totalPages).toEqual(7)
expect(response.totalHits).toEqual(7)
})

test(`${permission} key: search with pagination parameters: hitsPerPage at 0 and page at 0`, async () => {
const client = await getClient(permission)

const response = await client.index(index.uid).search('', {
hitsPerPage: 0,
page: 0,
})

expect(response.hits.length).toEqual(0)
expect(response.hitsPerPage).toEqual(0)
expect(response.page).toEqual(0)
expect(response.totalPages).toEqual(0)
expect(response.totalHits).toEqual(7)
})

test(`${permission} key: search with pagination parameters hitsPerPage/page and offset/limit`, async () => {
const client = await getClient(permission)

const response = await client.index(index.uid).search('', {
hitsPerPage: 1,
page: 1,
offset: 1,
limit: 1,
})

expect(response.hits.length).toEqual(1)
expect(response.limit).toEqual(1)
expect(response.offset).toEqual(1)
expect(response.estimatedTotalHits).toEqual(7)
})

test(`${permission} key: search with pagination parameters hitsPerPage/page and offset`, async () => {
const client = await getClient(permission)

const response = await client.index(index.uid).search('', {
hitsPerPage: 1,
page: 1,
limit: 1,
})

expect(response.hits.length).toEqual(1)
expect(response.limit).toEqual(1)
expect(response.offset).toEqual(0)
expect(response.estimatedTotalHits).toEqual(7)
})

test(`${permission} key: search with pagination parameters hitsPerPage/page and offset`, async () => {
const client = await getClient(permission)

const response = await client.index(index.uid).search('', {
hitsPerPage: 1,
page: 1,
offset: 1,
})

expect(response.hits.length).toEqual(6)
expect(response.limit).toEqual(20)
expect(response.offset).toEqual(1)
expect(response.estimatedTotalHits).toEqual(7)
})

test(`${permission} key: search on index with no documents and no primary key`, async () => {
const client = await getClient(permission)
const response = await client.index(emptyIndex.uid).search('prince', {})
expect(response).toHaveProperty('hits', [])
expect(response).toHaveProperty('offset', 0)
expect(response).toHaveProperty('limit', 20)
expect(response).toHaveProperty('hitsPerPage', 20)
expect(response).toHaveProperty('page', 1)
expect(response).toHaveProperty('totalPages', 0)
expect(response).toHaveProperty('processingTimeMs', expect.any(Number))
expect(response).toHaveProperty('query', 'prince')
expect(response.hits.length).toEqual(0)
Expand All @@ -493,9 +617,11 @@ describe.each([
test(`${permission} key: search on index with no documents and no primary key`, async () => {
const client = await getClient(permission)
const response = await client.index(emptyIndex.uid).search('prince', {})

expect(response).toHaveProperty('hits', [])
expect(response).toHaveProperty('offset', 0)
expect(response).toHaveProperty('limit', 20)
expect(response).toHaveProperty('hitsPerPage', 20)
expect(response).toHaveProperty('page', 1)
expect(response).toHaveProperty('totalPages', 0)
expect(response).toHaveProperty('processingTimeMs', expect.any(Number))
expect(response).toHaveProperty('query', 'prince')
expect(response.hits.length).toEqual(0)
Expand Down
Loading