CaroFG / meilisearch-ruby

Ruby wrapper for the MeiliSearch API

Home Page:https://github.com/meilisearch/MeiliSearch

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MeiliSearch-Ruby

MeiliSearch Ruby

Latest Stable Version Test License Slack Bors enabled

⚑ The MeiliSearch API client written for Ruby πŸ’Ž

MeiliSearch Ruby is the MeiliSearch API client for Ruby developers. MeiliSearch is a powerful, fast, open-source, easy to use and deploy search engine. Both searching and indexing are highly customizable. Features such as typo-tolerance, filters, facets, and synonyms are provided out-of-the-box.

Table of Contents

πŸ“– Documentation

See our Documentation or our API References.

πŸ”§ Installation

With gem in command line:

$ gem install meilisearch

In your Gemfile with bundler:

source 'https://rubygems.org'

gem 'meilisearch'

Run MeiliSearch

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

For example, if you use Docker:

$ docker pull getmeili/meilisearch:latest # Fetch the latest version of MeiliSearch image from Docker Hub
$ docker run -it --rm -p 7700:7700 getmeili/meilisearch:latest ./meilisearch --master-key=masterKey

NB: you can also download MeiliSearch from Homebrew or APT.

πŸš€ Getting Started

Add documents

require 'meilisearch'

client = MeiliSearch::Client.new('http://127.0.0.1:7700', 'masterKey')
index = client.create_index('books') # If your index does not exist
index = client.index('books')        # If you already created your index

documents = [
  { book_id: 123,  title: 'Pride and Prejudice' },
  { book_id: 456,  title: 'Le Petit Prince' },
  { book_id: 1,    title: 'Alice In Wonderland' },
  { book_id: 1344, title: 'The Hobbit' },
  { book_id: 4,    title: 'Harry Potter and the Half-Blood Prince' },
  { book_id: 42,   title: 'The Hitchhiker\'s Guide to the Galaxy' }
]
index.add_documents(documents) # => { "updateId": 0 }

With the updateId, you can check the status (enqueued, processed or failed) of your documents addition using the update endpoint.

Basic Search

# MeiliSearch is typo-tolerant:
puts index.search('harry pottre')

Output:

{
  "hits" => [{
    "book_id" => 4,
    "title" => "Harry Potter and the Half-Blood Prince"
  }],
  "offset" => 0,
  "limit" => 20,
  "processingTimeMs" => 1,
  "query" => "harry pottre"
}

Custom search

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

index.search('prince',
  {
    filters: 'book_id > 10',
    attributesToHighlight: ['*']
  }
)

JSON output:

{
    "hits": [
        {
            "book_id": 456,
            "title": "Le Petit Prince",
            "_formatted": {
                "book_id": 456,
                "title": "Le Petit <em>Prince</em>"
            }
        }
    ],
    "offset": 0,
    "limit": 20,
    "processingTimeMs": 0,
    "query": "prince"
}

πŸ€– Compatibility with MeiliSearch

This package only guarantees the compatibility with the version v0.16.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.

About

Ruby wrapper for the MeiliSearch API

https://github.com/meilisearch/MeiliSearch

License:MIT License


Languages

Language:Ruby 99.4%Language:Shell 0.6%