Skip to content

Commit

Permalink
chore: add index create
Browse files Browse the repository at this point in the history
  • Loading branch information
henomis committed Sep 23, 2023
1 parent 931c2e9 commit 599b9e4
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ This is [Qdrant](https://qdrant.tech/)'s **unofficial** Go client, designed to e
- ✅ update
- ✅ delete
- ❌ update aliases
- create index
- create index
- ❌ delete index
- ❌ cluster info
- ❌ update cluster setup
Expand Down
8 changes: 8 additions & 0 deletions qdrantgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ func (c *Client) CollectionUpdate(
return c.restClient.Patch(ctx, req, res)
}

func (c *Client) IndexCreate(
ctx context.Context,
req *request.IndexCreate,
res *response.IndexCreate,
) error {
return c.restClient.Put(ctx, req, res)
}

func (c *Client) PointUpsert(
ctx context.Context,
req *request.PointUpsert,
Expand Down
44 changes: 44 additions & 0 deletions request/indexCreate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package request

import (
"bytes"
"encoding/json"
"fmt"
"io"

"github.com/henomis/restclientgo"
)

type IndexCreate struct {
CollectionName string `json:"-"`
Wait *bool `json:"-"`
Ordering *Ordering `json:"-"`
FieldName string `json:"field_name"`
FieldSchema any `json:"field_schema,omitempty"`
}

func (c *IndexCreate) Path() (string, error) {
var urlValues restclientgo.URLValues
urlValues.AddBool("timeout", c.Wait)
urlValues.Add("ordering", (*string)(c.Ordering))

parameters := ""
if len(urlValues) > 0 {
parameters = "?" + urlValues.Encode()
}

return fmt.Sprintf("/collections/%s%s", c.CollectionName, parameters), nil
}

func (c *IndexCreate) Encode() (io.Reader, error) {
jsonBytes, err := json.Marshal(c)
if err != nil {
return nil, err
}

return bytes.NewReader(jsonBytes), nil
}

func (c *IndexCreate) ContentType() string {
return "application/json"
}
19 changes: 19 additions & 0 deletions response/indexCreate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package response

import (
"encoding/json"
"io"
)

type IndexCreate struct {
Response
Result OperationResult `json:"result"`
}

func (c *IndexCreate) AcceptContentType() string {
return "application/json"
}

func (c *IndexCreate) Decode(body io.Reader) error {
return json.NewDecoder(body).Decode(c)
}
2 changes: 1 addition & 1 deletion response/pointDelete.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

type PointDelete struct {
Response
Result PointOperationResult `json:"result"`
Result OperationResult `json:"result"`
}

func (p *PointDelete) AcceptContentType() string {
Expand Down
14 changes: 7 additions & 7 deletions response/pointUpsert.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ import (

type PointUpsert struct {
Response
Result PointOperationResult `json:"result"`
Result OperationResult `json:"result"`
}

type PointOperationResultStatus string
type OperationResultStatus string

const (
PointOperationResultStatusAcknowledged PointOperationResultStatus = "acknowledged"
PointOperationResultStatusCompleted PointOperationResultStatus = "completed"
PointOperationResultStatusAcknowledged OperationResultStatus = "acknowledged"
PointOperationResultStatusCompleted OperationResultStatus = "completed"
)

type PointOperationResult struct {
OperationID uint64 `json:"operation_id"`
Status PointOperationResultStatus `json:"status"`
type OperationResult struct {
OperationID uint64 `json:"operation_id"`
Status OperationResultStatus `json:"status"`
}

func (p *PointUpsert) AcceptContentType() string {
Expand Down

0 comments on commit 599b9e4

Please sign in to comment.