feat(11.1-04): add the Backend section, the remaining Services pages and the concept map links
- docs/backend: admin controllers, forms, lists and filters, relation manager, users and permissions, settings, partials and widgets, admin SPA - docs/services: storage, outbound HTTP, realtime, Web Push, search, parity testing and the Frontend and AJAX (not provided) page - Examples for cabana (with testdata/docs YAML), fetchguard, lighthouse and its centrifugo driver, flare, beachcomber and typesense, tide; lighthouse and beachcomber TestDocs* regions run on their Postgres harnesses - concept map rows link their guide pages and the not-provided rows the Frontend and AJAX page; index lists Backend, Database and Services - TestDocsRequiredPages asserts the D-08 section order
This commit is contained in:
49
modules/beachcomber/typesense/example_test.go
Normal file
49
modules/beachcomber/typesense/example_test.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package typesense_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"git.golem15.com/golem15/summercms/modules/beachcomber"
|
||||
"git.golem15.com/golem15/summercms/modules/beachcomber/typesense"
|
||||
)
|
||||
|
||||
func ExampleEngine_SearchIDs() {
|
||||
// A stand-in Typesense node.
|
||||
node := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
q := r.URL.Query()
|
||||
fmt.Println(r.Method, r.URL.Path, "key sent:", r.Header.Get("X-TYPESENSE-API-KEY") != "")
|
||||
fmt.Println("q", q.Get("q"), "query_by", q.Get("query_by"), "filter_by", q.Get("filter_by"))
|
||||
fmt.Fprint(w, `{"hits":[{"document":{"id":"3"}},{"document":{"id":"1"}}]}`)
|
||||
}))
|
||||
defer node.Close()
|
||||
u, _ := url.Parse(node.URL)
|
||||
port, _ := strconv.Atoi(u.Port())
|
||||
|
||||
engine := typesense.New(typesense.Config{
|
||||
APIKey: "test-only-key", // SUMMER_SEARCH__TYPESENSE__API_KEY
|
||||
Host: u.Hostname(),
|
||||
Port: port,
|
||||
Protocol: "http",
|
||||
ConnectionTimeout: 2 * time.Second,
|
||||
})
|
||||
ids, err := engine.SearchIDs(context.Background(), "acme_blog_posts", beachcomber.Query{
|
||||
Q: "go",
|
||||
QueryBy: []string{"title"},
|
||||
FilterBy: "blog_id:=7",
|
||||
})
|
||||
fmt.Println(ids, err)
|
||||
|
||||
// Without an API key the engine is not configured and nothing is sent.
|
||||
fmt.Println(typesense.New(typesense.Config{}).Configured())
|
||||
// Output:
|
||||
// GET /collections/acme_blog_posts/documents/search key sent: true
|
||||
// q go query_by title filter_by blog_id:=7
|
||||
// [3 1] <nil>
|
||||
// false
|
||||
}
|
||||
Reference in New Issue
Block a user