From 15f08fcb3e6f7d5f541de17d6991d0d476b23535 Mon Sep 17 00:00:00 2001 From: Pablo Alcalde Date: Tue, 26 Mar 2024 10:23:48 +0100 Subject: [PATCH 1/2] add PostSearchIndex --- db.go | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/db.go b/db.go index c5335e1..40ce2a5 100644 --- a/db.go +++ b/db.go @@ -23,8 +23,7 @@ type DB struct { // WithContext returns a new copy of the database object with the // new context set. Use like: // -// db.WithContext(ctx).Post(doc) -// +// db.WithContext(ctx).Post(doc) func (db *DB) WithContext(ctx context.Context) *DB { db2 := new(DB) *db2 = *db @@ -296,6 +295,34 @@ func (db *DB) PostView(ddoc, view string, result interface{}, opts Options, payl return readBody(resp, &result) } +// PostSearchIndex invokes a Search Index +// The ddoc parameter must be the name of the design document +// containing the index, but excluding the _design/ prefix. +// +// The output of the query is unmarshalled into the given result. +// The format of the result depends on the options. Please +// refer to the CouchDB HTTP API documentation for all the possible +// options that can be set. +// +// https://docs.couchdb.org/en/stable/ddocs/search.html +func (db *DB) PostSearchIndex(ddoc, index string, result interface{}, opts Options, payload Payload) error { + ddoc = strings.Replace(ddoc, "_design/", "", 1) + path, err := optpath(opts, viewJsonKeys, db.name, "_design", ddoc, "_search", index) + if err != nil { + return err + } + json, err := json.Marshal(payload) + if err != nil { + return err + } + body := bytes.NewReader(json) + resp, err := db.request(db.ctx, "POST", path, body) + if err != nil { + return err + } + return readBody(resp, &result) +} + // AllDocs invokes the _all_docs view of a database. // // The output of the query is unmarshalled into the given result. From 961eb6e78294e226fcbbcf38b09a578c62b87014 Mon Sep 17 00:00:00 2001 From: Pablo Alcalde Date: Tue, 9 Apr 2024 15:31:08 +0200 Subject: [PATCH 2/2] add changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b01f04b..b20535f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,10 @@ ### Security - Nothing +## [0.5.0] - 2024-04-09 +### Added +- Added PostSearchIndex endpoint to give support for search indexes + ## [0.4.1] - 2020-08-03 ### Fixed - Fix BulkGet request body