• Stars
    star
    316
  • Rank 127,611 (Top 3 %)
  • Language
    Rust
  • License
    MIT License
  • Created almost 4 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Rust wrapper for the Meilisearch API.

Meilisearch-Rust

Meilisearch Rust SDK

Meilisearch | Meilisearch Cloud | Documentation | Discord | Roadmap | Website | FAQ

crates.io Tests License Bors enabled

โšก The Meilisearch API client written for Rust ๐Ÿฆ€

Meilisearch Rust is the Meilisearch API client for Rust developers.

Meilisearch is an open-source search engine. Learn more about Meilisearch.

Table of Contents

๐Ÿ“– Documentation

This readme contains all the documentation you need to start using this Meilisearch SDK.

For general information on how to use Meilisearchโ€”such as our API reference, tutorials, guides, and in-depth articlesโ€”refer to our main documentation website.

โšก Supercharge your Meilisearch experience

Say goodbye to server deployment and manual updates with Meilisearch Cloud. Get started with a 14-day free trial! No credit card required.

๐Ÿ”ง Installation

To use meilisearch-sdk, add this to your Cargo.toml:

[dependencies]
meilisearch-sdk = "0.24.1"

The following optional dependencies may also be useful:

futures = "0.3" # To be able to block on async functions if you are not using an async runtime
serde = { version = "1.0", features = ["derive"] }

This crate is async but you can choose to use an async runtime like tokio or just block on futures. You can enable the sync feature to make most structs Sync. It may be a bit slower.

Using this crate is possible without serde, but a lot of features require serde.

Run a Meilisearch Instance

This crate requires a Meilisearch server to run.

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.

๐Ÿš€ Getting started

Add Documents

use meilisearch_sdk::client::*;
use serde::{Serialize, Deserialize};
use futures::executor::block_on;

#[derive(Serialize, Deserialize, Debug)]
struct Movie {
    id: usize,
    title: String,
    genres: Vec<String>,
}


fn main() { block_on(async move {
    // Create a client (without sending any request so that can't fail)
    let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY));

    // An index is where the documents are stored.
    let movies = client.index("movies");

    // Add some movies in the index. If the index 'movies' does not exist, Meilisearch creates it when you first add the documents.
    movies.add_documents(&[
        Movie { id: 1, title: String::from("Carol"), genres: vec!["Romance".to_string(), "Drama".to_string()] },
        Movie { id: 2, title: String::from("Wonder Woman"), genres: vec!["Action".to_string(), "Adventure".to_string()] },
        Movie { id: 3, title: String::from("Life of Pi"), genres: vec!["Adventure".to_string(), "Drama".to_string()] },
        Movie { id: 4, title: String::from("Mad Max"), genres: vec!["Adventure".to_string(), "Science Fiction".to_string()] },
        Movie { id: 5, title: String::from("Moana"), genres: vec!["Fantasy".to_string(), "Action".to_string()] },
        Movie { id: 6, title: String::from("Philadelphia"), genres: vec!["Drama".to_string()] },
    ], Some("id")).await.unwrap();
})}

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

Basic Search

// Meilisearch is typo-tolerant:
println!("{:?}", client.index("movies_2").search().with_query("caorl").execute::<Movie>().await.unwrap().hits);

Output:

[Movie { id: 1, title: String::from("Carol"), genres: vec!["Romance", "Drama"] }]

Json output:

{
  "hits": [{
    "id": 1,
    "title": "Carol",
    "genres": ["Romance", "Drama"]
  }],
  "offset": 0,
  "limit": 10,
  "processingTimeMs": 1,
  "query": "caorl"
}

Custom Search

let search_result = client.index("movies_3")
  .search()
  .with_query("phil")
  .with_attributes_to_highlight(Selectors::Some(&["*"]))
  .execute::<Movie>()
  .await
  .unwrap();
println!("{:?}", search_result.hits);

Json output:

{
    "hits": [
        {
            "id": 6,
            "title": "Philadelphia",
            "_formatted": {
                "id": 6,
                "title": "<em>Phil</em>adelphia",
                "genre": ["Drama"]
            }
        }
    ],
    "offset": 0,
    "limit": 20,
    "processingTimeMs": 0,
    "query": "phil"
}

Custom Search With Filters

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

let filterable_attributes = [
    "id",
    "genres",
];
client.index("movies_4").set_filterable_attributes(&filterable_attributes).await.unwrap();

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

Then, you can perform the search:

let search_result = client.index("movies_5")
  .search()
  .with_query("wonder")
  .with_filter("id > 1 AND genres = Action")
  .execute::<Movie>()
  .await
  .unwrap();
println!("{:?}", search_result.hits);

Json output:

{
  "hits": [
    {
      "id": 2,
      "title": "Wonder Woman",
      "genres": ["Action", "Adventure"]
    }
  ],
  "offset": 0,
  "limit": 20,
  "estimatedTotalHits": 1,
  "processingTimeMs": 0,
  "query": "wonder"
}

๐ŸŒ Running in the Browser with WASM

This crate fully supports WASM.

The only difference between the WASM and the native version is that the native version has one more variant (Error::Http) in the Error enum. That should not matter so much but we could add this variant in WASM too.

However, making a program intended to run in a web browser requires a very different design than a CLI program. To see an example of a simple Rust web app using Meilisearch, see the our demo.

WARNING: meilisearch-sdk will panic if no Window is available (ex: Web extension).

๐Ÿค– Compatibility with Meilisearch

This package guarantees compatibility with version v1.x of Meilisearch, but some features may not be present. Please check the issues for more info.

โš™๏ธ 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.

More Repositories

1

meilisearch

A lightning-fast search API that fits effortlessly into your apps, websites, and workflow
Rust
43,248
star
2

meilisearch-js

JavaScript client for the Meilisearch API
TypeScript
672
star
3

meilisearch-php

PHP wrapper for the Meilisearch API
PHP
543
star
4

meilisearch-laravel-scout

MeiliSearch integration for Laravel Scout
PHP
467
star
5

milli

Search engine library for Meilisearch โšก๏ธ
Rust
459
star
6

meilisearch-js-plugins

The search client to use Meilisearch with InstantSearch.
TypeScript
449
star
7

meilisearch-go

Golang wrapper for the Meilisearch API
Go
444
star
8

heed

A fully typed LMDB wrapper with minimum overhead ๐Ÿฆ
Rust
424
star
9

meilisearch-python

Python wrapper for the Meilisearch API
Python
400
star
10

MeiliES

A Rust based event store using the Redis protocol
Rust
326
star
11

meilisearch-rails

Meilisearch integration for Ruby on Rails
Ruby
273
star
12

docs-scraper

Scrape documentation into Meilisearch
Python
257
star
13

meilisearch-dotnet

.NET wrapper for the Meilisearch API
C#
232
star
14

strapi-plugin-meilisearch

A strapi plugin to add your collections to Meilisearch
JavaScript
208
star
15

mini-dashboard

mini-dashboard for Meilisearch
JavaScript
204
star
16

charabia

Library used by Meilisearch to tokenize queries and documents
Rust
202
star
17

meilisearch-ruby

Ruby SDK for the Meilisearch API
Ruby
186
star
18

meilisearch-react

182
star
19

meilisearch-kubernetes

Meilisearch on Kubernetes Helm charts and manifests
Mustache
181
star
20

arroy

Annoy-inspired Approximate Nearest Neighbors in Rust, based on LMDB and optimized for memory usage ๐Ÿ’ฅ
Rust
170
star
21

meilisearch-java

Java client for Meilisearch
Java
163
star
22

docs-searchbar.js

Front-end search bar for documentation with Meilisearch
JavaScript
161
star
23

meilisearch-vue

148
star
24

documentation

Meilisearch documentation
MDX
132
star
25

integration-guides

Central reference for Meilisearch integrations.
Shell
127
star
26

meilisearch-symfony

Seamless integration of Meilisearch into your Symfony project.
PHP
111
star
27

awesome-meilisearch

A curated list of awesome Meilisearch resources
88
star
28

meilisearch-swift

Swift client for the Meilisearch API
Swift
87
star
29

firestore-meilisearch

Fulltext search on Firebase with Meilisearch
TypeScript
83
star
30

meilisearch-dart

The Meilisearch API client written for Dart
Dart
73
star
31

ecommerce-demo

Nuxt 3 ecommerce site search with filtering and facets powered by Meilisearch
Vue
73
star
32

vuepress-plugin-meilisearch

Add a relevant and typo tolerant search bar to your VuePress
JavaScript
62
star
33

saas-demo

App search in a CRM use case, powered by Meilisearch
PHP
58
star
34

product

Public feedback and ideation discussions for Meilisearch product ๐Ÿ”ฎ
55
star
35

meilisearch-wordpress

WordPress plugin for Meilisearch.
PHP
53
star
36

demos

A list of Meilisearch demos with open-source code and live preview โšก๏ธ
CoffeeScript
43
star
37

gatsby-plugin-meilisearch

A plugin to index your Gatsby content to Meilisearch based on graphQL queries
JavaScript
40
star
38

demo-movies

A website that lets you know where to watch a movie
JavaScript
34
star
39

landing

Meilisearch's landing page
JavaScript
33
star
40

meilisearch-migration

Scripts to update Meilisearch version's.
Shell
32
star
41

devrel

Anything Developer Relations at Meili
CSS
27
star
42

meilisearch-digitalocean

Meilisearch services on DigitalOcean
Python
24
star
43

meilisearch-angular

Instant Meilisearch for Angular Framework
23
star
44

deserr

Deserialization library with focus on error handling
Rust
22
star
45

meilisearch-aws

AWS services for Meilisearch
Python
20
star
46

cargo-flaky

A cargo sub-command to helps you find flaky tests
Rust
20
star
47

meilisearch-gcp

Meilisearch services on GCP
Python
20
star
48

grenad

Tools to sort, merge, write, and read immutable key-value pairs ๐Ÿ…
Rust
19
star
49

specifications

Track specification elaboration.
18
star
50

madness

an async mdns library for tokio
Rust
17
star
51

demo-finding-crates

Expose all crates from crates.io with MeiliSearch
Rust
17
star
52

scrapix

TypeScript
16
star
53

transplant

Rust
15
star
54

cloud-providers

โ˜ Meilisearch DevOps Tools for the Cloud โ˜
Shell
15
star
55

engine-team

Repository gathering the development process of the core-team
13
star
56

meilisearch-importer

A CLI to import massive CSV and NdJson into Meilisearch
Rust
12
star
57

compute-embeddings

A small tool to compute the embeddings of a list of JSON documents
Rust
10
star
58

cloud-scripts

Cloud scripts for cloud provider agnostic configuration
Shell
9
star
59

demo-finding-rubygems

Alternative search bar for RubyGems
Ruby
8
star
60

minimeili-raft

A small implementation of a dummy Meilisearch running on top of Raft
Rust
7
star
61

demo-MoMA

A MeiliSearch demo using the Museum Of Modern Art Collection
JavaScript
6
star
62

strapi-plugin-meilisearch-v4

Work in progress
JavaScript
6
star
63

searchbar.js

wip
JavaScript
6
star
64

meili-aoc

meili-aoc
Rust
5
star
65

mini-search-engine-presentation

A simple and "short" presentation of the search engine
5
star
66

vercel-demo

A website that lets you know where to watch a movie built on Next.js and Meilisearch, deployed on Vercel with the Meilisearch + Vercel integration.
JavaScript
5
star
67

meilisearch-flutter

[wip] A basic UI kit with Meilisearch search widgets for Flutter
CMake
4
star
68

jayson

Rust
4
star
69

nelson

Rust
4
star
70

demo-finding-pypi

Alternative search bar for PyPI packages
Python
4
star
71

nextjs-starter-meilisearch-table

TypeScript
3
star
72

js-project-boilerplate

A boilerplate providing basic configuration for JavaScript projects in Meilisearch
3
star
73

synonyms

2
star
74

devops-tools

Shell
2
star
75

discord-bot-productboard

JavaScript
2
star
76

strois

A simple non-async S3 client based on the REST API
Rust
2
star
77

datasets

2
star
78

poc-vector-store-recall

A experimental tool that uses the vector store to increase Meilisearch's recall
Rust
2
star
79

.github

1
star
80

actions

Meilisearch Github Actions
JavaScript
1
star
81

devspector

Develop specification inspector
JavaScript
1
star
82

design-team

1
star
83

movies-react-demo

Created with CodeSandbox
HTML
1
star
84

ansible-vm-benchmarks

Ansible Playbook to index datasets on several typology of Instance on a specific Meilisearch version/commit
Rust
1
star
85

akamai-purge

A Rust helper to purge Akamai cache
Rust
1
star
86

poc-heed-codec

A repository to help us define the new design of heed
Rust
1
star
87

mainspector

Main specification inspector
JavaScript
1
star
88

settings_guessr

A tool that guess your settings by using the dataset
Rust
1
star
89

meilisearch-webhook-usage-example

Example of how to use the meilisearch webhook
Rust
1
star
90

meilikeeper

A sync zookeeper client on top of the official C client
Rust
1
star
91

massive-meilisearch-sampling

A program that generates and sends dataset and samples update/deletes to a Meilisearch server
Rust
1
star
92

zookeeper-client-sync

zookeeper-client-sync
Rust
1
star