All Projects → typesense → typesense-go

typesense / typesense-go

Licence: Apache-2.0 License
Go client for Typesense: https://github.com/typesense/typesense

Programming Languages

go
31211 projects - #10 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to typesense-go

Typesense
Fast, typo tolerant, fuzzy search engine for building delightful search experiences ⚡ 🔍 ✨ An Open Source alternative to Algolia and an Easier-to-Use alternative to ElasticSearch.
Stars: ✭ 8,644 (+14070.49%)
Mutual labels:  search, typesense
rgpipe
lesspipe for ripgrep for common new filetypes using few dependencies
Stars: ✭ 21 (-65.57%)
Mutual labels:  search
Persistent Search View
An Android library designed to simplify the process of implementing search-related functionality.
Stars: ✭ 232 (+280.33%)
Mutual labels:  search
Alfred Searchio
Alfred workflow to auto-suggest search results from multiple search engines and languages.
Stars: ✭ 250 (+309.84%)
Mutual labels:  search
Jina
Cloud-native neural search framework for 𝙖𝙣𝙮 kind of data
Stars: ✭ 12,618 (+20585.25%)
Mutual labels:  search
typesense-dart
Dart client for Typesense
Stars: ✭ 50 (-18.03%)
Mutual labels:  typesense
Elastix
A simple Elasticsearch REST client written in Elixir.
Stars: ✭ 231 (+278.69%)
Mutual labels:  search
uspto-opendata-python
A client library for accessing the USPTO Open Data APIs, written in Python.
Stars: ✭ 51 (-16.39%)
Mutual labels:  search
showcase-books-search
A site to instantly search 28M books from OpenLibrary using Typesense Search (an open source alternative to Algolia / ElasticSearch) ⚡ 📚 🔍
Stars: ✭ 117 (+91.8%)
Mutual labels:  typesense
Chipmunk
log analysis tool
Stars: ✭ 247 (+304.92%)
Mutual labels:  search
Codequestion
Ask coding questions directly from the terminal
Stars: ✭ 246 (+303.28%)
Mutual labels:  search
Ajax Live Search
AJAX Live Search is a PHP search form that similar to Google Autocomplete feature displays the result as you type.
Stars: ✭ 238 (+290.16%)
Mutual labels:  search
typesense-js
JavaScript / TypeScript client for Typesense
Stars: ✭ 239 (+291.8%)
Mutual labels:  typesense
Place Search Dialog
A place autocomplete search dialog which uses Google's places API for finding results.
Stars: ✭ 235 (+285.25%)
Mutual labels:  search
food-help
A clone of popular food and business review web app yelp
Stars: ✭ 24 (-60.66%)
Mutual labels:  search
Image Match
🎇 Quickly search over billions of images
Stars: ✭ 2,662 (+4263.93%)
Mutual labels:  search
Haskell Symbol Search Cheatsheet
Haskell/GHC symbol search cheatsheet
Stars: ✭ 243 (+298.36%)
Mutual labels:  search
Datbase
[DEPRECATED] Open data sharing powered by Dat
Stars: ✭ 251 (+311.48%)
Mutual labels:  search
v-oogle
Google.com, reVued. 🔎
Stars: ✭ 40 (-34.43%)
Mutual labels:  search
ci4-album
🔥 CodeIgniter 4 example Album module uses Domain Driven Design Architecture with Tactical Pattern
Stars: ✭ 67 (+9.84%)
Mutual labels:  search

typesense-go

Build Status GoReportCard Status Go Reference GitHub release Gitter

Go client for the Typesense API: https://github.com/typesense/typesense

Installation

go get github.com/typesense/typesense-go

Usage

Import the the package into your code :

import "github.com/typesense/typesense-go/typesense"

Create new client:

client := typesense.NewClient(
	    typesense.WithServer("http://localhost:8108"),
	    typesense.WithAPIKey("<API_KEY>"))

New client with advanced configuration options (see godoc):

client := typesense.NewClient(
		typesense.WithServer("http://localhost:8108"),
		typesense.WithAPIKey("<API_KEY>"),
		typesense.WithConnectionTimeout(5*time.Second),
		typesense.WithCircuitBreakerMaxRequests(50),
		typesense.WithCircuitBreakerInterval(2*time.Minute),
		typesense.WithCircuitBreakerTimeout(1*time.Minute),
	)

You can also find some examples in integration tests.

Create a collection

	schema := &api.CollectionSchema{
		Name: "companies",
		Fields: []api.Field{
			{
				Name: "company_name",
				Type: "string",
			},
			{
				Name: "num_employees",
				Type: "int32",
			},
			{
				Name:  "country",
				Type:  "string",
				Facet: true,
			},
		},
		DefaultSortingField: "num_employees",
	}

	client.Collections().Create(schema)

Index a document

	document := struct {
		ID           string `json:"id"`
		CompanyName  string `json:"company_name"`
		NumEmployees int    `json:"num_employees"`
		Country      string `json:"country"`
	}{
		ID:           "123",
		CompanyName:  "Stark Industries",
		NumEmployees: 5215,
		Country:      "USA",
	}

	client.Collection("companies").Documents().Create(document)

Upserting a document

	document := struct {
		ID           string `json:"id"`
		CompanyName  string `json:"company_name"`
		NumEmployees int    `json:"num_employees"`
		Country      string `json:"country"`
	}{
		ID:           "123",
		CompanyName:  "Stark Industries",
		NumEmployees: 5215,
		Country:      "USA",
	}

	client.Collection("companies").Documents().Upsert(newDocument)

Search a collection

	searchParameters := &api.SearchCollectionParams{
		Q:        "stark",
		QueryBy:  []string{"company_name"},
		FilterBy: pointer.String("num_employees:>100"),
		SortBy:   &([]string{"num_employees:desc"}),
	}

	client.Collection("companies").Documents().Search(searchParameters)

Retrieve a document

client.Collection("companies").Document("123").Retrieve()

Update a document

	document := struct {
		CompanyName  string `json:"company_name"`
		NumEmployees int    `json:"num_employees"`
	}{
		CompanyName:  "Stark Industries",
		NumEmployees: 5500,
	}

	client.Collection("companies").Document("123").Update(document)

Delete an individual document

client.Collection("companies").Document("123").Delete()

Delete a bunch of documents

filter := &api.DeleteDocumentsParams{FilterBy: "num_employees:>100", BatchSize: 100}
client.Collection("companies").Documents().Delete(filter)

Retrieve a collection

client.Collection("companies").Retrieve()

Export documents from a collection

client.Collection("companies").Documents().Export()

Import documents into a collection

The documents to be imported can be either an array of document objects or be formatted as a newline delimited JSON string (see JSONL).

Import an array of documents:

	documents := []interface{}{
		struct {
			ID           string `json:"id"`
			CompanyName  string `json:"companyName"`
			NumEmployees int    `json:"numEmployees"`
			Country      string `json:"country"`
		}{
			ID:           "123",
			CompanyName:  "Stark Industries",
			NumEmployees: 5215,
			Country:      "USA",
		},
	}
	params := &api.ImportDocumentsParams{
		Action:    "create",
		BatchSize: 40,
	}

	client.Collection("companies").Documents().Import(documents, params)

Import a JSONL file:

	params := &api.ImportDocumentsParams{
		Action:    "create",
		BatchSize: 40,
	}
	importBody, err := os.Open("documents.jsonl")
	// defer close, error handling ...

	client.Collection("companies").Documents().ImportJsonl(importBody, params)

List all collections

client.Collections().Retrieve()

Drop a collection

client.Collection("companies").Delete()

Create an API Key

	keySchema := &api.ApiKeySchema{
		Description: "Search-only key.",
		Actions:     []string{"documents:search"},
		Collections: []string{"companies"},
		ExpiresAt:   time.Now().AddDate(0, 6, 0).Unix(),
	}

	client.Keys().Create(keySchema)

Retrieve an API Key

client.Key(1).Retrieve()

List all keys

client.Keys().Retrieve()

Delete API Key

client.Key(1).Delete()

Create or update an override

	override := &api.SearchOverrideSchema{
		Rule: api.SearchOverrideRule{
			Query: "apple",
			Match: "exact",
		},
		Includes: []api.SearchOverrideInclude{
			{
				Id:       "422",
				Position: 1,
			},
			{
				Id:       "54",
				Position: 2,
			},
		},
		Excludes: []api.SearchOverrideExclude{
			{
				Id: "287",
			},
		},
	}

	client.Collection("companies").Overrides().Upsert("customize-apple", override)

List all overrides

client.Collection("companies").Overrides().Retrieve()

Delete an override

client.Collection("companies").Override("customize-apple").Delete()

Create or Update an alias

	body := &api.CollectionAliasSchema{CollectionName: "companies_june11"}
	client.Aliases().Upsert("companies", body)

Retrieve an alias

client.Alias("companies").Retrieve()

List all aliases

client.Aliases().Retrieve()

Delete an alias

client.Alias("companies").Delete()

Create or update a multi-way synonym

	synonym := &api.SearchSynonymSchema{
		Synonyms: []string{"blazer", "coat", "jacket"},
	}
	client.Collection("products").Synonyms().Upsert("coat-synonyms", synonym)

Create or update a one-way synonym

	synonym := &api.SearchSynonymSchema{
		Root:     "blazer",
		Synonyms: []string{"blazer", "coat", "jacket"},
	}
	client.Collection("products").Synonyms().Upsert("coat-synonyms", synonym)

Retrieve a synonym

client.Collection("products").Synonym("coat-synonyms").Retrieve()

List all synonyms

client.Collection("products").Synonyms().Retrieve()

Delete a synonym

client.Collection("products").Synonym("coat-synonyms").Delete()

Create snapshot (for backups)

client.Operations().Snapshot("/tmp/typesense-data-snapshot")

Re-elect Leader

client.Operations().Vote()

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/typesense/typesense-go.

Development Workflow Setup

Install dependencies,

go mod download

Update the generated files,

go generate

NOTE: Make sure you have GOBIN in environment variables

License

typesense-go is distributed under the Apache 2 license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].