Coder Social home page Coder Social logo

strogo / meilisearch-laravel-scout Goto Github PK

View Code? Open in Web Editor NEW

This project forked from meilisearch/meilisearch-laravel-scout

0.0 2.0 0.0 97 KB

Laravel Scout Engine for Meilisearch

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

License: MIT License

PHP 100.00%

meilisearch-laravel-scout's Introduction

MeiliSearch Laravel Scout

MeiliSearch Laravel Scout

MeiliSearch | Documentation | Roadmap | Website | Blog | Twitter | FAQ

Latest Stable Version Actions Status License Slack Bors enabled

The MeiliSearch driver for Laravel Scout

MeiliSearch Laravel Scout is a MeiliSearch driver for Laravel. 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

Installation

Install the Plugin

$ composer require meilisearch/meilisearch-laravel-scout

Install the HTTP Client

You could use any PSR-18 compatible client to use with this SDK. No additional configurations are required.
A list of compatible HTTP clients and client adapters can be found at php-http.org.

If you use Laravel 8 you can skip this section as laravel pre-install Guzzle 7 by default.

Guzzle 7:

$ composer require guzzlehttp/guzzle

If you already have guzzle installed with a version < 7, don't forget to update the version inside your composer.json

"require": {
  "guzzlehttp/guzzle": "^7.0"
}

Guzzle 6:

$ composer require php-http/guzzle6-adapter

Symfony Http Client:

$ composer require symfony/http-client nyholm/psr7

Curl:

$ composer require php-http/curl-client nyholm/psr7

Export configuration

$ php artisan vendor:publish --provider="Laravel\Scout\ScoutServiceProvider"
$ php artisan vendor:publish --provider="Meilisearch\Scout\MeilisearchServiceProvider" --tag="config"

Update .env

SCOUT_DRIVER=meilisearch
MEILISEARCH_HOST=http://127.0.0.1:7700
MEILISEARCH_KEY=masterKey

Run MeiliSearch

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

For example, if you use Docker:

$ 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

Indexes

Create an index

// Create an index
$ php artisan scout:index books
// Create an index and give the primary-key
$ php artisan scout:index books --key book_id

Add document

<?php

use Laravel\Scout\Searchable;

class Book extends Model
{
    use Searchable;
}
<?php

class BookController extends Controller
{
    public function store()
    {
        $book = new Book();
        $book->title = 'Pride and Prejudice';
        ...
        $book->save();
    }
}

You can also import all your table to meilisearch by using the artisan command:

$ php artisan scout:import "App\Book"

Search in index

class BookController extends Controller
{
    public function search()
    {
        // MeiliSearch is typo-tolerant:
        Book::search('harry pottre')->get();
        // Or if you want to get the result from meilisearch:
        Book::search('harry pottre')->raw();
    }
}

Delete documents

class BookController extends Controller
{
    public function destroy($id)
    {
        // Delete one document
        Book::find($id)->delete();
        // Delete several documents
        Book::destroy([1, 42]);
        // Delete all documents /!\
        Book::query()->delete();
    }
}

or you can use the artisan command to delete all documents from an index:

$ php artisan scout:flush "App\Book"

Delete an index

$ php artisan scout:index -d books

Search

Custom search

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

class BookController extends Controller
{
    public function customSearch()
    {
        Book::search('prince', function (Indexes $meilisearch, $query, $options) {
            $options['filters'] = 'author="Antoine de Saint-Exupéry"';

            return $meilisearch->search($query, $options);
        })->take(3)->get();
    }
}

Pagination

class BookController extends Controller
{
    public function search()
    {
        Book::search('mustang')->paginate();
        // with a limit of items per page:
        Book::search('mustang')->paginate(5);
        // using meilisearch response:
        Book::search('mustang')->paginateRaw();
    }
}

Compatibility with MeiliSearch

This package only guarantees the compatibility with the version v0.17.0 of MeiliSearch.

Documentation

See our Documentation and the Wiki of this repository.

Additional notes

You can use more advance function by reading the documentation of MeiliSearch PHP Client

This package is a custom engine of Laravel Scout

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.

meilisearch-laravel-scout's People

Contributors

alifjafar avatar bensherred avatar bors[bot] avatar cannonb4ll avatar cappuc avatar curquiza avatar dependabot-preview[bot] avatar josecanhelp avatar jwohlfert23 avatar lkmadushan avatar matboivin avatar meili-bot avatar pet1330 avatar qdequele avatar shokme avatar willvincent avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.