All Projects → james2doyle → laravel-scout-sonic

james2doyle / laravel-scout-sonic

Licence: MIT License
Sonic driver for Laravel Scout

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to laravel-scout-sonic

psonic
Sonic is a super fast auto suggestion engine built by the team at crisp.chat, a customer engagement platform. its built in Rust and they officially support a javascript client, but if you want to use sonic via php, this is the library that you can look for. Completely unit tested, and adheres to modern coding standards, and offers a clean api to…
Stars: ✭ 90 (+91.49%)
Mutual labels:  sonic
python-sonic-client
sonic search backend client in python
Stars: ✭ 45 (-4.26%)
Mutual labels:  sonic
sonic-gms2
A GameMaker Studio 2 template project used for constructing games based on the Sonic the Hedgehog series.
Stars: ✭ 18 (-61.7%)
Mutual labels:  sonic
sonix
An Elixir client for Sonic Search
Stars: ✭ 56 (+19.15%)
Mutual labels:  sonic
outrun
A Sonic Runners custom server.
Stars: ✭ 68 (+44.68%)
Mutual labels:  sonic
Sonic-1-2-2013-Decompilation
Sonic 1/2 (2013) Decompilation for New 3DS
Stars: ✭ 41 (-12.77%)
Mutual labels:  sonic
poly-commit
A Rust library for polynomial commitments
Stars: ✭ 170 (+261.7%)
Mutual labels:  sonic
laravel-datatables-scout
Laravel DataTables plugin to support Laravel Scout.
Stars: ✭ 12 (-74.47%)
Mutual labels:  scout
wi
Installer for Python Wheels
Stars: ✭ 17 (-63.83%)
Mutual labels:  sonic
dellemc.enterprise sonic
Ansible Network Collection for Enterprise SONiC Distribution by Dell Technologies
Stars: ✭ 26 (-44.68%)
Mutual labels:  sonic
HedgeLib
A C++ library and collection of tools that aims to make modding games in the Sonic the Hedgehog franchise easier.
Stars: ✭ 63 (+34.04%)
Mutual labels:  sonic
XinFramework
Android 快速开发框架 总结以往开发结合三方项目 不断更新
Stars: ✭ 21 (-55.32%)
Mutual labels:  sonic
retro-contest-sonic
World Models applied to the Open AI Sonic Retro Contest
Stars: ✭ 74 (+57.45%)
Mutual labels:  sonic
elasticscout
ElasticScout is an optimized Laravel Scout driver for Elasticsearch 7.1+
Stars: ✭ 64 (+36.17%)
Mutual labels:  scout

Laravel Scout Sonic Driver

Search Eloquent Models using Sonic indexes.

  1. Implementation
  2. Installation
  3. Usage

Implementation

When implementing the toSearchableArray method, you need to provide an array that will be coerced into a string (the engine just joins with a ' ') as Sonic can only index strings. So you need to provide a "stringified" (index string) version of your model. The default toArray works but it is probably too much noise for reasonable usage.

Here is an example of the string I used when I was developing this Engine:

public function toSearchableArray()
{
    return array_filter([$this->display_name, $this->first_name, $this->last_name]);
}

For me, this builds a nice string for search that can match on a "name". In my application, the concept of "name" is either the User display name or first/last name.


If the locale is known, you can also create the getSonicLocale() method on your model, which returns the locale. It will then get passed to the Sonic PUSH calls:

// an ISO 639-3 locale code eg. eng for English (if set, the locale must be a valid ISO 639-3 code; if set to none, lexing will be disabled; if not set, the locale will be guessed from text)
public function getSonicLocale() {
    return 'none';
}

Installation

If you haven't already you should install Laravel Scout to your project and apply the Laravel\Scout\Searchable trait to any Eloquent models you would like to make searchable.

Install this package via Composer

composer require james2doyle/laravel-scout-sonic

Note: if you have Laravel >= 5.5 you can skip this step because of Package Auto-Discovery.

Next add the ServiceProvider to the Package Service Providers in config/app.php

/*
 * Package Service Providers...
 */
james2doyle\SonicScout\Providers\SonicScoutServiceProvider::class,

Append the default configuration to config/scout.php

/*
|--------------------------------------------------------------------------
| Sonic Configuration
|--------------------------------------------------------------------------
|
| Here you may configure your Sonic settings.
|
*/

'sonic' => [
    'address' => \env('SONIC_ADDRESS', 'localhost'),
    'port' => \env('SONIC_PORT', 1491),
    'password' => \env('SONIC_PASSWORD'),
    'connection_timeout' => \env('SONIC_CONNECTION_TIMEOUT', 10),
    'read_timeout' => \env('SONIC_READ_TIMEOUT',  5)
],

Set SCOUT_DRIVER=sonic in your .env file

In addition there is no need to use the php artisan scout:import command.

Usage

Simply call the search() method on your Searchable models:

$users = App\User::search('bro')->get();

Simple constraints can be applied using the where() builder method:

$users = App\User::search('bro')->where('active', 1)->get();

Note: Sonic does not support the concept of "where", so the where is applied at the collection level not the query!

Pagination

Sonic cannot support real pagination because Sonic does not return proper paging or total information. It simply returns all the results for a given query.

There is a naive implementation of pagination in place but it probably isn't perfect as it doesn't take into account the "where" filter.

For more usage information see the Laravel Scout Documentation.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].