Skip to content

Commit 518cc19

Browse files
bors[bot]bidoubiwa
andauthored
Merge #193
193: Lazy index r=bidoubiwa a=bidoubiwa # Breaking changes: ## Index is now a public Class required for most of the indexes related methods In MeiliSearch some actions are about to the whole instance. For example `GET /stats` but most are specific actions on indexes, for exemple `GET indexes/myIndex/documents`. All specific actions linked to an index are now available through an instance of the `Indexes` class. ### Before ```swift client.addDocuments(documents) ``` ### After Now, these methods are only available in the `Indexes` class. ```swift let index = client.index("myIndex") index.getDocuments(). ``` Or ```swift client.index(myIndex").getDocuments() ``` The following method are still available in a Client instance and return an `Index` instance: - `client.index("myIndex")` - `createIndex(uid: "myIndex")` - `getOrCreateIndex(uid: "myIndex")` - `getindex("myIndex")` - `getindexes("myIndex")` -> returns an array of Indexes() ## Breaking methods Every method related to a specific `index` are now only available in an Index instance. These are the methods that you will not find on a `Client` instance anymore: - `client.index("myIndex").addDocuments` - `client.index("myIndex").updateDocuments` - `client.index("myIndex").updateDocuments` - `client.index("myIndex").getDocument` - `client.index("myIndex").getDocument` - `client.index("myIndex").getDocuments` - `client.index("myIndex").deleteDocument` - `client.index("myIndex").deleteAllDocuments` - `client.index("myIndex").deleteBatchDocuments` - `client.index("myIndex").search` - `client.index("myIndex").getUpdate` - `client.index("myIndex").getAllUpdates` - `client.index("myIndex").waitForPendingUpdate` - `client.index("myIndex").getSettings` - `client.index("myIndex").updateSettings` - `client.index("myIndex").resetSettings` - `client.index("myIndex").getSynonyms` - `client.index("myIndex").updateSynonyms` - `client.index("myIndex").resetSynonyms` - `client.index("myIndex").getStopWords` - `client.index("myIndex").updateStopWords` - `client.index("myIndex").resetStopWords` - `client.index("myIndex").getRankingRules` - `client.index("myIndex").updateRankingRules` - `client.index("myIndex").resetRankingRules` - `client.index("myIndex").getDistinctAttribute` - `client.index("myIndex").updateDistinctAttribute` - `client.index("myIndex").resetDistinctAttribute` - `client.index("myIndex").getSearchableAttributes` - `client.index("myIndex").updateSearchableAttributes` - `client.index("myIndex").resetSearchableAttributes` - `client.index("myIndex").getDisplayedAttributes` - `client.index("myIndex").updateDisplayedAttributes` - `client.index("myIndex").resetDisplayedAttributes` - `client.index("myIndex").getFilterableAttributes` - `client.index("myIndex").updateFilterableAttributes` - `client.index("myIndex").resetFilterableAttributes` - `client.index("myIndex").getSortableAttributes` - `client.index("myIndex").updateSortableAttributes` - `client.index("myIndex").resetSortableAttributes` - `client.index("myIndex").stats` ## Parameters label removed/added/renamed Some method saw there parameter declaration changed to make the usage more explicit and to add some needed data. Example: `createIndex(UID: String, _ completion: ...)` Became: `createIndex(uid: String, primaryKey: String? = nil, _ completion: ...)` All required `UID` labels became `uid`. As seen in the example above. Co-authored-by: Charlotte Vermandel <charlottevermandel@gmail.com> Co-authored-by: cvermand <33010418+bidoubiwa@users.noreply.github.com>
2 parents 8cb0cce + b638439 commit 518cc19

40 files changed

+1590
-2382
lines changed

.code-samples.meilisearch.yaml

Lines changed: 124 additions & 117 deletions
Large diffs are not rendered by default.

Demos/PerfectDemo/Sources/PerfectTemplate/main.swift

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@ private struct Movie: Codable, Equatable {
3232
let title: String
3333
let comment: String?
3434

35-
enum CodingKeys: String, CodingKey {
36-
case id
37-
case title
38-
case comment
39-
}
40-
4135
init(id: Int, title: String, comment: String? = nil) {
4236
self.id = id
4337
self.title = title
@@ -62,7 +56,7 @@ func index(request: HTTPRequest, response: HTTPResponse) {
6256
return
6357
}
6458

65-
client.getIndex(UID: uid) { result in
59+
client.getIndex(uid) { result in
6660

6761
switch result {
6862
case .success(let index):
@@ -112,7 +106,7 @@ func search(request: HTTPRequest, response: HTTPResponse) {
112106

113107
let searchParameters = SearchParameters.query(query)
114108

115-
client.search(UID: "books_test", searchParameters) { (result: Result<SearchResult<Movie>, Swift.Error>) in
109+
client.index("books_test").search(searchParameters) { (result: Result<SearchResult<Movie>, Swift.Error>) in
116110

117111
switch result {
118112
case .success(let searchResult):

Demos/VaporDemo/Sources/App/routes.swift

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@ private struct Movie: Codable, Equatable {
99
let title: String
1010
let comment: String?
1111

12-
enum CodingKeys: String, CodingKey {
13-
case id
14-
case title
15-
case comment
16-
}
17-
1812
init(id: Int, title: String, comment: String? = nil) {
1913
self.id = id
2014
self.title = title
@@ -43,7 +37,7 @@ func routes(_ app: Application) throws {
4337
return
4438
}
4539

46-
client.getIndex(UID: uid) { result in
40+
client.getIndex(uid) { result in
4741

4842
switch result {
4943
case .success(let index):
@@ -83,7 +77,7 @@ func routes(_ app: Application) throws {
8377

8478
let searchParameters = SearchParameters.query(query)
8579

86-
client.search(UID: "movies", searchParameters) { (result: Result<SearchResult<Movie>, Swift.Error>) in
80+
client.index("movies").search(searchParameters) { (result: Result<SearchResult<Movie>, Swift.Error>) in
8781
switch result {
8882
case .success(let searchResult):
8983
if let jsonData = try? JSONSerialization.data(withJSONObject: searchResult.hits, options: []) {

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,10 @@ To do a simply search using the client, you can create a Swift script like this:
117117

118118
// An index is where the documents are stored.
119119
// The uid is the unique identifier to that index.
120-
let indexUid = "movies"
120+
let index = client.index("movies")
121121

122122
// If the index 'movies' does not exist, MeiliSearch creates it when you first add the documents.
123-
client.addDocuments(
124-
UID: indexUid,
123+
client.index.addDocuments(
125124
documents: movies,
126125
primaryKey: nil
127126
) { result in
@@ -139,6 +138,7 @@ To do a simply search using the client, you can create a Swift script like this:
139138
With the `updateId`, you can check the status (`enqueued`, `processing`, `processed` or `failed`) of your documents addition using the [update endpoint](https://docs.meilisearch.com/reference/api/updates.html#get-an-update-status).
140139

141140
#### Basic Search <!-- omit in toc -->
141+
142142
```swift
143143

144144
let semaphore = DispatchSemaphore(value: 0)
@@ -147,7 +147,7 @@ let semaphore = DispatchSemaphore(value: 0)
147147
typealias MeiliResult = Result<SearchResult<Movie>, Swift.Error>
148148

149149
// Call the function search and wait for the closure result.
150-
client.search(UID: "movies", SearchParameters( query: "philoudelphia" )) { (result: MeiliResult) in
150+
client.index("movies").search(SearchParameters( query: "philoudelphia" )) { (result: MeiliResult) in
151151
switch result {
152152
case .success(let searchResult):
153153
dump(searchResult)
@@ -208,8 +208,8 @@ If you want to know more about the development workflow or want to contribute, p
208208

209209
To try out a demo you will need to go to its directory in `Demos/`. In that directory you can either:
210210

211-
- Open the SwiftPM project in Xcode and press run, or
212-
- Run `swift build` or `swift run` in the terminal.
211+
- Open the SwiftPM project in Xcode and press run, or
212+
- Run `swift build` or `swift run` in the terminal.
213213

214214
### Vapor <!-- omit in toc -->
215215

0 commit comments

Comments
 (0)