From b8d39b2b099d8c5842fd7c4d7911933f15953e40 Mon Sep 17 00:00:00 2001 From: Fanis Tharropoulos Date: Mon, 29 Dec 2025 14:49:33 +0200 Subject: [PATCH 1/2] chore: bump deps --- go.mod | 16 +++++++--------- go.sum | 12 ++++++++++++ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index b30c58c0..ee83e763 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,6 @@ module github.com/typesense/typesense-go/v4 -go 1.22 - -toolchain go1.23.5 +go 1.24.0 require ( github.com/google/uuid v1.6.0 @@ -56,12 +54,12 @@ require ( github.com/ugorji/go/codec v1.2.12 // indirect github.com/vmware-labs/yaml-jsonpath v0.3.2 // indirect go.opencensus.io v0.23.0 // indirect - golang.org/x/mod v0.18.0 // indirect - golang.org/x/net v0.26.0 // indirect - golang.org/x/sync v0.8.0 // indirect - golang.org/x/sys v0.21.0 // indirect - golang.org/x/text v0.18.0 // indirect - golang.org/x/tools v0.22.0 // indirect + golang.org/x/mod v0.31.0 // indirect + golang.org/x/net v0.48.0 // indirect + golang.org/x/sync v0.19.0 // indirect + golang.org/x/sys v0.39.0 // indirect + golang.org/x/text v0.32.0 // indirect + golang.org/x/tools v0.40.0 // indirect google.golang.org/genproto v0.0.0-20211208223120-3a66f561d7aa // indirect google.golang.org/grpc v1.43.0 // indirect google.golang.org/protobuf v1.31.0 // indirect diff --git a/go.sum b/go.sum index 10961cfe..f36e3875 100644 --- a/go.sum +++ b/go.sum @@ -801,6 +801,8 @@ golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0= golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.31.0 h1:HaW9xtz0+kOcWKwli0ZXy79Ix+UW/vOfmWI5QVd2tgI= +golang.org/x/mod v0.31.0/go.mod h1:43JraMp9cGx1Rx3AqioxrbrhNsLl2l/iNAvuBkrezpg= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -846,6 +848,8 @@ golang.org/x/net v0.0.0-20211108170745-6635138e15ea/go.mod h1:9nx3DQGgdP8bBQD5qx golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= +golang.org/x/net v0.48.0 h1:zyQRTTrjc33Lhh0fBgT/H3oZq9WuvRR5gPC70xpDiQU= +golang.org/x/net v0.48.0/go.mod h1:+ndRgGjkh8FGtu1w1FGbEC31if4VrNVMuKTgcAAnQRY= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -864,6 +868,8 @@ golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4= +golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -939,6 +945,8 @@ golang.org/x/sys v0.0.0-20211109184856-51b60fd695b3/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.39.0 h1:CvCKL8MeisomCi6qNZ+wbb0DN9E5AATixKsvNtMoMFk= +golang.org/x/sys v0.39.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -952,6 +960,8 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224= golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +golang.org/x/text v0.32.0 h1:ZD01bjUt1FQ9WJ0ClOL5vxgxOI/sVCNgX1YtKwcY0mU= +golang.org/x/text v0.32.0/go.mod h1:o/rUWzghvpD5TXrTIBuJU77MTaN0ljMWE47kxGJQ7jY= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -1007,6 +1017,8 @@ golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.22.0 h1:gqSGLZqv+AI9lIQzniJ0nZDRG5GBPsSi+DRNHWNz6yA= golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c= +golang.org/x/tools v0.40.0 h1:yLkxfA+Qnul4cs9QA3KnlFu0lVmd8JJfoq+E41uSutA= +golang.org/x/tools v0.40.0/go.mod h1:Ik/tzLRlbscWpqqMRjyWYDisX8bG13FrdXp3o4Sr9lc= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= From 1d87448ad72c2002af86400fec41a8899ecf99ec Mon Sep 17 00:00:00 2001 From: Fanis Tharropoulos Date: Mon, 29 Dec 2025 14:49:07 +0200 Subject: [PATCH 2/2] refactor: update client for API spec changes --- typesense/analytics_rule_test.go | 2 +- typesense/analytics_rules_test.go | 6 +- typesense/api/client_gen.go | 8 +- typesense/api/generator/generator.yml | 87 +++- typesense/api/generator/openapi.yml | 610 +++++++++++++------------- typesense/api/types_gen.go | 101 +++-- typesense/curation_set.go | 4 +- typesense/multi_search_test.go | 194 ++++++++ typesense/synonym_set.go | 4 +- typesense/test/analytics_rule_test.go | 4 +- typesense/test/dbhelpers_test.go | 4 +- typesense/test/multi_search_test.go | 79 ++++ 12 files changed, 718 insertions(+), 385 deletions(-) diff --git a/typesense/analytics_rule_test.go b/typesense/analytics_rule_test.go index 51b2ac14..4af44a1b 100644 --- a/typesense/analytics_rule_test.go +++ b/typesense/analytics_rule_test.go @@ -13,7 +13,7 @@ import ( func TestAnalyticsRuleRetrieve(t *testing.T) { expectedData := &api.AnalyticsRule{ Name: "test_rule", - Type: api.AnalyticsRuleTypeCounter, + Type: api.Counter, Collection: "test_collection", EventType: "click", Params: &api.AnalyticsRuleCreateParams{ diff --git a/typesense/analytics_rules_test.go b/typesense/analytics_rules_test.go index 52501a4a..49901432 100644 --- a/typesense/analytics_rules_test.go +++ b/typesense/analytics_rules_test.go @@ -15,7 +15,7 @@ func TestAnalyticsRulesRetrieve(t *testing.T) { expectedData := []*api.AnalyticsRule{ { Name: "test_rule_1", - Type: api.AnalyticsRuleTypeCounter, + Type: api.Counter, Collection: "test_collection", EventType: "click", Params: &api.AnalyticsRuleCreateParams{ @@ -54,7 +54,7 @@ func TestAnalyticsRulesCreate(t *testing.T) { createData := []*api.AnalyticsRuleCreate{ { Name: "test_rule", - Type: api.AnalyticsRuleCreateTypeCounter, + Type: api.Counter, Collection: "test_collection", EventType: "click", Params: &api.AnalyticsRuleCreateParams{ @@ -67,7 +67,7 @@ func TestAnalyticsRulesCreate(t *testing.T) { expectedData := []*api.AnalyticsRule{ { Name: "test_rule", - Type: api.AnalyticsRuleTypeCounter, + Type: api.Counter, Collection: "test_collection", EventType: "click", Params: &api.AnalyticsRuleCreateParams{ diff --git a/typesense/api/client_gen.go b/typesense/api/client_gen.go index 76132049..8886026a 100644 --- a/typesense/api/client_gen.go +++ b/typesense/api/client_gen.go @@ -8311,7 +8311,7 @@ func (r DeleteCurationSetResponse) StatusCode() int { type RetrieveCurationSetResponse struct { Body []byte HTTPResponse *http.Response - JSON200 *CurationSetRetrieveSchema + JSON200 *CurationSetSchema JSON404 *ApiResponse } @@ -9178,7 +9178,7 @@ func (r DeleteSynonymSetResponse) StatusCode() int { type RetrieveSynonymSetResponse struct { Body []byte HTTPResponse *http.Response - JSON200 *SynonymSetRetrieveSchema + JSON200 *SynonymSetSchema JSON404 *ApiResponse } @@ -11336,7 +11336,7 @@ func ParseRetrieveCurationSetResponse(rsp *http.Response) (*RetrieveCurationSetR switch { case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: - var dest CurationSetRetrieveSchema + var dest CurationSetSchema if err := json.Unmarshal(bodyBytes, &dest); err != nil { return nil, err } @@ -12505,7 +12505,7 @@ func ParseRetrieveSynonymSetResponse(rsp *http.Response) (*RetrieveSynonymSetRes switch { case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: - var dest SynonymSetRetrieveSchema + var dest SynonymSetSchema if err := json.Unmarshal(bodyBytes, &dest); err != nil { return nil, err } diff --git a/typesense/api/generator/generator.yml b/typesense/api/generator/generator.yml index 32c93459..f18ab5bc 100644 --- a/typesense/api/generator/generator.yml +++ b/typesense/api/generator/generator.yml @@ -126,12 +126,7 @@ components: rule_tag: type: string type: - enum: - - popular_queries - - nohits_queries - - counter - - log - type: string + $ref: '#/components/schemas/AnalyticsRuleType' required: - name - type @@ -157,6 +152,13 @@ components: weight: type: integer type: object + AnalyticsRuleType: + enum: + - popular_queries + - nohits_queries + - counter + - log + type: string AnalyticsRuleUpdate: description: Fields allowed to update on an analytics rule properties: @@ -607,8 +609,6 @@ components: required: - name type: object - CurationSetRetrieveSchema: - $ref: '#/components/schemas/CurationSetCreateSchema' CurationSetSchema: allOf: - $ref: '#/components/schemas/CurationSetCreateSchema' @@ -672,6 +672,10 @@ components: type: object Field: properties: + async_reference: + description: | + Allow documents to be indexed successfully even when the referenced document doesn't exist yet. + type: boolean drop: example: true type: boolean @@ -1071,14 +1075,51 @@ components: properties: conversation: $ref: '#/components/schemas/SearchResultConversation' - results: + facet_counts: items: - $ref: '#/components/schemas/MultiSearchResultItem' + $ref: '#/components/schemas/FacetCounts' + type: array + found: + description: The number of documents found + type: integer + found_docs: + type: integer + grouped_hits: + items: + $ref: '#/components/schemas/SearchGroupedHit' type: array hits: + description: The documents that matched the search query items: $ref: '#/components/schemas/SearchResultHit' type: array + metadata: + additionalProperties: true + description: Custom JSON object that can be returned in the search response + type: object + out_of: + description: The total number of documents in the collection + type: integer + page: + description: The search result page number + type: integer + request_params: + $ref: '#/components/schemas/SearchRequestParams' + results: + items: + $ref: '#/components/schemas/MultiSearchResultItem' + type: array + search_cutoff: + description: Whether the search was cut off + type: boolean + search_time_ms: + description: The number of milliseconds the search took + type: integer + union_request_params: + description: Returned only for union query response. + items: + $ref: '#/components/schemas/SearchRequestParams' + type: array required: - results type: object @@ -1867,10 +1908,17 @@ components: - id type: object SynonymItemSchema: + allOf: + - properties: + id: + description: Unique identifier for the synonym item + type: string + required: + - id + type: object + - $ref: '#/components/schemas/SynonymItemUpsertSchema' + SynonymItemUpsertSchema: properties: - id: - description: Unique identifier for the synonym item - type: string locale: description: Locale for the synonym, leave blank to use the standard tokenizer type: string @@ -1888,7 +1936,6 @@ components: type: string type: array required: - - id - synonyms type: object SynonymSetCreateSchema: @@ -1909,8 +1956,6 @@ components: required: - name type: object - SynonymSetRetrieveSchema: - $ref: '#/components/schemas/SynonymSetCreateSchema' SynonymSetSchema: allOf: - $ref: '#/components/schemas/SynonymSetCreateSchema' @@ -2183,7 +2228,7 @@ paths: oneOf: - $ref: '#/components/schemas/AnalyticsRule' - items: - anyOf: + oneOf: - $ref: '#/components/schemas/AnalyticsRule' - properties: error: @@ -3166,7 +3211,7 @@ paths: application/json: schema: $ref: '#/components/schemas/SuccessStatus' - description: Compacting the on-disk database succeeded. + description: Toggle Slow Request Log database succeeded. summary: Toggle Slow Request Log tags: - operations @@ -3337,7 +3382,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/CurationSetRetrieveSchema' + $ref: '#/components/schemas/CurationSetSchema' description: Curation set fetched "404": content: @@ -4561,7 +4606,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/SynonymSetRetrieveSchema' + $ref: '#/components/schemas/SynonymSetSchema' description: Synonym set fetched "404": content: @@ -4719,7 +4764,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/SynonymItemSchema' + $ref: '#/components/schemas/SynonymItemUpsertSchema' description: The synonym item to be created/updated required: true responses: diff --git a/typesense/api/generator/openapi.yml b/typesense/api/generator/openapi.yml index 05af32d5..ee31a255 100644 --- a/typesense/api/generator/openapi.yml +++ b/typesense/api/generator/openapi.yml @@ -2,7 +2,7 @@ openapi: 3.0.3 info: title: Typesense API description: "An open source search engine for building delightful search experiences." - version: '30.0' + version: "30.0" license: name: GPL-3.0 url: https://opensource.org/licenses/GPL-3.0 @@ -91,8 +91,7 @@ paths: tags: - collections summary: List all collections - description: - Returns a summary of all your collections. The collections are + description: Returns a summary of all your collections. The collections are returned sorted by creation date, with the most recent collections appearing first. operationId: getCollections @@ -114,7 +113,7 @@ paths: description: Identifies the starting point to return collections when paginating. type: integer responses: - '200': + "200": description: List of all collections content: application/json: @@ -127,8 +126,7 @@ paths: tags: - collections summary: Create a new collection - description: - When a collection is created, we give it a name and describe the + description: When a collection is created, we give it a name and describe the fields that will be indexed from the documents added to the collection. operationId: createCollection requestBody: @@ -139,19 +137,19 @@ paths: $ref: "#/components/schemas/CollectionSchema" required: true responses: - '201': + "201": description: Collection successfully created content: application/json: schema: $ref: "#/components/schemas/CollectionResponse" - '400': + "400": description: Bad request, see error message for details content: application/json: schema: $ref: "#/components/schemas/ApiResponse" - '409': + "409": description: Collection already exists content: application/json: @@ -172,13 +170,13 @@ paths: schema: type: string responses: - '200': + "200": description: Collection fetched content: application/json: schema: $ref: "#/components/schemas/CollectionResponse" - '404': + "404": description: Collection not found content: application/json: @@ -188,8 +186,7 @@ paths: tags: - collections summary: Update a collection - description: - Update a collection's schema to modify the fields and their types. + description: Update a collection's schema to modify the fields and their types. operationId: updateCollection parameters: - name: collectionName @@ -206,19 +203,19 @@ paths: $ref: "#/components/schemas/CollectionUpdateSchema" required: true responses: - '200': + "200": description: The updated partial collection schema content: application/json: schema: $ref: "#/components/schemas/CollectionUpdateSchema" - '400': + "400": description: Bad request, see error message for details content: application/json: schema: $ref: "#/components/schemas/ApiResponse" - '404': + "404": description: The collection was not found content: application/json: @@ -228,8 +225,7 @@ paths: tags: - collections summary: Delete a collection - description: - Permanently drops a collection. This action cannot be undone. For + description: Permanently drops a collection. This action cannot be undone. For large collections, this might have an impact on read latencies. operationId: deleteCollection parameters: @@ -240,13 +236,13 @@ paths: schema: type: string responses: - '200': + "200": description: Collection deleted content: application/json: schema: $ref: "#/components/schemas/CollectionResponse" - '404': + "404": description: Collection not found content: application/json: @@ -257,8 +253,7 @@ paths: tags: - documents summary: Index a document - description: - A document to be indexed in a given collection must conform to + description: A document to be indexed in a given collection must conform to the schema of the collection. operationId: indexDocument parameters: @@ -290,14 +285,14 @@ paths: x-go-type: "interface{}" required: true responses: - '201': + "201": description: Document successfully created/indexed content: application/json: schema: type: object description: Can be any key-value pair - '404': + "404": description: Collection not found content: application/json: @@ -328,9 +323,8 @@ paths: type: string example: "num_employees:>100 && country: [USA, UK]" responses: - '200': - description: - The response contains a single field, `num_updated`, indicating the number of documents affected. + "200": + description: The response contains a single field, `num_updated`, indicating the number of documents affected. content: application/json: schema: @@ -342,18 +336,18 @@ paths: type: integer description: The number of documents that have been updated example: 1 - '400': - description: 'Bad request, see error message for details' + "400": + description: "Bad request, see error message for details" content: application/json: schema: - $ref: '#/components/schemas/ApiResponse' - '404': + $ref: "#/components/schemas/ApiResponse" + "404": description: The collection was not found content: application/json: schema: - $ref: '#/components/schemas/ApiResponse' + $ref: "#/components/schemas/ApiResponse" requestBody: description: The document fields to be updated content: @@ -367,8 +361,7 @@ paths: tags: - documents summary: Delete a bunch of documents - description: - Delete a bunch of documents that match a specific filter condition. + description: Delete a bunch of documents that match a specific filter condition. Use the `batch_size` parameter to control the number of documents that should deleted at a time. A larger value will speed up deletions, but will impact performance of other operations running on the server. @@ -391,8 +384,7 @@ paths: type: string example: "num_employees:>100 && country: [USA, UK]" batch_size: - description: - Batch size parameter controls the number of documents that should be deleted + description: Batch size parameter controls the number of documents that should be deleted at a time. A larger value will speed up deletions, but will impact performance of other operations running on the server. type: integer @@ -402,7 +394,7 @@ paths: description: When true, removes all documents from the collection while preserving the collection and its schema. type: boolean responses: - '200': + "200": description: Documents successfully deleted content: application/json: @@ -413,7 +405,7 @@ paths: properties: num_deleted: type: integer - '404': + "404": description: Collection not found content: application/json: @@ -439,19 +431,19 @@ paths: schema: $ref: "#/components/schemas/SearchParameters" responses: - '200': + "200": description: Search results content: application/json: schema: $ref: "#/components/schemas/SearchResult" - '400': + "400": description: Bad request, see error message for details content: application/json: schema: $ref: "#/components/schemas/ApiResponse" - '404': + "404": description: The collection or field was not found content: application/json: @@ -495,14 +487,14 @@ paths: content: application/json: schema: - $ref: "#/components/schemas/SynonymSetRetrieveSchema" + $ref: "#/components/schemas/SynonymSetSchema" "404": description: Synonym set not found content: application/json: schema: $ref: "#/components/schemas/ApiResponse" - + put: tags: - synonyms @@ -650,7 +642,7 @@ paths: content: application/json: schema: - $ref: "#/components/schemas/SynonymItemSchema" + $ref: "#/components/schemas/SynonymItemUpsertSchema" required: true responses: "200": @@ -735,7 +727,7 @@ paths: content: application/json: schema: - $ref: "#/components/schemas/CurationSetRetrieveSchema" + $ref: "#/components/schemas/CurationSetSchema" "404": description: Curation set not found content: @@ -957,8 +949,7 @@ paths: type: object properties: filter_by: - description: - Filter conditions for refining your search results. Separate + description: Filter conditions for refining your search results. Separate multiple conditions with &&. type: string include_fields: @@ -969,7 +960,7 @@ paths: type: string responses: - '200': + "200": description: Exports all the documents in a given collection. content: application/octet-stream: @@ -979,7 +970,7 @@ paths: {"id": "124", "company_name": "Stark Industries", "num_employees": 5215, "country": "US"} {"id": "125", "company_name": "Future Technology", "num_employees": 1232,"country": "UK"} {"id": "126", "company_name": "Random Corp.", "num_employees": 531,"country": "AU"} - '404': + "404": description: The collection was not found content: application/json: @@ -990,8 +981,7 @@ paths: tags: - documents summary: Import documents into a collection - description: - The documents to be imported must be formatted in a newline delimited + description: The documents to be imported must be formatted in a newline delimited JSON structure. You can feed the output file from a Typesense export operation directly as import. operationId: importDocuments @@ -1012,8 +1002,7 @@ paths: type: integer return_id: type: boolean - description: - Returning the id of the imported documents. If you want the + description: Returning the id of the imported documents. If you want the import response to return the ingested document's id in the response, you can use the return_id parameter. remote_embedding_batch_size: @@ -1033,9 +1022,8 @@ paths: description: The JSONL file to import required: true responses: - '200': - description: - Result of the import operation. Each line of the response indicates the result + "200": + description: Result of the import operation. Each line of the response indicates the result of each document present in the request body (in the same order). If the import of a single document fails, it does not affect the other documents. If there is a failure, the response line will include a corresponding error @@ -1047,13 +1035,13 @@ paths: example: | {"success": true} {"success": false, "error": "Bad JSON.", "document": "[bad doc"} - '400': + "400": description: Bad request, see error message for details content: application/json: schema: $ref: "#/components/schemas/ApiResponse" - '404': + "404": description: The collection was not found content: application/json: @@ -1080,14 +1068,14 @@ paths: schema: type: string responses: - '200': + "200": description: The document referenced by the ID content: application/json: schema: type: object description: Can be any key-value pair - '404': + "404": description: The document or collection was not found content: application/json: @@ -1097,8 +1085,7 @@ paths: tags: - documents summary: Update a document - description: - Update an individual document from a collection by using its ID. + description: Update an individual document from a collection by using its ID. The update can be partial. operationId: updateDocument parameters: @@ -1129,14 +1116,14 @@ paths: x-go-type: "interface{}" required: true responses: - '200': + "200": description: The document referenced by the ID was updated content: application/json: schema: type: object description: Can be any key-value pair - '404': + "404": description: The document or collection was not found content: application/json: @@ -1162,14 +1149,14 @@ paths: schema: type: string responses: - '200': + "200": description: The document referenced by the ID was deleted content: application/json: schema: type: object description: Can be any key-value pair - '404': + "404": description: The document or collection was not found content: application/json: @@ -1180,14 +1167,14 @@ paths: description: Retrieve all conversation models operationId: retrieveAllConversationModels responses: - '200': + "200": content: application/json: schema: items: - $ref: '#/components/schemas/ConversationModelSchema' + $ref: "#/components/schemas/ConversationModelSchema" type: array - x-go-type: '[]*ConversationModelSchema' + x-go-type: "[]*ConversationModelSchema" description: List of all conversation models summary: List all conversation models tags: @@ -1200,20 +1187,20 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/ConversationModelCreateSchema' + $ref: "#/components/schemas/ConversationModelCreateSchema" required: true responses: - '201': + "201": content: application/json: schema: - $ref: '#/components/schemas/ConversationModelSchema' + $ref: "#/components/schemas/ConversationModelSchema" description: Created Conversation Model - '400': + "400": content: application/json: schema: - $ref: '#/components/schemas/ApiResponse' + $ref: "#/components/schemas/ApiResponse" description: Bad request, see error message for details tags: - conversations @@ -1229,11 +1216,11 @@ paths: schema: type: string responses: - '200': + "200": content: application/json: schema: - $ref: '#/components/schemas/ConversationModelSchema' + $ref: "#/components/schemas/ConversationModelSchema" description: A conversation model summary: Retrieve a conversation model tags: @@ -1245,7 +1232,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/ConversationModelUpdateSchema' + $ref: "#/components/schemas/ConversationModelUpdateSchema" required: true parameters: - name: modelId @@ -1255,11 +1242,11 @@ paths: schema: type: string responses: - '200': + "200": content: application/json: schema: - $ref: '#/components/schemas/ConversationModelSchema' + $ref: "#/components/schemas/ConversationModelSchema" description: The conversation model was successfully updated summary: Update a conversation model tags: @@ -1275,11 +1262,11 @@ paths: schema: type: string responses: - '200': + "200": content: application/json: schema: - $ref: '#/components/schemas/ConversationModelSchema' + $ref: "#/components/schemas/ConversationModelSchema" description: The conversation model was successfully deleted summary: Delete a conversation model tags: @@ -1291,7 +1278,7 @@ paths: summary: Retrieve (metadata about) all keys. operationId: getKeys responses: - '200': + "200": description: List of all keys content: application/json: @@ -1301,8 +1288,7 @@ paths: tags: - keys summary: Create an API Key - description: - Create an API Key with fine-grain access control. You can restrict access + description: Create an API Key with fine-grain access control. You can restrict access on both a per-collection and per-action level. The generated key is returned only during creation. You want to store this key carefully in a secure place. @@ -1314,19 +1300,19 @@ paths: schema: $ref: "#/components/schemas/ApiKeySchema" responses: - '201': + "201": description: Created API key content: application/json: schema: $ref: "#/components/schemas/ApiKey" - '400': + "400": description: Bad request, see error message for details content: application/json: schema: $ref: "#/components/schemas/ApiResponse" - '409': + "409": description: API key generation conflict content: application/json: @@ -1337,8 +1323,7 @@ paths: tags: - keys summary: Retrieve (metadata about) a key - description: - Retrieve (metadata about) a key. Only the key prefix is returned + description: Retrieve (metadata about) a key. Only the key prefix is returned when you retrieve a key. Due to security reasons, only the create endpoint returns the full API key. operationId: getKey @@ -1351,13 +1336,13 @@ paths: type: integer format: int64 responses: - '200': + "200": description: The key referenced by the ID content: application/json: schema: $ref: "#/components/schemas/ApiKey" - '404': + "404": description: The key was not found content: application/json: @@ -1377,19 +1362,19 @@ paths: type: integer format: int64 responses: - '200': + "200": description: The key referenced by the ID content: application/json: schema: $ref: "#/components/schemas/ApiKeyDeleteResponse" - '400': + "400": description: Bad request, see error message for details content: application/json: schema: $ref: "#/components/schemas/ApiResponse" - '404': + "404": description: Key not found content: application/json: @@ -1403,7 +1388,7 @@ paths: description: List all aliases and the corresponding collections that they map to. operationId: getAliases responses: - '200': + "200": description: List of all collection aliases content: application/json: @@ -1414,8 +1399,7 @@ paths: tags: - collections summary: Create or update a collection alias - description: - Create or update a collection alias. An alias is a virtual collection name that points + description: Create or update a collection alias. An alias is a virtual collection name that points to a real collection. If you're familiar with symbolic links on Linux, it's very similar to that. Aliases are useful when you want to reindex your data in the background on a new collection and switch your application to it without any changes to @@ -1435,19 +1419,19 @@ paths: schema: $ref: "#/components/schemas/CollectionAliasSchema" responses: - '200': + "200": description: The collection alias was created/updated content: application/json: schema: $ref: "#/components/schemas/CollectionAlias" - '400': + "400": description: Bad request, see error message for details content: application/json: schema: $ref: "#/components/schemas/ApiResponse" - '404': + "404": description: Alias not found content: application/json: @@ -1467,13 +1451,13 @@ paths: schema: type: string responses: - '200': + "200": description: Collection alias fetched content: application/json: schema: $ref: "#/components/schemas/CollectionAlias" - '404': + "404": description: The alias was not found content: application/json: @@ -1492,13 +1476,13 @@ paths: schema: type: string responses: - '200': + "200": description: Collection alias was deleted content: application/json: schema: $ref: "#/components/schemas/CollectionAlias" - '404': + "404": description: Alias not found content: application/json: @@ -1512,7 +1496,7 @@ paths: description: Print debugging information operationId: debug responses: - '200': + "200": description: Debugging information content: application/json: @@ -1529,7 +1513,7 @@ paths: description: Checks if Typesense server is ready to accept requests. operationId: health responses: - '200': + "200": description: Search service is ready for requests. content: application/json: @@ -1543,7 +1527,7 @@ paths: description: Returns the status of any ongoing schema change operations. If no schema changes are in progress, returns an empty response. operationId: getSchemaChanges responses: - '200': + "200": description: List of schema changes in progress content: application/json: @@ -1556,8 +1540,7 @@ paths: tags: - operations summary: Creates a point-in-time snapshot of a Typesense node's state and data in the specified directory. - description: - Creates a point-in-time snapshot of a Typesense node's state and data in the specified directory. + description: Creates a point-in-time snapshot of a Typesense node's state and data in the specified directory. You can then backup the snapshot directory that gets created and later restore it as a data directory, as needed. operationId: takeSnapshot @@ -1569,7 +1552,7 @@ paths: schema: type: string responses: - '201': + "201": description: Snapshot is created. content: application/json: @@ -1580,13 +1563,12 @@ paths: tags: - operations summary: Triggers a follower node to initiate the raft voting process, which triggers leader re-election. - description: - Triggers a follower node to initiate the raft voting process, which triggers leader re-election. + description: Triggers a follower node to initiate the raft voting process, which triggers leader re-election. The follower node that you run this operation against will become the new leader, once this command succeeds. operationId: vote responses: - '200': + "200": description: Re-election is performed. content: application/json: @@ -1597,11 +1579,10 @@ paths: tags: - operations summary: Clear the cached responses of search requests in the LRU cache. - description: - Clear the cached responses of search requests that are sent with `use_cache` parameter in the LRU cache. + description: Clear the cached responses of search requests that are sent with `use_cache` parameter in the LRU cache. operationId: clearCache responses: - '200': + "200": description: Clear cache succeeded. content: application/json: @@ -1617,7 +1598,7 @@ paths: This could reduce the size of the database and decrease read latency. While the database will not block during this operation, we recommend running it during off-peak hours. operationId: compactDb responses: - '200': + "200": description: Compacting the on-disk database succeeded. content: application/json: @@ -1628,8 +1609,7 @@ paths: tags: - operations summary: Toggle Slow Request Log - description: - Enable logging of requests that take over a defined threshold of time. + description: Enable logging of requests that take over a defined threshold of time. Default is `-1` which disables slow request logging. Slow requests are logged to the primary log file, with the prefix SLOW REQUEST. operationId: toggleSlowRequestLog @@ -1646,8 +1626,8 @@ paths: example: | {"log-slow-requests-time-ms": 2000} responses: - '200': - description: Compacting the on-disk database succeeded. + "200": + description: Toggle Slow Request Log database succeeded. content: application/json: schema: @@ -1673,13 +1653,13 @@ paths: schema: $ref: "#/components/schemas/MultiSearchSearchesParameter" responses: - '200': + "200": description: Search results content: application/json: schema: $ref: "#/components/schemas/MultiSearchResult" - '400': + "400": description: Bad request, see error message for details content: application/json: @@ -1697,21 +1677,21 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/AnalyticsEvent' + $ref: "#/components/schemas/AnalyticsEvent" required: true responses: - '200': + "200": description: Analytics event successfully created content: application/json: schema: - $ref: '#/components/schemas/AnalyticsEventCreateResponse' - '400': + $ref: "#/components/schemas/AnalyticsEventCreateResponse" + "400": description: Bad request, see error message for details content: application/json: schema: - $ref: '#/components/schemas/ApiResponse' + $ref: "#/components/schemas/ApiResponse" get: tags: - analytics @@ -1737,18 +1717,18 @@ paths: schema: type: integer responses: - '200': + "200": description: Events fetched content: application/json: schema: - $ref: '#/components/schemas/AnalyticsEventsResponse' - '400': + $ref: "#/components/schemas/AnalyticsEventsResponse" + "400": description: Bad request, see error message for details content: application/json: schema: - $ref: '#/components/schemas/ApiResponse' + $ref: "#/components/schemas/ApiResponse" /analytics/flush: post: tags: @@ -1757,12 +1737,12 @@ paths: description: Triggers a flush of analytics data to persistent storage. operationId: flushAnalytics responses: - '200': + "200": description: Flush triggered content: application/json: schema: - $ref: '#/components/schemas/AnalyticsEventCreateResponse' + $ref: "#/components/schemas/AnalyticsEventCreateResponse" /analytics/status: get: tags: @@ -1771,12 +1751,12 @@ paths: description: Returns sizes of internal analytics buffers and queues. operationId: getAnalyticsStatus responses: - '200': + "200": description: Status fetched content: application/json: schema: - $ref: '#/components/schemas/AnalyticsStatus' + $ref: "#/components/schemas/AnalyticsStatus" /analytics/rules: post: tags: @@ -1796,7 +1776,7 @@ paths: $ref: "#/components/schemas/AnalyticsRuleCreate" required: true responses: - '200': + "200": description: Analytics rule(s) successfully created content: application/json: @@ -1805,13 +1785,13 @@ paths: - $ref: "#/components/schemas/AnalyticsRule" - type: array items: - anyOf: + oneOf: - $ref: "#/components/schemas/AnalyticsRule" - type: object properties: error: type: string - '400': + "400": description: Bad request, see error message for details content: application/json: @@ -1831,7 +1811,7 @@ paths: required: false description: Filter rules by rule_tag responses: - '200': + "200": description: Analytics rules fetched content: application/json: @@ -1844,8 +1824,7 @@ paths: tags: - analytics summary: Upserts an analytics rule - description: - Upserts an analytics rule with the given name. + description: Upserts an analytics rule with the given name. operationId: upsertAnalyticsRule parameters: - in: path @@ -1862,13 +1841,13 @@ paths: $ref: "#/components/schemas/AnalyticsRuleUpdate" required: true responses: - '200': + "200": description: Analytics rule successfully upserted content: application/json: schema: $ref: "#/components/schemas/AnalyticsRule" - '400': + "400": description: Bad request, see error message for details content: application/json: @@ -1878,8 +1857,7 @@ paths: tags: - analytics summary: Retrieves an analytics rule - description: - Retrieve the details of an analytics rule, given it's name + description: Retrieve the details of an analytics rule, given it's name operationId: retrieveAnalyticsRule parameters: - in: path @@ -1889,13 +1867,13 @@ paths: type: string required: true responses: - '200': + "200": description: Analytics rule fetched content: application/json: schema: $ref: "#/components/schemas/AnalyticsRule" - '404': + "404": description: Analytics rule not found content: application/json: @@ -1905,8 +1883,7 @@ paths: tags: - analytics summary: Delete an analytics rule - description: - Permanently deletes an analytics rule, given it's name + description: Permanently deletes an analytics rule, given it's name operationId: deleteAnalyticsRule parameters: - in: path @@ -1916,13 +1893,13 @@ paths: type: string required: true responses: - '200': + "200": description: Analytics rule deleted content: application/json: schema: $ref: "#/components/schemas/AnalyticsRule" - '404': + "404": description: Analytics rule not found content: application/json: @@ -1933,11 +1910,10 @@ paths: tags: - operations summary: Get current RAM, CPU, Disk & Network usage metrics. - description: - Retrieve the metrics. + description: Retrieve the metrics. operationId: retrieveMetrics responses: - '200': + "200": description: Metrics fetched. content: application/json: @@ -1948,11 +1924,10 @@ paths: tags: - operations summary: Get stats about API endpoints. - description: - Retrieve the stats about API endpoints. + description: Retrieve the stats about API endpoints. operationId: retrieveAPIStats responses: - '200': + "200": description: Stats fetched. content: application/json: @@ -1963,11 +1938,10 @@ paths: tags: - stopwords summary: Retrieves all stopwords sets. - description: - Retrieve the details of all stopwords sets + description: Retrieve the details of all stopwords sets operationId: retrieveStopwordsSets responses: - '200': + "200": description: Stopwords sets fetched. content: application/json: @@ -1978,8 +1952,7 @@ paths: tags: - stopwords summary: Upserts a stopwords set. - description: - When an analytics rule is created, we give it a name and describe the type, the source collections and the destination collection. + description: When an analytics rule is created, we give it a name and describe the type, the source collections and the destination collection. operationId: upsertStopwordsSet parameters: - in: path @@ -1997,13 +1970,13 @@ paths: $ref: "#/components/schemas/StopwordsSetUpsertSchema" required: true responses: - '200': + "200": description: Stopwords set successfully upserted. content: application/json: schema: $ref: "#/components/schemas/StopwordsSetSchema" - '400': + "400": description: Bad request, see error message for details. content: application/json: @@ -2013,8 +1986,7 @@ paths: tags: - stopwords summary: Retrieves a stopwords set. - description: - Retrieve the details of a stopwords set, given it's name. + description: Retrieve the details of a stopwords set, given it's name. operationId: retrieveStopwordsSet parameters: - in: path @@ -2025,13 +1997,13 @@ paths: required: true example: countries responses: - '200': + "200": description: Stopwords set fetched. content: application/json: schema: $ref: "#/components/schemas/StopwordsSetRetrieveSchema" - '404': + "404": description: Stopwords set not found. content: application/json: @@ -2041,8 +2013,7 @@ paths: tags: - stopwords summary: Delete a stopwords set. - description: - Permanently deletes a stopwords set, given it's name. + description: Permanently deletes a stopwords set, given it's name. operationId: deleteStopwordsSet parameters: - in: path @@ -2053,7 +2024,7 @@ paths: required: true example: countries responses: - '200': + "200": description: Stopwords set rule deleted. content: application/json: @@ -2066,7 +2037,7 @@ paths: - id example: | {"id": "countries"} - '404': + "404": description: Stopwords set not found. content: application/json: @@ -2080,12 +2051,12 @@ paths: description: Retrieve the details of all presets operationId: retrieveAllPresets responses: - '200': + "200": description: Presets fetched. content: application/json: schema: - $ref: '#/components/schemas/PresetsRetrieveSchema' + $ref: "#/components/schemas/PresetsRetrieveSchema" /presets/{presetId}: get: tags: @@ -2102,18 +2073,18 @@ paths: required: true example: listing_view responses: - '200': + "200": description: Preset fetched. content: application/json: schema: - $ref: '#/components/schemas/PresetSchema' - '404': + $ref: "#/components/schemas/PresetSchema" + "404": description: Preset not found. content: application/json: schema: - $ref: '#/components/schemas/ApiResponse' + $ref: "#/components/schemas/ApiResponse" put: tags: - presets @@ -2133,21 +2104,21 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/PresetUpsertSchema' + $ref: "#/components/schemas/PresetUpsertSchema" required: true responses: - '200': + "200": description: Preset successfully upserted. content: application/json: schema: - $ref: '#/components/schemas/PresetSchema' - '400': + $ref: "#/components/schemas/PresetSchema" + "400": description: Bad request, see error message for details content: application/json: schema: - $ref: '#/components/schemas/ApiResponse' + $ref: "#/components/schemas/ApiResponse" delete: tags: - presets @@ -2163,18 +2134,18 @@ paths: required: true example: listing_view responses: - '200': + "200": description: Preset deleted. content: application/json: schema: - $ref: '#/components/schemas/PresetDeleteSchema' - '404': + $ref: "#/components/schemas/PresetDeleteSchema" + "404": description: Preset not found. content: application/json: schema: - $ref: '#/components/schemas/ApiResponse' + $ref: "#/components/schemas/ApiResponse" /stemming/dictionaries: get: tags: @@ -2183,7 +2154,7 @@ paths: description: Retrieve a list of all available stemming dictionaries. operationId: listStemmingDictionaries responses: - '200': + "200": description: List of all dictionaries content: application/json: @@ -2212,13 +2183,13 @@ paths: type: string example: irregular-plurals responses: - '200': + "200": description: Stemming dictionary details content: application/json: schema: $ref: "#/components/schemas/StemmingDictionary" - '404': + "404": description: Dictionary not found content: application/json: @@ -2251,7 +2222,7 @@ paths: {"word": "people", "root": "person"} {"word": "children", "root": "child"} responses: - '200': + "200": description: Dictionary successfully imported content: application/octet-stream: @@ -2260,7 +2231,7 @@ paths: example: > {"word": "people", "root": "person"} {"word": "children", "root": "child"} - '400': + "400": description: Bad request, see error message for details content: application/json: @@ -2274,14 +2245,14 @@ paths: description: Retrieve all NL search models. operationId: retrieveAllNLSearchModels responses: - '200': + "200": description: List of all NL search models content: application/json: schema: type: array items: - $ref: '#/components/schemas/NLSearchModelSchema' + $ref: "#/components/schemas/NLSearchModelSchema" post: tags: - nl_search_models @@ -2293,21 +2264,21 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/NLSearchModelCreateSchema' + $ref: "#/components/schemas/NLSearchModelCreateSchema" required: true responses: - '201': + "201": description: NL search model successfully created content: application/json: schema: - $ref: '#/components/schemas/NLSearchModelSchema' - '400': + $ref: "#/components/schemas/NLSearchModelSchema" + "400": description: Bad request, see error message for details content: application/json: schema: - $ref: '#/components/schemas/ApiResponse' + $ref: "#/components/schemas/ApiResponse" /nl_search_models/{modelId}: get: tags: @@ -2323,18 +2294,18 @@ paths: schema: type: string responses: - '200': + "200": description: NL search model fetched content: application/json: schema: - $ref: '#/components/schemas/NLSearchModelSchema' - '404': + $ref: "#/components/schemas/NLSearchModelSchema" + "404": description: NL search model not found content: application/json: schema: - $ref: '#/components/schemas/ApiResponse' + $ref: "#/components/schemas/ApiResponse" put: tags: - nl_search_models @@ -2353,27 +2324,27 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/NLSearchModelUpdateSchema' + $ref: "#/components/schemas/NLSearchModelUpdateSchema" required: true responses: - '200': + "200": description: NL search model successfully updated content: application/json: schema: - $ref: '#/components/schemas/NLSearchModelSchema' - '400': + $ref: "#/components/schemas/NLSearchModelSchema" + "400": description: Bad request, see error message for details content: application/json: schema: - $ref: '#/components/schemas/ApiResponse' - '404': + $ref: "#/components/schemas/ApiResponse" + "404": description: NL search model not found content: application/json: schema: - $ref: '#/components/schemas/ApiResponse' + $ref: "#/components/schemas/ApiResponse" delete: tags: - nl_search_models @@ -2388,18 +2359,18 @@ paths: schema: type: string responses: - '200': + "200": description: NL search model successfully deleted content: application/json: schema: - $ref: '#/components/schemas/NLSearchModelDeleteSchema' - '404': + $ref: "#/components/schemas/NLSearchModelDeleteSchema" + "404": description: NL search model not found content: application/json: schema: - $ref: '#/components/schemas/ApiResponse' + $ref: "#/components/schemas/ApiResponse" components: schemas: @@ -2430,8 +2401,7 @@ components: $ref: "#/components/schemas/Field" default_sorting_field: type: string - description: - The name of an int32 / float field that determines the order in which + description: The name of an int32 / float field that determines the order in which the search results are ranked when a sort_by clause is not provided during searching. This field must indicate some kind of popularity. example: num_employees # Go with the first field name listed above to produce sane defaults @@ -2456,8 +2426,7 @@ components: example: "synonym_set_1" enable_nested_fields: type: boolean - description: - Enables experimental support at a collection level for nested object or object array fields. + 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 @@ -2562,6 +2531,10 @@ components: type: string description: > Name of a field in another collection that should be linked to this collection so that it can be joined during query. + async_reference: + type: boolean + description: > + Allow documents to be indexed successfully even when the referenced document doesn't exist yet. num_dim: type: integer example: 256 @@ -2720,7 +2693,7 @@ components: items: $ref: "#/components/schemas/SearchResultHit" request_params: - $ref: "#/components/schemas/SearchRequestParams" + $ref: "#/components/schemas/SearchRequestParams" conversation: $ref: "#/components/schemas/SearchResultConversation" union_request_params: @@ -3043,22 +3016,59 @@ components: $ref: "#/components/schemas/MultiSearchResultItem" conversation: $ref: "#/components/schemas/SearchResultConversation" + facet_counts: + type: array + items: + $ref: "#/components/schemas/FacetCounts" + found: + type: integer + description: The number of documents found + found_docs: + type: integer + search_time_ms: + type: integer + description: The number of milliseconds the search took + out_of: + type: integer + description: The total number of documents in the collection + search_cutoff: + type: boolean + description: Whether the search was cut off + page: + type: integer + description: The search result page number + grouped_hits: + type: array + items: + $ref: "#/components/schemas/SearchGroupedHit" hits: + type: array + description: The documents that matched the search query items: - $ref: '#/components/schemas/SearchResultHit' + $ref: "#/components/schemas/SearchResultHit" + request_params: + $ref: "#/components/schemas/SearchRequestParams" + union_request_params: type: array + description: Returned only for union query response. + items: + $ref: "#/components/schemas/SearchRequestParams" + metadata: + type: object + description: Custom JSON object that can be returned in the search response + additionalProperties: true MultiSearchResultItem: allOf: - - $ref: "#/components/schemas/SearchResult" - - type: object - properties: - code: - type: integer - description: HTTP error code - format: int64 - error: - type: string - description: Error description + - $ref: "#/components/schemas/SearchResult" + - type: object + properties: + code: + type: integer + description: HTTP error code + format: int64 + error: + type: string + description: Error description SearchParameters: type: object properties: @@ -3082,28 +3092,24 @@ components: type: string query_by_weights: - description: - The relative weight to give each `query_by` field when ranking results. + description: The relative weight to give each `query_by` field when ranking results. This can be used to boost fields in priority, when looking for matches. Multiple fields are separated with a comma. type: string text_match_type: - description: - In a multi-field matching context, this parameter determines how the representative text match + description: In a multi-field matching context, this parameter determines how the representative text match score of a record is calculated. Possible values are max_score (default) or max_weight. type: string prefix: - description: - Boolean field to indicate that the last word in the query should + description: Boolean field to indicate that the last word in the query should be treated as a prefix, and not as a whole word. This is used for building autocomplete and instant search interfaces. Defaults to true. type: string infix: - description: - If infix index is enabled for this field, infix searching can be done on a per-field + description: 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 @@ -3111,37 +3117,32 @@ components: type: string max_extra_prefix: - description: - There are also 2 parameters that allow you to control the extent of infix searching + description: There are also 2 parameters that allow you to control the extent of infix searching max_extra_prefix and max_extra_suffix which specify the maximum number of symbols before or after the query that can be present in the token. For example query "K2100" has 2 extra symbols in "6PK2100". By default, any number of prefixes/suffixes can be present for a match. type: integer max_extra_suffix: - description: - There are also 2 parameters that allow you to control the extent of infix searching + description: There are also 2 parameters that allow you to control the extent of infix searching max_extra_prefix and max_extra_suffix which specify the maximum number of symbols before or after the query that can be present in the token. For example query "K2100" has 2 extra symbols in "6PK2100". By default, any number of prefixes/suffixes can be present for a match. type: integer filter_by: - description: - Filter conditions for refining your open api validator search results. Separate + description: Filter conditions for refining your open api validator search results. Separate multiple conditions with &&. type: string example: "num_employees:>100 && country: [USA, UK]" max_filter_by_candidates: - description: - Controls the number of similar words that Typesense considers during fuzzy search + description: Controls the number of similar words that Typesense considers during fuzzy search on filter_by values. Useful for controlling prefix matches like company_name:Acm*. type: integer sort_by: - description: - A list of numerical fields and their corresponding sort orders + description: A list of numerical fields and their corresponding sort orders that will be used for ordering your results. Up to 3 sort fields can be specified. The text similarity score is exposed as a special `_text_match` field that @@ -3152,8 +3153,7 @@ components: example: num_employees:desc facet_by: - description: - A list of fields that will be used for faceting your results + description: A list of fields that will be used for faceting your results on. Separate multiple fields with a comma. type: string @@ -3162,8 +3162,7 @@ components: type: integer facet_query: - description: - Facet values that are returned can now be filtered via this parameter. + description: Facet values that are returned can now be filtered via this parameter. The matching facet text is also highlighted. For example, when faceting by `category`, you can set `facet_query=category:shoe` to return only facet values that contain the prefix "shoe". @@ -3194,8 +3193,7 @@ components: type: integer group_by: - description: - You can aggregate search results into groups or buckets by specify + description: You can aggregate search results into groups or buckets by specify one or more `group_by` fields. Separate multiple fields with a comma. To group on a particular field, it must be a faceted field. type: string @@ -3485,28 +3483,24 @@ components: type: string query_by_weights: - description: - The relative weight to give each `query_by` field when ranking results. + description: The relative weight to give each `query_by` field when ranking results. This can be used to boost fields in priority, when looking for matches. Multiple fields are separated with a comma. type: string text_match_type: - description: - In a multi-field matching context, this parameter determines how the representative text match + description: In a multi-field matching context, this parameter determines how the representative text match score of a record is calculated. Possible values are max_score (default) or max_weight. type: string prefix: - description: - Boolean field to indicate that the last word in the query should + description: Boolean field to indicate that the last word in the query should be treated as a prefix, and not as a whole word. This is used for building autocomplete and instant search interfaces. Defaults to true. type: string infix: - description: - If infix index is enabled for this field, infix searching can be done on a per-field + description: 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 @@ -3514,31 +3508,27 @@ components: type: string max_extra_prefix: - description: - There are also 2 parameters that allow you to control the extent of infix searching + description: There are also 2 parameters that allow you to control the extent of infix searching max_extra_prefix and max_extra_suffix which specify the maximum number of symbols before or after the query that can be present in the token. For example query "K2100" has 2 extra symbols in "6PK2100". By default, any number of prefixes/suffixes can be present for a match. type: integer max_extra_suffix: - description: - There are also 2 parameters that allow you to control the extent of infix searching + description: There are also 2 parameters that allow you to control the extent of infix searching max_extra_prefix and max_extra_suffix which specify the maximum number of symbols before or after the query that can be present in the token. For example query "K2100" has 2 extra symbols in "6PK2100". By default, any number of prefixes/suffixes can be present for a match. type: integer filter_by: - description: - Filter conditions for refining youropen api validator search results. Separate + description: Filter conditions for refining youropen api validator search results. Separate multiple conditions with &&. type: string example: "num_employees:>100 && country: [USA, UK]" sort_by: - description: - A list of numerical fields and their corresponding sort orders + description: A list of numerical fields and their corresponding sort orders that will be used for ordering your results. Up to 3 sort fields can be specified. The text similarity score is exposed as a special `_text_match` field that @@ -3548,8 +3538,7 @@ components: type: string facet_by: - description: - A list of fields that will be used for faceting your results + description: A list of fields that will be used for faceting your results on. Separate multiple fields with a comma. type: string @@ -3558,8 +3547,7 @@ components: type: integer facet_query: - description: - Facet values that are returned can now be filtered via this parameter. + description: Facet values that are returned can now be filtered via this parameter. The matching facet text is also highlighted. For example, when faceting by `category`, you can set `facet_query=category:shoe` to return only facet values that contain the prefix "shoe". @@ -3590,8 +3578,7 @@ components: type: integer group_by: - description: - You can aggregate search results into groups or buckets by specify + description: You can aggregate search results into groups or buckets by specify one or more `group_by` fields. Separate multiple fields with a comma. To group on a particular field, it must be a faceted field. type: string @@ -3979,8 +3966,7 @@ components: name: type: string type: - type: string - enum: [popular_queries, nohits_queries, counter, log] + $ref: "#/components/schemas/AnalyticsRuleType" collection: type: string event_type: @@ -4005,6 +3991,9 @@ components: type: string weight: type: integer + AnalyticsRuleType: + type: string + enum: [popular_queries, nohits_queries, counter, log] AnalyticsRuleUpdate: type: object description: Fields allowed to update on an analytics rule @@ -4033,7 +4022,7 @@ components: type: integer AnalyticsRule: allOf: - - $ref: '#/components/schemas/AnalyticsRuleCreate' + - $ref: "#/components/schemas/AnalyticsRuleCreate" - type: object AnalyticsStatus: type: object @@ -4045,7 +4034,7 @@ components: query_counter_events: { type: integer } doc_log_events: { type: integer } doc_counter_events: { type: integer } - + APIStatsResponse: type: object properties: @@ -4141,13 +4130,13 @@ components: properties: value: oneOf: - - $ref: '#/components/schemas/SearchParameters' - - $ref: '#/components/schemas/MultiSearchSearchesParameter' + - $ref: "#/components/schemas/SearchParameters" + - $ref: "#/components/schemas/MultiSearchSearchesParameter" required: - value PresetSchema: allOf: - - $ref: '#/components/schemas/PresetUpsertSchema' + - $ref: "#/components/schemas/PresetUpsertSchema" - type: object required: - name @@ -4162,8 +4151,8 @@ components: presets: type: array items: - $ref: '#/components/schemas/PresetSchema' - x-go-type: '[]*PresetSchema' + $ref: "#/components/schemas/PresetSchema" + x-go-type: "[]*PresetSchema" PresetDeleteSchema: type: object required: @@ -4190,7 +4179,7 @@ components: - model_name - max_bytes allOf: - - $ref: '#/components/schemas/ConversationModelUpdateSchema' + - $ref: "#/components/schemas/ConversationModelUpdateSchema" - type: object required: - model_name @@ -4241,7 +4230,7 @@ components: type: string ConversationModelSchema: allOf: - - $ref: '#/components/schemas/ConversationModelCreateSchema' + - $ref: "#/components/schemas/ConversationModelCreateSchema" - type: object required: - id @@ -4338,7 +4327,7 @@ components: NLSearchModelCreateSchema: allOf: - - $ref: '#/components/schemas/NLSearchModelBase' + - $ref: "#/components/schemas/NLSearchModelBase" - type: object properties: id: @@ -4347,7 +4336,7 @@ components: NLSearchModelSchema: allOf: - - $ref: '#/components/schemas/NLSearchModelCreateSchema' + - $ref: "#/components/schemas/NLSearchModelCreateSchema" - type: object required: - id @@ -4357,7 +4346,7 @@ components: description: ID of the NL search model NLSearchModelUpdateSchema: - $ref: '#/components/schemas/NLSearchModelCreateSchema' + $ref: "#/components/schemas/NLSearchModelCreateSchema" NLSearchModelDeleteSchema: type: object @@ -4368,15 +4357,11 @@ components: type: string description: ID of the deleted NL search model - SynonymItemSchema: + SynonymItemUpsertSchema: type: object required: - - id - synonyms properties: - id: - type: string - description: Unique identifier for the synonym item synonyms: type: array description: Array of words that should be considered as synonyms @@ -4394,6 +4379,17 @@ components: items: type: string + SynonymItemSchema: + allOf: + - type: object + required: + - id + properties: + id: + type: string + description: Unique identifier for the synonym item + - $ref: "#/components/schemas/SynonymItemUpsertSchema" + SynonymSetCreateSchema: type: object required: @@ -4427,9 +4423,6 @@ components: items: $ref: "#/components/schemas/SynonymSetSchema" - SynonymSetRetrieveSchema: - $ref: "#/components/schemas/SynonymSetCreateSchema" - SynonymSetDeleteSchema: type: object required: @@ -4454,19 +4447,18 @@ components: - rule properties: rule: - $ref: '#/components/schemas/CurationRule' + $ref: "#/components/schemas/CurationRule" includes: type: array - description: - List of document `id`s that should be included in the search results with their + description: List of document `id`s that should be included in the search results with their corresponding `position`s. items: - $ref: '#/components/schemas/CurationInclude' + $ref: "#/components/schemas/CurationInclude" excludes: type: array description: List of document `id`s that should be excluded from the search results. items: - $ref: '#/components/schemas/CurationExclude' + $ref: "#/components/schemas/CurationExclude" filter_by: type: string description: > @@ -4509,10 +4501,9 @@ components: type: string description: ID of the curation item - CurationItemSchema: allOf: - - $ref: '#/components/schemas/CurationItemCreateSchema' + - $ref: "#/components/schemas/CurationItemCreateSchema" - type: object required: - id @@ -4529,14 +4520,14 @@ components: type: array description: Array of curation items items: - $ref: '#/components/schemas/CurationItemCreateSchema' + $ref: "#/components/schemas/CurationItemCreateSchema" description: type: string description: Optional description for the curation set CurationSetSchema: allOf: - - $ref: '#/components/schemas/CurationSetCreateSchema' + - $ref: "#/components/schemas/CurationSetCreateSchema" - type: object required: - name @@ -4590,9 +4581,6 @@ components: type: string description: document id that should be excluded from the search results. - CurationSetRetrieveSchema: - $ref: '#/components/schemas/CurationSetCreateSchema' - CurationSetDeleteSchema: type: object required: diff --git a/typesense/api/types_gen.go b/typesense/api/types_gen.go index 693eb51d..916f175d 100644 --- a/typesense/api/types_gen.go +++ b/typesense/api/types_gen.go @@ -15,18 +15,10 @@ const ( // Defines values for AnalyticsRuleType. const ( - AnalyticsRuleTypeCounter AnalyticsRuleType = "counter" - AnalyticsRuleTypeLog AnalyticsRuleType = "log" - AnalyticsRuleTypeNohitsQueries AnalyticsRuleType = "nohits_queries" - AnalyticsRuleTypePopularQueries AnalyticsRuleType = "popular_queries" -) - -// Defines values for AnalyticsRuleCreateType. -const ( - AnalyticsRuleCreateTypeCounter AnalyticsRuleCreateType = "counter" - AnalyticsRuleCreateTypeLog AnalyticsRuleCreateType = "log" - AnalyticsRuleCreateTypeNohitsQueries AnalyticsRuleCreateType = "nohits_queries" - AnalyticsRuleCreateTypePopularQueries AnalyticsRuleCreateType = "popular_queries" + Counter AnalyticsRuleType = "counter" + Log AnalyticsRuleType = "log" + NohitsQueries AnalyticsRuleType = "nohits_queries" + PopularQueries AnalyticsRuleType = "popular_queries" ) // Defines values for CurationRuleMatch. @@ -125,9 +117,6 @@ type AnalyticsRule struct { Type AnalyticsRuleType `json:"type"` } -// AnalyticsRuleType defines model for AnalyticsRule.Type. -type AnalyticsRuleType string - // AnalyticsRuleCreate defines model for AnalyticsRuleCreate. type AnalyticsRuleCreate struct { Collection string `json:"collection"` @@ -135,12 +124,9 @@ type AnalyticsRuleCreate struct { Name string `json:"name"` Params *AnalyticsRuleCreateParams `json:"params,omitempty"` RuleTag *string `json:"rule_tag,omitempty"` - Type AnalyticsRuleCreateType `json:"type"` + Type AnalyticsRuleType `json:"type"` } -// AnalyticsRuleCreateType defines model for AnalyticsRuleCreate.Type. -type AnalyticsRuleCreateType string - // AnalyticsRuleCreateParams defines model for AnalyticsRuleCreateParams. type AnalyticsRuleCreateParams struct { CaptureSearchRequests *bool `json:"capture_search_requests,omitempty"` @@ -152,6 +138,9 @@ type AnalyticsRuleCreateParams struct { Weight *int `json:"weight,omitempty"` } +// AnalyticsRuleType defines model for AnalyticsRuleType. +type AnalyticsRuleType string + // AnalyticsRuleUpdate Fields allowed to update on an analytics rule type AnalyticsRuleUpdate struct { Name *string `json:"name,omitempty"` @@ -537,9 +526,6 @@ type CurationSetDeleteSchema struct { Name string `json:"name"` } -// CurationSetRetrieveSchema defines model for CurationSetRetrieveSchema. -type CurationSetRetrieveSchema = CurationSetCreateSchema - // CurationSetSchema defines model for CurationSetSchema. type CurationSetSchema struct { // Description Optional description for the curation set @@ -579,15 +565,17 @@ type FacetCountsStats struct { // Field defines model for Field. type Field struct { - Drop *bool `json:"drop,omitempty"` - Embed *FieldEmbed `json:"embed,omitempty"` - Facet *bool `json:"facet,omitempty"` - Index *bool `json:"index,omitempty"` - Infix *bool `json:"infix,omitempty"` - Locale *string `json:"locale,omitempty"` - Name string `json:"name"` - NumDim *int `json:"num_dim,omitempty"` - Optional *bool `json:"optional,omitempty"` + // AsyncReference Allow documents to be indexed successfully even when the referenced document doesn't exist yet. + AsyncReference *bool `json:"async_reference,omitempty"` + Drop *bool `json:"drop,omitempty"` + Embed *FieldEmbed `json:"embed,omitempty"` + Facet *bool `json:"facet,omitempty"` + Index *bool `json:"index,omitempty"` + Infix *bool `json:"infix,omitempty"` + Locale *string `json:"locale,omitempty"` + Name string `json:"name"` + NumDim *int `json:"num_dim,omitempty"` + Optional *bool `json:"optional,omitempty"` // RangeIndex Enables an index optimized for range filtering on numerical fields (e.g. rating:>3.5). Default: false. RangeIndex *bool `json:"range_index,omitempty"` @@ -1049,8 +1037,35 @@ type MultiSearchParameters struct { // MultiSearchResult defines model for MultiSearchResult. type MultiSearchResult struct { Conversation *SearchResultConversation `json:"conversation,omitempty"` - Hits *[]SearchResultHit `json:"hits,omitempty"` - Results []MultiSearchResultItem `json:"results"` + FacetCounts *[]FacetCounts `json:"facet_counts,omitempty"` + + // Found The number of documents found + Found *int `json:"found,omitempty"` + FoundDocs *int `json:"found_docs,omitempty"` + GroupedHits *[]SearchGroupedHit `json:"grouped_hits,omitempty"` + + // Hits The documents that matched the search query + Hits *[]SearchResultHit `json:"hits,omitempty"` + + // Metadata Custom JSON object that can be returned in the search response + Metadata *map[string]interface{} `json:"metadata,omitempty"` + + // OutOf The total number of documents in the collection + OutOf *int `json:"out_of,omitempty"` + + // Page The search result page number + Page *int `json:"page,omitempty"` + RequestParams *SearchRequestParams `json:"request_params,omitempty"` + Results []MultiSearchResultItem `json:"results"` + + // SearchCutoff Whether the search was cut off + SearchCutoff *bool `json:"search_cutoff,omitempty"` + + // SearchTimeMs The number of milliseconds the search took + SearchTimeMs *int `json:"search_time_ms,omitempty"` + + // UnionRequestParams Returned only for union query response. + UnionRequestParams *[]SearchRequestParams `json:"union_request_params,omitempty"` } // MultiSearchResultItem defines model for MultiSearchResultItem. @@ -1741,6 +1756,21 @@ type SynonymItemSchema struct { Synonyms []string `json:"synonyms"` } +// SynonymItemUpsertSchema defines model for SynonymItemUpsertSchema. +type SynonymItemUpsertSchema struct { + // Locale Locale for the synonym, leave blank to use the standard tokenizer + Locale *string `json:"locale,omitempty"` + + // Root For 1-way synonyms, indicates the root word that words in the synonyms parameter map to + Root *string `json:"root,omitempty"` + + // SymbolsToIndex By default, special characters are dropped from synonyms. Use this attribute to specify which special characters should be indexed as is + SymbolsToIndex *[]string `json:"symbols_to_index,omitempty"` + + // Synonyms Array of words that should be considered as synonyms + Synonyms []string `json:"synonyms"` +} + // SynonymSetCreateSchema defines model for SynonymSetCreateSchema. type SynonymSetCreateSchema struct { // Items Array of synonym items @@ -1753,9 +1783,6 @@ type SynonymSetDeleteSchema struct { Name string `json:"name"` } -// SynonymSetRetrieveSchema defines model for SynonymSetRetrieveSchema. -type SynonymSetRetrieveSchema = SynonymSetCreateSchema - // SynonymSetSchema defines model for SynonymSetSchema. type SynonymSetSchema struct { // Items Array of synonym items @@ -2093,7 +2120,7 @@ type UpsertStopwordsSetJSONRequestBody = StopwordsSetUpsertSchema type UpsertSynonymSetJSONRequestBody = SynonymSetCreateSchema // UpsertSynonymSetItemJSONRequestBody defines body for UpsertSynonymSetItem for application/json ContentType. -type UpsertSynonymSetItemJSONRequestBody = SynonymItemSchema +type UpsertSynonymSetItemJSONRequestBody = SynonymItemUpsertSchema // AsSearchParameters returns the union data inside the PresetSchema_Value as a SearchParameters func (t PresetSchema_Value) AsSearchParameters() (SearchParameters, error) { diff --git a/typesense/curation_set.go b/typesense/curation_set.go index 30db6edd..a9c28a2a 100644 --- a/typesense/curation_set.go +++ b/typesense/curation_set.go @@ -9,7 +9,7 @@ import ( // CurationSetInterface is a type for individual Curation Set API operations type CurationSetInterface interface { // Retrieve a single curation set - Retrieve(ctx context.Context) (*api.CurationSetRetrieveSchema, error) + Retrieve(ctx context.Context) (*api.CurationSetSchema, error) // Update a curation set Upsert(ctx context.Context, curationSetSchema *api.CurationSetCreateSchema) (*api.CurationSetSchema, error) // Delete a curation set @@ -22,7 +22,7 @@ type curationSet struct { curationSetName string } -func (c *curationSet) Retrieve(ctx context.Context) (*api.CurationSetRetrieveSchema, error) { +func (c *curationSet) Retrieve(ctx context.Context) (*api.CurationSetSchema, error) { response, err := c.apiClient.RetrieveCurationSetWithResponse(ctx, c.curationSetName) if err != nil { return nil, err diff --git a/typesense/multi_search_test.go b/typesense/multi_search_test.go index 27638b11..2f9b91a6 100644 --- a/typesense/multi_search_test.go +++ b/typesense/multi_search_test.go @@ -206,6 +206,200 @@ func TestMultiSearchResultDeserialization(t *testing.T) { assert.Equal(t, expected, result) } +func TestMultiSearchResultDeserializationWithTopLevelFields(t *testing.T) { + inputJSON := `{ + "found": 3, + "out_of": 10, + "search_time_ms": 5, + "page": 1, + "search_cutoff": false, + "hits": [ + { + "highlights": [ + { + "field": "company_name", + "snippet": "Stark Industries", + "matched_tokens": ["Stark"] + } + ], + "document": { + "id": "124", + "company_name": "Stark Industries", + "num_employees": 5215, + "country": "USA" + } + }, + { + "document": { + "id": "125", + "company_name": "Company 2", + "num_employees": 150, + "country": "USA" + } + }, + { + "document": { + "id": "127", + "company_name": "Company 3", + "num_employees": 250, + "country": "USA" + } + } + ], + "results": [ + { + "facet_counts": [], + "found": 2, + "search_time_ms": 2, + "hits": [ + { + "highlights": [ + { + "field": "company_name", + "snippet": "Stark Industries", + "matched_tokens": ["Stark"] + } + ], + "document": { + "id": "124", + "company_name": "Stark Industries", + "num_employees": 5215, + "country": "USA" + } + }, + { + "document": { + "id": "125", + "company_name": "Company 2", + "num_employees": 150, + "country": "USA" + } + } + ] + }, + { + "facet_counts": [], + "found": 1, + "search_time_ms": 1, + "hits": [ + { + "document": { + "id": "127", + "company_name": "Company 3", + "num_employees": 250, + "country": "USA" + } + } + ] + } + ] + }` + expected := &api.MultiSearchResult{ + Found: pointer.Int(3), + OutOf: pointer.Int(10), + SearchTimeMs: pointer.Int(5), + Page: pointer.Int(1), + SearchCutoff: pointer.False(), + Hits: &[]api.SearchResultHit{ + { + Highlights: &[]api.SearchHighlight{ + { + Field: pointer.String("company_name"), + Snippet: pointer.String("Stark Industries"), + MatchedTokens: &[]interface{}{"Stark"}, + }, + }, + Document: &map[string]interface{}{ + "id": "124", + "company_name": "Stark Industries", + "num_employees": float64(5215), + "country": "USA", + }, + }, + { + Document: &map[string]interface{}{ + "id": "125", + "company_name": "Company 2", + "num_employees": float64(150), + "country": "USA", + }, + }, + { + Document: &map[string]interface{}{ + "id": "127", + "company_name": "Company 3", + "num_employees": float64(250), + "country": "USA", + }, + }, + }, + Results: []api.MultiSearchResultItem{ + { + Found: pointer.Int(2), + SearchTimeMs: pointer.Int(2), + FacetCounts: &[]api.FacetCounts{}, + Hits: &[]api.SearchResultHit{ + { + Highlights: &[]api.SearchHighlight{ + { + Field: pointer.String("company_name"), + Snippet: pointer.String("Stark Industries"), + MatchedTokens: &[]interface{}{"Stark"}, + }, + }, + Document: &map[string]interface{}{ + "id": "124", + "company_name": "Stark Industries", + "num_employees": float64(5215), + "country": "USA", + }, + }, + { + Document: &map[string]interface{}{ + "id": "125", + "company_name": "Company 2", + "num_employees": float64(150), + "country": "USA", + }, + }, + }, + }, + { + Found: pointer.Int(1), + SearchTimeMs: pointer.Int(1), + FacetCounts: &[]api.FacetCounts{}, + Hits: &[]api.SearchResultHit{ + { + Document: &map[string]interface{}{ + "id": "127", + "company_name": "Company 3", + "num_employees": float64(250), + "country": "USA", + }, + }, + }, + }, + }, + } + result := &api.MultiSearchResult{} + err := json.Unmarshal([]byte(inputJSON), result) + assert.Nil(t, err) + assert.Equal(t, expected, result) + + assert.NotNil(t, result.Found) + assert.Equal(t, 3, *result.Found) + assert.NotNil(t, result.OutOf) + assert.Equal(t, 10, *result.OutOf) + assert.NotNil(t, result.SearchTimeMs) + assert.Equal(t, 5, *result.SearchTimeMs) + assert.NotNil(t, result.Page) + assert.Equal(t, 1, *result.Page) + assert.NotNil(t, result.SearchCutoff) + assert.Equal(t, false, *result.SearchCutoff) + assert.NotNil(t, result.Hits) + assert.Equal(t, 3, len(*result.Hits)) +} + func TestMultiSearch(t *testing.T) { expectedParams := newMultiSearchParams() expectedResult := newMultiSearchResult() diff --git a/typesense/synonym_set.go b/typesense/synonym_set.go index f12023f3..479f3726 100644 --- a/typesense/synonym_set.go +++ b/typesense/synonym_set.go @@ -9,7 +9,7 @@ import ( // SynonymSetInterface is a type for individual Synonym Set API operations type SynonymSetInterface interface { // Retrieve a single synonym set - Retrieve(ctx context.Context) (*api.SynonymSetRetrieveSchema, error) + Retrieve(ctx context.Context) (*api.SynonymSetSchema, error) // Update a synonym set Upsert(ctx context.Context, synonymSetSchema *api.SynonymSetCreateSchema) (*api.SynonymSetSchema, error) // Delete a synonym set @@ -22,7 +22,7 @@ type synonymSet struct { synonymSetName string } -func (s *synonymSet) Retrieve(ctx context.Context) (*api.SynonymSetRetrieveSchema, error) { +func (s *synonymSet) Retrieve(ctx context.Context) (*api.SynonymSetSchema, error) { response, err := s.apiClient.RetrieveSynonymSetWithResponse(ctx, s.synonymSetName) if err != nil { return nil, err diff --git a/typesense/test/analytics_rule_test.go b/typesense/test/analytics_rule_test.go index 251793ce..21f29a3e 100644 --- a/typesense/test/analytics_rule_test.go +++ b/typesense/test/analytics_rule_test.go @@ -37,7 +37,7 @@ func TestAnalyticsRule(t *testing.T) { ruleName := newUUIDName("test-rule") ruleCreate := &api.AnalyticsRuleCreate{ Name: ruleName, - Type: api.AnalyticsRuleCreateTypeCounter, + Type: api.Counter, Collection: collectionName, EventType: "click", Params: &api.AnalyticsRuleCreateParams{ @@ -52,7 +52,7 @@ func TestAnalyticsRule(t *testing.T) { createdRule := result[0] require.Equal(t, ruleName, createdRule.Name) - require.Equal(t, api.AnalyticsRuleTypeCounter, createdRule.Type) + require.Equal(t, api.Counter, createdRule.Type) require.Equal(t, collectionName, createdRule.Collection) require.Equal(t, "click", createdRule.EventType) }) diff --git a/typesense/test/dbhelpers_test.go b/typesense/test/dbhelpers_test.go index 98d1d22b..f865bbc7 100644 --- a/typesense/test/dbhelpers_test.go +++ b/typesense/test/dbhelpers_test.go @@ -452,7 +452,7 @@ func newPresetFromMultiSearchSearchesParameter(presetName string) *api.PresetSch func newAnalyticsRule(ruleName string, collectionName string, sourceCollectionName string, eventName string) *api.AnalyticsRule { return &api.AnalyticsRule{ Name: ruleName, - Type: api.AnalyticsRuleTypeCounter, + Type: api.Counter, Collection: collectionName, EventType: "click", Params: &api.AnalyticsRuleCreateParams{ @@ -469,7 +469,7 @@ func createNewAnalyticsRule(t *testing.T, collectionName string, sourceCollectio // Create the rule using the new API ruleCreate := &api.AnalyticsRuleCreate{ Name: ruleName, - Type: api.AnalyticsRuleCreateTypeCounter, + Type: api.Counter, Collection: collectionName, EventType: "click", Params: &api.AnalyticsRuleCreateParams{ diff --git a/typesense/test/multi_search_test.go b/typesense/test/multi_search_test.go index 90912f4e..cb1a524e 100644 --- a/typesense/test/multi_search_test.go +++ b/typesense/test/multi_search_test.go @@ -346,3 +346,82 @@ func TestMultiSearchWithStopwords(t *testing.T) { // Check second result require.Equal(t, 0, len(*result.Results[1].Hits), "Number of docs in second result did not equal") } + +func TestMultiSearchUnionWithTopLevelFields(t *testing.T) { + collectionName1 := createNewCollection(t, "companies") + collectionName2 := createNewCollection(t, "companies") + documents := []interface{}{ + newDocument("123", withCompanyName("Company 1"), withNumEmployees(50)), + newDocument("125", withCompanyName("Company 2"), withNumEmployees(150)), + newDocument("127", withCompanyName("Company 3"), withNumEmployees(250)), + newDocument("129", withCompanyName("Stark Industries 4"), withNumEmployees(500)), + newDocument("131", withCompanyName("Stark Industries 5"), withNumEmployees(1000)), + } + + params := &api.ImportDocumentsParams{Action: pointer.Any(api.Create)} + _, err := typesenseClient.Collection(collectionName1).Documents().Import(context.Background(), documents, params) + require.NoError(t, err) + + _, err = typesenseClient.Collection(collectionName2).Documents().Import(context.Background(), documents, params) + require.NoError(t, err) + + searchParams := &api.MultiSearchParams{ + FilterBy: pointer.String("num_employees:>100"), + QueryBy: pointer.String("company_name"), + } + + searches := api.MultiSearchSearchesParameter{ + Union: pointer.True(), + Searches: []api.MultiSearchCollectionParameters{ + { + Q: pointer.String("Company"), + Collection: pointer.Any(collectionName1), + FilterBy: pointer.String("num_employees:>100"), + SortBy: pointer.String("num_employees:desc"), + }, + { + Q: pointer.String("Stark"), + Collection: pointer.Any(collectionName2), + FilterBy: pointer.String("num_employees:>=500"), + }, + }, + } + + result, err := typesenseClient.MultiSearch.Perform(context.Background(), searchParams, searches) + require.NoError(t, err) + + _ = result.Found + _ = result.OutOf + _ = result.SearchTimeMs + _ = result.Hits + _ = result.UnionRequestParams + _ = result.Page + _ = result.SearchCutoff + _ = result.FacetCounts + _ = result.Metadata + _ = result.RequestParams + + if result.Found != nil { + require.Greater(t, *result.Found, 0, "Found should be greater than 0 if populated") + } + + if result.OutOf != nil { + require.Greater(t, *result.OutOf, 0, "OutOf should be greater than 0 if populated") + } + + if result.SearchTimeMs != nil { + require.GreaterOrEqual(t, *result.SearchTimeMs, 0, "SearchTimeMs should be >= 0 if populated") + } + + if result.Hits != nil { + require.Greater(t, len(*result.Hits), 0, "Hits should contain results if populated") + if result.Found != nil { + require.Equal(t, *result.Found, len(*result.Hits), "Found count should match number of hits if both are populated") + } + } + + if result.UnionRequestParams != nil { + require.Greater(t, len(*result.UnionRequestParams), 0, "UnionRequestParams should contain request params if populated") + } + _ = result.Results +}