mirror of
https://github.com/foomo/typesense.git
synced 2025-10-16 12:45:37 +00:00
Bumps the gomod-update group with 2 updates in the / directory: [github.com/foomo/contentserver](https://github.com/foomo/contentserver) and [github.com/typesense/typesense-go/v3](https://github.com/typesense/typesense-go). Updates `github.com/foomo/contentserver` from 1.11.2 to 1.12.0 - [Release notes](https://github.com/foomo/contentserver/releases) - [Changelog](https://github.com/foomo/contentserver/blob/main/.goreleaser.yml) - [Commits](https://github.com/foomo/contentserver/compare/v1.11.2...v1.12.0) Updates `github.com/typesense/typesense-go/v3` from 3.0.0 to 3.2.0 - [Release notes](https://github.com/typesense/typesense-go/releases) - [Commits](https://github.com/typesense/typesense-go/compare/v3.0.0...v3.2.0) --- updated-dependencies: - dependency-name: github.com/foomo/contentserver dependency-version: 1.12.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: gomod-update - dependency-name: github.com/typesense/typesense-go/v3 dependency-version: 3.2.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: gomod-update ... Signed-off-by: dependabot[bot] <support@github.com> |
||
|---|---|---|
| .github | ||
| .husky | ||
| pkg | ||
| .editorconfig | ||
| .gitignore | ||
| .golangci.yml | ||
| .goreleaser.yml | ||
| .husky.yaml | ||
| go.mod | ||
| go.sum | ||
| LICENSE | ||
| Makefile | ||
| README.md | ||
Typesense API
Overview
This package provides an API for managing and searching Typesense collections. It offers functionalities for initializing, indexing, searching, and maintaining Typesense collections and aliases.
Features
- Initialization: Ensures that all aliases point to the latest revision-based collections.
- Health Check: Verifies if the Typesense client is operational.
- Index Management: Lists, creates, and updates index collections.
- Document Upsertion: Bulk upsert support for indexing documents.
- Search Operations: Provides simple and advanced search capabilities.
- Revision Management: Supports committing and reverting indexing revisions.
Installation
To use this package, add it as a dependency in your Go project:
go get github.com/foomo/typesense
Usage example
import (
"context"
"time"
"github.com/foomo/contentserver/client"
"github.com/foomo/keel/config"
"github.com/foomo/keel/log"
typesenseapi "github.com/foomo/typesense/pkg/api"
typesenseindexing "github.com/foomo/typesense/pkg/indexing"
"github.com/typesense/typesense-go/v3/typesense"
)
func main() {
ctx := context.Background()
l := log.Logger()
// contentserver client
csClient, errClient := client.NewHTTPClient("contentserver_url")
log.Must(l, errClient, "could not get contentserver client")
// contentful client
// provide list of content types
cfClients := contentful.NewDefaultContentfulClients(ctx, l, contentful_types, true)
cfClients.UpdateCache()
cfClients.Client.ClientStats()
// create typesense client
typesenseClient := typesense.NewClient(
typesense.WithConnectionTimeout(2*time.Minute),
typesense.WithServer("typesense_server"),
typesense.WithAPIKey("typesense_api_key"),
)
// configure document provider
documentProvider := typesenseindexing.NewContentServer(
l, csClient,
GetDocumentProviderFunctions(...), // retrieve document provider functions
supportedMimeTypes, // provide supported mime types
)
// create typesense api
// create indexDocument and returnType
api := typesenseapi.NewBaseAPI[indexDocument, returnType](
l,
typesenseClient,
collectionSchemas, //map[IndexID]*api.CollectionSchema
presetUpsertSchema, //*api.PresetUpsertSchema
)
// create typesense indexer
indexer := typesenseindexing.NewBaseIndexer(
l,
api,
documentProvider,
)
// run indexer
err := indexer.Run(ctx)
log.Must(l, err, "could not run indexer")
}
Health Check
err := apiInstance.Healthz(context.Background())
if err != nil {
log.Fatalf("Health check failed: %v", err)
}
Searching Documents
Simple Search
results, scores, total, err := apiInstance.SimpleSearch(context.Background(), "products", "laptop", nil, 1, 10, "price:desc")
if err != nil {
log.Fatalf("Search failed: %v", err)
}
log.Printf("Found %d results", total)
Advanced Search
searchParams := &api.SearchCollectionParams{
Q: pointer.String("laptop"),
SortBy: pointer.String("price:desc"),
}
results, scores, total, err = apiInstance.ExpertSearch(context.Background(), "products", searchParams)
if err != nil {
log.Fatalf("Advanced search failed: %v", err)
}
log.Printf("Found %d results", total)
How to Contribute
Please refer to the CONTRIBUTING details and follow the CODE_OF_CONDUCT and SECURITY guidelines.
License
Distributed under MIT License, please see license file within the code for more details.