ariews / elastic-scout-driver-plus

Extension for Elastic Scout Driver

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Buy Me A Coffee


Extension for Elastic Scout Driver.

Contents

Features

Elastic Scout Driver Plus supports:

Compatibility

The current version of Elastic Scout Driver Plus has been tested with the following configuration:

  • PHP 7.2-8.0
  • Elasticsearch 7.0-7.10
  • Laravel 6.x-8.x
  • Laravel Scout 7.x-8.x
  • Elastic Scout Driver 1.x

Installation

The library can be installed via Composer:

composer require babenkoivan/elastic-scout-driver-plus

Note, that the library doesn't work without Elastic Scout Driver. If it's not installed yet, please follow the installation steps described here. If you are already using Elastic Scout Driver, I recommend you to update it before installing Elastic Scout Driver Plus:

composer update babenkoivan/elastic-scout-driver

If you want to use Elastic Scout Driver Plus with Lumen framework refer to this guide.

Usage

Elastic Scout Driver Plus comes with a new trait QueryDsl, which you need to add in your model to activate advanced search functionality:

class Book extends Model
{
    use Searchable;
    use QueryDsl;
}

This trait adds a bunch of factory methods in your model: boolSearch(), matchSearch(), rawSearch(), etc. Each method creates a search request builder for specific query type. For example, if you want to make a match query use matchSearch() method:

$searchResult = Book::matchSearch()
    ->field('title')
    ->query('My book')
    ->fuzziness('AUTO')
    ->size(10)
    ->execute();

Choose factory method depending on the query type you wish to perform:

If there is no method for the query type you need, you can use rawSearch():

$searchResult = Book::rawSearch()
    ->query(['match' => ['title' => 'The Book']])
    ->execute();

It is important to know, that all search request builders share the same generic methods, which provide such basic functionality as sorting, highlighting, etc. Check the full list of available generic methods and the usage examples here.

Finally, refer to this page to get familiar with $searchResult object, pagination and more.

About

Extension for Elastic Scout Driver

License:MIT License


Languages

Language:PHP 98.7%Language:Makefile 1.3%