Skip to content

Commit

Permalink
feat: add dirty values parameter for single document indexing
Browse files Browse the repository at this point in the history
- add `dirty_values` parameter for .Create, .Upsert and .Update methods
- pull latest oapi-spec changes
  • Loading branch information
haydenhoang committed Oct 3, 2024
1 parent 90638ca commit 77722d7
Show file tree
Hide file tree
Showing 14 changed files with 139 additions and 91 deletions.
6 changes: 6 additions & 0 deletions typesense/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ func WithAPIKey(apiKey string) ClientOption {
return nil
}
}

// Manually defining this unreferenced schema here instead of disabling oapi-codegen schema pruning

type DocumentIndexParameters struct {
DirtyValues *DirtyValues `json:"dirty_values,omitempty"`
}
52 changes: 37 additions & 15 deletions typesense/api/client_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 12 additions & 5 deletions typesense/api/generator/generator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,8 @@ components:
type: string
project_id:
type: string
url:
type: string
required:
- model_name
type: object
Expand Down Expand Up @@ -2151,6 +2153,11 @@ paths:
required: true
schema:
type: string
- description: Dealing with Dirty Data
in: query
name: dirty_values
schema:
$ref: '#/components/schemas/DirtyValues'
requestBody:
content:
application/json:
Expand Down Expand Up @@ -2605,7 +2612,7 @@ paths:
summary: List all collection overrides
tags:
- documents
- promote
- curation
/collections/{collectionName}/overrides/{overrideId}:
delete:
operationId: deleteSearchOverride
Expand Down Expand Up @@ -2638,7 +2645,7 @@ paths:
summary: Delete an override associated with a collection
tags:
- documents
- promote
- curation
get:
description: Retrieve the details of a search override, given its id.
operationId: getSearchOverride
Expand Down Expand Up @@ -2705,7 +2712,7 @@ paths:
summary: Create or update an override to promote certain documents over others
tags:
- documents
- promote
- curation
/collections/{collectionName}/synonyms:
get:
operationId: getSearchSynonyms
Expand Down Expand Up @@ -3657,11 +3664,11 @@ tags:
description: Find out more
url: https://typesense.org/api/#index-document
name: documents
- description: Promote certain documents over others
- description: Hand-curate search results based on conditional business rules
externalDocs:
description: Find out more
url: https://typesense.org/docs/0.23.0/api/#curation
name: promote
name: curation
- description: Typesense can aggregate search queries for both analytics purposes and for query suggestions.
externalDocs:
description: Find out more
Expand Down
41 changes: 24 additions & 17 deletions typesense/api/generator/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ tags:
externalDocs:
description: Find out more
url: https://typesense.org/api/#index-document
- name: promote
description: Promote certain documents over others
- name: curation
description: Hand-curate search results based on conditional business rules
externalDocs:
description: Find out more
url: https://typesense.org/docs/0.23.0/api/#curation
Expand Down Expand Up @@ -412,7 +412,7 @@ paths:
get:
tags:
- documents
- promote
- curation
summary: List all collection overrides
operationId: getSearchOverrides
parameters:
Expand Down Expand Up @@ -460,7 +460,7 @@ paths:
put:
tags:
- documents
- promote
- curation
summary: Create or update an override to promote certain documents over others
description:
Create or update an override to promote certain documents over others.
Expand Down Expand Up @@ -502,7 +502,7 @@ paths:
delete:
tags:
- documents
- promote
- curation
summary: Delete an override associated with a collection
operationId: deleteSearchOverride
parameters:
Expand Down Expand Up @@ -842,6 +842,11 @@ paths:
required: true
schema:
type: string
- name: dirty_values
in: query
description: Dealing with Dirty Data
schema:
$ref: "#/components/schemas/DirtyValues"
requestBody:
description: The document object with fields to be updated
content:
Expand Down Expand Up @@ -1784,12 +1789,12 @@ components:
maxLength: 1
default: []
enable_nested_fields:
type: boolean
description:
Enables experimental support at a collection level for nested object or object array fields.
This field is only available if the Typesense server is version `0.24.0.rcn34` or later.
default: false
example: true
type: boolean
description:
Enables experimental support at a collection level for nested object or object array fields.
This field is only available if the Typesense server is version `0.24.0.rcn34` or later.
default: false
example: true
symbols_to_index:
type: array
description: >
Expand Down Expand Up @@ -1919,6 +1924,8 @@ components:
type: string
api_key:
type: string
url:
type: string
access_token:
type: string
client_id:
Expand Down Expand Up @@ -2436,8 +2443,8 @@ components:
If infix index is enabled for this field, infix searching can be done on a per-field
basis by sending a comma separated string parameter called infix to the search query.
This parameter can have 3 values; `off` infix search is disabled, which is default
`always` infix search is performed along with regular search
`fallback` infix search is performed if regular search does not produce results
`always` infix search is performed along with regular search
`fallback` infix search is performed if regular search does not produce results
type: string

max_extra_prefix:
Expand Down Expand Up @@ -2773,7 +2780,7 @@ components:
type: boolean
conversation_model_id:
description: >
The Id of Conversation Model to be used.
The Id of Conversation Model to be used.
type: string
conversation_id:
description: >
Expand Down Expand Up @@ -2821,8 +2828,8 @@ components:
If infix index is enabled for this field, infix searching can be done on a per-field
basis by sending a comma separated string parameter called infix to the search query.
This parameter can have 3 values; `off` infix search is disabled, which is default
`always` infix search is performed along with regular search
`fallback` infix search is performed if regular search does not produce results
`always` infix search is performed along with regular search
`fallback` infix search is performed if regular search does not produce results
type: string

max_extra_prefix:
Expand Down Expand Up @@ -3143,7 +3150,7 @@ components:
type: boolean
conversation_model_id:
description: >
The Id of Conversation Model to be used.
The Id of Conversation Model to be used.
type: string
conversation_id:
description: >
Expand Down
7 changes: 7 additions & 0 deletions typesense/api/types_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions typesense/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import (
"encoding/json"
"io"
"strings"

"github.com/typesense/typesense-go/v2/typesense/api"
)

type DocumentInterface[T any] interface {
Retrieve(ctx context.Context) (T, error)
Update(ctx context.Context, document any) (T, error)
Update(ctx context.Context, document any, params *api.DocumentIndexParameters) (T, error)
Delete(ctx context.Context) (T, error)
}

Expand Down Expand Up @@ -39,9 +41,9 @@ func (d *document[T]) Retrieve(ctx context.Context) (resp T, err error) {
return resp, nil
}

func (d *document[T]) Update(ctx context.Context, document any) (resp T, err error) {
func (d *document[T]) Update(ctx context.Context, document any, params *api.DocumentIndexParameters) (resp T, err error) {
response, err := d.apiClient.UpdateDocument(ctx,
d.collectionName, d.documentID, document)
d.collectionName, d.documentID, &api.UpdateDocumentParams{DirtyValues: params.DirtyValues}, document)
if err != nil {
return resp, err
}
Expand Down
Loading

0 comments on commit 77722d7

Please sign in to comment.