Giter VIP home page Giter VIP logo

manticore-scout-engine's Introduction

Manticore Scout Engine

Release

Manticore Engine for Laravel Scout

Installation

Via Composer

$ composer require romanstruk/manticore-scout-engine

Configuration

After installing Manticore Scout Engine, you should publish the Manticore configuration file using the vendor:publish Artisan command. This command will publish the manticore.php configuration file to your application's config directory:

php artisan vendor:publish --provider="RomanStruk\ManticoreScoutEngine\ManticoreServiceProvider"
php artisan vendor:publish --provider="Laravel\Scout\ScoutServiceProvider"

Configuring Search Driver

Set up your search driver manticore in .env file

SCOUT_DRIVER=manticore

There is a choice between two ways to connect to the manticore

  • http-client - \Manticoresearch\Client github
  • mysql-builder - \RomanStruk\ManticoreScoutEngine\Builder use mysql connection

Set up your engine in .env file

MANTICORE_ENGINE=http-client

Configuring Driver Connection

For http-client in .env file

MANTICORE_HOST=localhost
MANTICORE_PORT=9308

For mysql-builder in .env file

MANTICORE_MYSQL_HOST=127.0.0.1
MANTICORE_MYSQL_PORT=9306

Configuring Model Migration

To create a migration, specify the required fields in the searchable model

public function scoutIndexMigration(): array
{
    return [
        'fields' => [
            'id' => ['type' => 'bigint'],
            'name' => ['type' => 'text'],
        ],
        'settings' => [
            'min_prefix_len' => '3',
            'min_infix_len' => '3',
            'prefix_fields' => 'name',
            'expand_keywords' => '1',
        ],
    ];
}

Configuring query options

max_matches - Maximum amount of matches that the server keeps in RAM for each index and can return to the client. Default is 1000.

For queries with pagination, you can specify automatic parameter calculation max_matches Set up your paginate_max_matches in manticore.php config file

'paginate_max_matches' => 1000,

Set null for calculate offset + limit

As some characters are used as operators in the query string, they should be escaped to avoid query errors or unwanted matching conditions. Set up your auto_escape_search_phrase in manticore.php config file

'auto_escape_search_phrase' => true,

Set false for disable auto escape special symbols ! " $ ' ( ) - / < @ \ ^ | ~

Other parameters for queries can be specified in the model

public function scoutMetadata(): array
{
    return [
        'cutoff' => 0,
        'max_matches' => 1000,
    ];
}

Config paginate_max_matches has higher priority than scoutMetadata max_matches option

Usage

Documentation for Scout can be found on the Laravel website.

Run artisan command for create Manticore index

php artisan manticore:index "App\Models\Product"

Manticore allows you to add "whereRaw" methods to your search queries.

use RomanStruk\ManticoreScoutEngine\Mysql\Builder;

$products = Product::search('Brand Name', function (Builder $builder) {
    return $builder
        ->whereAny('category_id', ['1', '2', '3'])
        ->facet('category_id')
        ->inRandomOrder();
})->get();

Quorum matching operator introduces a kind of fuzzy matching. It will only match those documents that pass a given threshold of given words. The example above ("the world is a wonderful place"/3) will match all documents that have at least 3 of the 6 specified words.

use RomanStruk\ManticoreScoutEngine\Mysql\Builder;

$products = Product::search('the world is a wonderful place', function (Builder $builder) {
    return $builder->setQuorumMatchingOperator(3);
})->get();

Proximity distance is specified in words, adjusted for word count, and applies to all words within quotes. For instance, "cat dog mouse"~5 query means that there must be less than 8-word span which contains all 3 words, ie.

use RomanStruk\ManticoreScoutEngine\Mysql\Builder;

$products = Product::search('cat dog mouse', function (Builder $builder) {
    return $builder->setProximitySearchOperator(5);
})->get();

Change log

Please see the changelog for more information on what has changed recently.

Testing

$ composer test

Contributing

Please see contributing.md for details and a todolist.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

License

MIT. Please see the license file for more information.

manticore-scout-engine's People

Contributors

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