Skip to content

Commit 7a43625

Browse files
bors[bot]alallema
andauthored
Merge #150
150: Rewrite client r=alallema a=alallema **Description** Start of SDK go modification: - Rewriting of the Client that implements this method: - Index(uid string) - GetIndex(indexID string) - GetAllIndexes() - CreateIndex(config IndexConfig) - GetOrCreateIndex(config IndexConfig) - GetKeys() - GetAllStats() - CreateDump() - GetDumpStatus(dumpUID string) - Version() - GetVersion() - Health() - IsHealthy() - DeleteIndex(uid string) - Rewriting of the Index that implements this method: - FetchInfo() - FetchPrimaryKey() - ChangePrimaryKey() - Delete() - AddDocuments() - UpdateDocuments() - GetDocument() - GetDocuments() - DeleteOneDocument() - DeletesDocuments() - DeleteAllDocuments() - GetAllUpdateStatus() - GetUpdateStatus() - Search() - GetSettings() - UpdateSettings() - ResetSettings() - GetStats() - WaitForPendingUpdate() - DefaultWaitForPendingUpdate() - Removing of intermediates interfaces - Rewriting of sample and Readme for the new usage - Add tests for every method **To do** - Client - [x] Rewrite Client - [x] Add Test to Client - Index - [x] Rewrite Index - [x] Add Tests to Index - [x] Adding test for `WaitForPendingUpdate()` Issue [related](meilisearch/integration-guides#1) - [x] Rewrite Document - [x] Add Tests to Document - [x] Rewrite Search - [x] Add Tests Search - [x] Rewrite Settings - [x] Add Tests Settings Co-authored-by: alallema <[email protected]>
2 parents 4b4af89 + a12b625 commit 7a43625

37 files changed

+5730
-3298
lines changed

.code-samples.meilisearch.yaml

Lines changed: 98 additions & 86 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -67,43 +67,36 @@ NB: you can also download MeiliSearch from **Homebrew** or **APT**.
6767
package main
6868

6969
import (
70-
"fmt"
71-
"os"
70+
"fmt"
71+
"os"
7272

73-
"github.com/meilisearch/meilisearch-go"
73+
"github.com/meilisearch/meilisearch-go"
7474
)
7575

7676
func main() {
77-
var client = meilisearch.NewClient(meilisearch.Config{
78-
Host: "http://127.0.0.1:7700",
79-
APIKey: "masterKey",
80-
})
81-
82-
// Create an index if your index does not already exist
83-
_, err := client.Indexes().Create(meilisearch.CreateIndexRequest{
84-
UID: "books",
85-
})
86-
if err != nil {
87-
fmt.Println(err)
88-
os.Exit(1)
89-
}
90-
91-
documents := []map[string]interface{}{
92-
{"book_id": 123, "title": "Pride and Prejudice"},
93-
{"book_id": 456, "title": "Le Petit Prince"},
94-
{"book_id": 1, "title": "Alice In Wonderland"},
95-
{"book_id": 1344, "title": "The Hobbit"},
96-
{"book_id": 4, "title": "Harry Potter and the Half-Blood Prince"},
97-
{"book_id": 42, "title": "The Hitchhiker's Guide to the Galaxy"},
98-
}
99-
100-
updateRes, err := client.Documents("books").AddOrUpdate(documents) // => { "updateId": 0 }
101-
if err != nil {
102-
fmt.Println(err)
103-
os.Exit(1)
104-
}
105-
106-
fmt.Println(updateRes.UpdateID)
77+
client := meilisearch.NewClient(meilisearch.ClientConfig{
78+
Host: "http://127.0.0.1:7700",
79+
MasterKey: "masterKey",
80+
})
81+
// An index is where the documents are stored.
82+
index := client.Index("indexUID")
83+
84+
// If the index 'books' does not exist, MeiliSearch creates it when you first add the documents.
85+
documents := []map[string]interface{}{
86+
{"book_id": 123, "title": "Pride and Prejudice"},
87+
{"book_id": 456, "title": "Le Petit Prince"},
88+
{"book_id": 1, "title": "Alice In Wonderland"},
89+
{"book_id": 1344, "title": "The Hobbit"},
90+
{"book_id": 4, "title": "Harry Potter and the Half-Blood Prince"},
91+
{"book_id": 42, "title": "The Hitchhiker's Guide to the Galaxy"},
92+
}
93+
update, err := index.AddDocuments(documents)
94+
if err != nil {
95+
fmt.Println(err)
96+
os.Exit(1)
97+
}
98+
99+
fmt.Println(update.UpdateID)
107100
}
108101
```
109102

@@ -123,7 +116,7 @@ import (
123116

124117
func main() {
125118
// MeiliSearch is typo-tolerant:
126-
searchRes, err := client.Search("books").Search(meilisearch.SearchRequest{
119+
searchRes, err := client.Index("books").Search(meilisearch.SearchRequest{
127120
Query: "harry pottre",
128121
Limit: 10,
129122
})
@@ -156,7 +149,7 @@ All the supported options are described in the [search parameters](https://docs.
156149

157150
```go
158151
func main() {
159-
resp, err := client.Search(indexUID).Search(meilisearch.SearchRequest{
152+
resp, err := client.Index("books").Search(meilisearch.SearchRequest{
160153
Query: "prince",
161154
AttributesToHighlight: []string{"*"},
162155
Filters: "book_id > 10"
@@ -201,7 +194,7 @@ The following sections may interest you:
201194
- **Manipulate documents**: see the [API references](https://docs.meilisearch.com/reference/api/documents.html) or read more about [documents](https://docs.meilisearch.com/learn/core_concepts/documents.html).
202195
- **Search**: see the [API references](https://docs.meilisearch.com/reference/api/search.html) or follow our guide on [search parameters](https://docs.meilisearch.com/reference/features/search_parameters.html).
203196
- **Manage the indexes**: see the [API references](https://docs.meilisearch.com/reference/api/indexes.html) or read more about [indexes](https://docs.meilisearch.com/learn/core_concepts/indexes.html).
204-
- **Configure the index settings**: see the [API references](https://docs.meilisearch.com/reference/api/settings.html) or follow our guide on [settings parameters](https://docs.meilisearch.com/reference/features/settings.html).
197+
- **ClientConfigure the index settings**: see the [API references](https://docs.meilisearch.com/reference/api/settings.html) or follow our guide on [settings parameters](https://docs.meilisearch.com/reference/features/settings.html).
205198

206199
## ⚙️ Development Workflow and Contributing
207200

apis.go

Lines changed: 0 additions & 206 deletions
This file was deleted.

0 commit comments

Comments
 (0)