All Projects → meilisearch → meilisearch-go

meilisearch / meilisearch-go

Licence: MIT license
Golang wrapper for the Meilisearch API

Programming Languages

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

Projects that are alternatives of or similar to meilisearch-go

product
Public feedback and ideation discussions for Meilisearch product 🔮
Stars: ✭ 26 (-87%)
Mutual labels:  meilisearch
docs-searchbar.js
Front-end search bar for documentation with Meilisearch
Stars: ✭ 128 (-36%)
Mutual labels:  meilisearch
meilisearch-dart
The Meilisearch API client written for Dart
Stars: ✭ 48 (-76%)
Mutual labels:  meilisearch
milli
Search engine library for Meilisearch ⚡️
Stars: ✭ 433 (+116.5%)
Mutual labels:  meilisearch
mongomeili
Keep your Mongoose Schemas synced with MeiliSearch
Stars: ✭ 33 (-83.5%)
Mutual labels:  meilisearch
meilisearch-dotnet
.NET wrapper for the Meilisearch API
Stars: ✭ 66 (-67%)
Mutual labels:  meilisearch
meilisearch-vue
www.meilisearch.com/
Stars: ✭ 80 (-60%)
Mutual labels:  meilisearch
meilisearch-react
www.meilisearch.com/
Stars: ✭ 87 (-56.5%)
Mutual labels:  meilisearch

Meilisearch-Go

Meilisearch Go

Meilisearch | Documentation | Slack | Roadmap | Website | FAQ

GitHub Workflow Status Test License Bors enabled

The Meilisearch API client written for Golang

Meilisearch Go is the Meilisearch API client for Go developers.

Meilisearch is an open-source search engine. Discover what Meilisearch is!

Table of Contents

📖 Documentation

See our Documentation or our API References.

🔧 Installation

With go get in command line:

go get github.com/meilisearch/meilisearch-go

Run Meilisearch

There are many easy ways to download and run a Meilisearch instance.

For example, using the curl command in your Terminal:

# Install Meilisearch
curl -L https://install.meilisearch.com | sh

# Launch Meilisearch
./meilisearch --master-key=masterKey

NB: you can also download Meilisearch from Homebrew or APT or even run it using Docker.

🚀 Getting Started

Add documents

package main

import (
	"fmt"
	"os"

	"github.com/meilisearch/meilisearch-go"
)

func main() {
	client := meilisearch.NewClient(meilisearch.ClientConfig{
                Host: "http://127.0.0.1:7700",
                APIKey: "masterKey",
        })
	// An index is where the documents are stored.
	index := client.Index("movies")

	// If the index 'movies' does not exist, Meilisearch creates it when you first add the documents.
	documents := []map[string]interface{}{
        { "id": 1, "title": "Carol", "genres": []string{"Romance", "Drama"} },
        { "id": 2, "title": "Wonder Woman", "genres": []string{"Action", "Adventure"} },
        { "id": 3, "title": "Life of Pi", "genres": []string{"Adventure", "Drama"} },
        { "id": 4, "title": "Mad Max: Fury Road", "genres": []string{"Adventure", "Science Fiction"} },
        { "id": 5, "title": "Moana", "genres": []string{"Fantasy", "Action"} },
        { "id": 6, "title": "Philadelphia", "genres": []string{"Drama"} },
	}
	task, err := index.AddDocuments(documents)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	fmt.Println(task.taskID)
}

With the taskID, you can check the status (enqueued, processing, succeeded or failed) of your documents addition using the task endpoint.

Basic Search

package main

import (
    "fmt"
    "os"

    "github.com/meilisearch/meilisearch-go"
)

func main() {
    // Meilisearch is typo-tolerant:
    searchRes, err := client.Index("movies").Search("philoudelphia",
        &meilisearch.SearchRequest{
            Limit: 10,
        })
    if err != nil {
        fmt.Println(err)
        os.Exit(1)
    }

    fmt.Println(searchRes.Hits)
}

JSON output:

{
  "hits": [{
    "id": 6,
    "title": "Philadelphia",
    "genres": ["Drama"]
  }],
  "offset": 0,
  "limit": 10,
  "processingTimeMs": 1,
  "query": "philoudelphia"
}

Custom Search

All the supported options are described in the search parameters section of the documentation.

func main() {
    searchRes, err := client.Index("movies").Search("wonder",
        &meilisearch.SearchRequest{
            AttributesToHighlight: []string{"*"},
        })
    if err != nil {
        fmt.Println(err)
        os.Exit(1)
    }

    fmt.Println(searchRes.Hits)
}

JSON output:

{
    "hits": [
        {
            "id": 2,
            "title": "Wonder Woman",
            "genres": ["Action", "Adventure"],
            "_formatted": {
                "id": 2,
                "title": "<em>Wonder</em> Woman"
            }
        }
    ],
    "offset": 0,
    "limit": 20,
    "processingTimeMs": 0,
    "query": "wonder"
}

Custom Search With Filters

If you want to enable filtering, you must add your attributes to the filterableAttributes index setting.

task, err := index.UpdateFilterableAttributes(&[]string{"id", "genres"})

You only need to perform this operation once.

Note that Meilisearch will rebuild your index whenever you update filterableAttributes. Depending on the size of your dataset, this might take time. You can track the process using the task status.

Then, you can perform the search:

searchRes, err := index.Search("wonder",
    &meilisearch.SearchRequest{
        Filter: "id > 1 AND genres = Action",
    })
{
  "hits": [
    {
      "id": 2,
      "title": "Wonder Woman",
      "genres": ["Action","Adventure"]
    }
  ],
  "offset": 0,
  "limit": 20,
  "nbHits": 1,
  "processingTimeMs": 0,
  "query": "wonder"
}

🤖 Compatibility with Meilisearch

This package only guarantees the compatibility with the version v0.27.0 of Meilisearch.

💡 Learn More

The following sections may interest you:

⚙️ Development Workflow and Contributing

Any new contribution is more than welcome in this project!

If you want to know more about the development workflow or want to contribute, please visit our contributing guidelines for detailed instructions!


Meilisearch provides and maintains many SDKs and Integration tools like this one. We want to provide everyone with an amazing search experience for any kind of project. If you want to contribute, make suggestions, or just know what's going on right now, visit us in the integration-guides repository.

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].