Skip to content

Commit 6fc2b51

Browse files
meili-bors[bot]samuele ruffinoStrift
authored
Merge #822
822: docs: update README with SDK changes and add pagination examples r=Strift a=samuele-ruffino96 # Pull Request ## What does this PR do? - Updates the README example code to show the necessity to cast the returned value (new `Searchable` interface) to `SearchResult` - Adds a new comprehensive example demonstrating custom search with pagination - Shows practical usage of pagination parameters like `setPage()` and `setHitsPerPage()` - Includes example JSON response showing pagination metadata (totalPages, hitsPerPage, etc.) ## PR checklist - [x] Changes are clearly described in the PR description above - [ ] Contributing guidelines have been reviewed (needs confirmer) - [x] PR title accurately describes changes: "fix(docs): update README example to reflect latest sdk changes" Co-authored-by: samuele ruffino <[email protected]> Co-authored-by: Laurent Cazanove <[email protected]>
2 parents 67cb005 + cebee92 commit 6fc2b51

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

README.md

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,10 @@ import com.meilisearch.sdk.SearchRequest;
147147

148148
// ...
149149

150-
SearchResult results = index.search(
151-
new SearchRequest("of")
152-
.setShowMatchesPosition(true)
153-
.setAttributesToHighlight(new String[]{"title"})
150+
SearchResult results = (SearchResult) index.search(
151+
new SearchRequest("of")
152+
.setShowMatchesPosition(true)
153+
.setAttributesToHighlight(new String[]{"title"})
154154
);
155155
System.out.println(results.getHits());
156156
```
@@ -216,6 +216,38 @@ index.search(
216216
"query": "wonder"
217217
}
218218
```
219+
#### Custom Search With Pagination <!-- omit in toc -->
220+
221+
```java
222+
import com.meilisearch.sdk.SearchResultPaginated;
223+
224+
// ...
225+
226+
SearchResultPaginated results = (SearchResultPaginated) index.search(
227+
new SearchRequest("wonder")
228+
.setPage(1)
229+
.setHitsPerPage(20)
230+
);
231+
```
232+
233+
```json
234+
{
235+
"hits": [
236+
{
237+
"id": 2,
238+
"title": "Wonder Woman",
239+
"genres": ["Action","Adventure"]
240+
}
241+
],
242+
"query": "wonder",
243+
"processingTimeMs": 0,
244+
"hitsPerPage": 20,
245+
"page": 1,
246+
"totalPages": 1,
247+
"totalHits": 1
248+
}
249+
```
250+
219251
## 🛠 Customization
220252

221253
### JSON <!-- omit in toc -->

0 commit comments

Comments
 (0)