mirror of
https://github.com/hanzoai/search-go.git
synced 2026-10-30 18:22:58 +00:00
Review feedback from @ja7ad: "Why duplicate in index?" You're right - the method had no index scoping. Looking at the existing API shape: `GetTask(taskUID)` on `*index` also just forwards to the top-level client (no scoping), but `GetTasks` on `*index` genuinely differs (it sets `indexUids=<index.uid>` on the query). `GetTaskDocuments` falls in the first bucket - the task UID is globally unique, so there's no per-index variant worth adding. Changes: - `meilisearch_interface.go`: move `GetTaskDocuments` and `GetTaskDocumentsWithContext` from `TaskReader` into `TaskManager`. `TaskManager` is only implemented by the top-level `meilisearch` client (via `ServiceManager.TaskManager()`); `*index` only embeds `TaskReader`, so this automatically removes the method from the index surface without touching the index interface. - `index_task.go`: delete the `(*index).GetTaskDocuments` and `GetTaskDocumentsWithContext` method bodies. - `mocks/`: regenerated via `mockery` (v3.6.1). The method now lives on `MeilisearchTaskManager` and `MeilisearchServiceManager` mocks, and is gone from the `MeilisearchTaskReader` and `MeilisearchIndexManager` mocks. Integration test (`integration/index_task_test.go::TestGetTaskDocuments`) already exercised `sv.GetTaskDocuments(...)` on the top-level client, so no test change needed. Code sample (`.code-samples.meilisearch.yaml::get_task_documents_1`) already references `client.GetTaskDocuments(...)`. Verified: `go build ./...`, `go vet ./...`, `go test -count=1 -short .` all pass.
80 lines
2.2 KiB
Go
80 lines
2.2 KiB
Go
package meilisearch
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"strconv"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
func (i *index) GetTask(taskUID int64) (*Task, error) {
|
|
return i.GetTaskWithContext(context.Background(), taskUID)
|
|
}
|
|
|
|
func (i *index) GetTaskWithContext(ctx context.Context, taskUID int64) (*Task, error) {
|
|
return getTask(ctx, i.client, taskUID)
|
|
}
|
|
|
|
func (i *index) GetTasks(param *TasksQuery) (*TaskResult, error) {
|
|
return i.GetTasksWithContext(context.Background(), param)
|
|
}
|
|
|
|
func (i *index) GetTasksWithContext(ctx context.Context, param *TasksQuery) (*TaskResult, error) {
|
|
resp := new(TaskResult)
|
|
req := &internalRequest{
|
|
endpoint: "/tasks",
|
|
method: http.MethodGet,
|
|
withRequest: nil,
|
|
withResponse: resp,
|
|
withQueryParams: map[string]string{},
|
|
acceptedStatusCodes: []int{http.StatusOK},
|
|
functionName: "GetTasks",
|
|
}
|
|
if param != nil {
|
|
if param.Limit != 0 {
|
|
req.withQueryParams["limit"] = strconv.FormatInt(param.Limit, 10)
|
|
}
|
|
if param.From != 0 {
|
|
req.withQueryParams["from"] = strconv.FormatInt(param.From, 10)
|
|
}
|
|
if len(param.Statuses) != 0 {
|
|
statuses := make([]string, len(param.Statuses))
|
|
for i, status := range param.Statuses {
|
|
statuses[i] = string(status)
|
|
}
|
|
req.withQueryParams["statuses"] = strings.Join(statuses, ",")
|
|
}
|
|
|
|
if len(param.Types) != 0 {
|
|
types := make([]string, len(param.Types))
|
|
for i, t := range param.Types {
|
|
types[i] = string(t)
|
|
}
|
|
req.withQueryParams["types"] = strings.Join(types, ",")
|
|
}
|
|
if len(param.IndexUIDS) != 0 {
|
|
param.IndexUIDS = append(param.IndexUIDS, i.uid)
|
|
req.withQueryParams["indexUids"] = strings.Join(param.IndexUIDS, ",")
|
|
} else {
|
|
req.withQueryParams["indexUids"] = i.uid
|
|
}
|
|
|
|
if param.Reverse {
|
|
req.withQueryParams["reverse"] = "true"
|
|
}
|
|
}
|
|
if err := i.client.executeRequest(ctx, req); err != nil {
|
|
return nil, err
|
|
}
|
|
return resp, nil
|
|
}
|
|
|
|
func (i *index) WaitForTask(taskUID int64, interval time.Duration) (*Task, error) {
|
|
return waitForTask(context.Background(), i.client, taskUID, interval)
|
|
}
|
|
|
|
func (i *index) WaitForTaskWithContext(ctx context.Context, taskUID int64, interval time.Duration) (*Task, error) {
|
|
return waitForTask(ctx, i.client, taskUID, interval)
|
|
}
|