meilisearch/meilisearch-http/src
bors[bot] 25ec51e783
Merge #2601
2601: Ease search result pagination r=Kerollmops a=ManyTheFish

# Summary
This PR is a prototype enhancing search results pagination (#2577)

# Todo

- [x] Update the API to return the number of pages and allow users to directly choose a page instead of computing an offset
- [x] Change computation of `total_pages` in order to have an exact count
  - [x] compute query tree exhaustively
  - [x] compute distinct exhaustively

# Small Documentation

## Default search query

**request**:
```sh
curl \
  -X POST 'http://localhost:7700/indexes/movies/search' \
  -H 'Content-Type: application/json' \
  --data-binary '{ "q": "botman" }'
```

**result**:
```json
{
  "hits":[...],
  "query":"botman",
  "processingTimeMs":5,
  "hitsPerPage":20,
  "page":1,
  "totalPages":4,
  "totalHits":66
}
```

## Search query with offset parameter

**request**:
```sh
curl \
  -X POST 'http://localhost:7700/indexes/movies/search' \
  -H 'Content-Type: application/json' \
  --data-binary '{ "q": "botman", "offset": 0 }'
```

**result**:
```json
{
  "hits":[...],
  "query":"botman",
  "processingTimeMs":3,
  "limit":20,
  "offset":0,
  "estimatedTotalHits":66
}
```

## Search query selecting page with page parameter

**request**:
```sh
curl \
  -X POST 'http://localhost:7700/indexes/movies/search' \
  -H 'Content-Type: application/json' \
  --data-binary '{ "q": "botman", "page": 2 }'
```

**result**:
```json
{
  "hits":[...],
  "query":"botman",
  "processingTimeMs":5,
  "hitsPerPage":20,
  "page":2,
  "totalPages":4,
  "totalHits":66
}
```

# Related

fixes #2577

## In charge of the feature

Core: `@ManyTheFish` 
Docs: `@guimachiavelli` 
Integration: `@bidoubiwa` 


Co-authored-by: ManyTheFish <many@meilisearch.com>
2022-10-26 16:10:58 +00:00
..
analytics Add is_finite_pagination method to SearchQuery 2022-10-26 18:08:29 +02:00
extractors Added support for encoded payload 2022-10-09 22:09:30 +02:00
routes Fix the tests 2022-10-20 17:41:13 +02:00
error.rs Add a new meilisearch_types crate 2022-06-09 16:14:13 +02:00
lib.rs move prometheus behind a feature flag 2022-08-29 14:36:59 +02:00
main.rs Add quotes around file name and change error message 2022-09-22 09:44:28 +02:00
metrics.rs cargo fmt 2022-08-23 17:17:02 +02:00
option.rs Change err mess for config 2022-10-25 16:16:34 +05:30
route_metrics.rs move prometheus behind a feature flag 2022-08-29 14:36:59 +02:00
task.rs Rename receivedDocumentIds into matchedDocuments 2022-10-01 21:59:20 +02:00