2017 © Pedro Peláez
 

library laravel-scout-tntsearch-driver

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

image

teamtnt/laravel-scout-tntsearch-driver

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

  • Monday, July 30, 2018
  • by nticaric
  • Repository
  • 24 Watchers
  • 431 Stars
  • 136,510 Installations
  • PHP
  • 21 Dependents
  • 0 Suggesters
  • 61 Forks
  • 37 Open issues
  • 39 Versions
  • 16 % Grown

The README.md

TNTSearch Driver for Laravel Scout - Laravel 5.3 - 11

Backers on Open Collective Sponsors on Open Collective Latest Version on Packagist Software License Build Status Quality Score Total Downloads, (*1)

This package makes it easy to add full text search support to your models with Laravel 5.3 to 9.0., (*2)

Premium products

If you find TNT Search to be one of your valuable assets, take a look at one of our premium products, (*3)

, (*4)

Support us on Open Collective

Contents

Installation

You can install the package via composer:, (*5)

``` bash composer require teamtnt/laravel-scout-tntsearch-driver, (*6)


Add the service provider: ```php // config/app.php 'providers' => [ // ... TeamTNT\Scout\TNTSearchScoutServiceProvider::class, ],

Ensure you have Laravel Scout as a provider too otherwise you will get an "unresolvable dependency" error, (*7)

// config/app.php
'providers' => [
    // ...
    Laravel\Scout\ScoutServiceProvider::class,
],

Add SCOUT_DRIVER=tntsearch to your .env file, (*8)

Then you should publish scout.php configuration file to your config directory, (*9)

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

In your config/scout.php add:, (*10)


'tntsearch' => [ 'storage' => storage_path(), //place where the index files will be stored 'fuzziness' => env('TNTSEARCH_FUZZINESS', false), 'fuzzy' => [ 'prefix_length' => 2, 'max_expansions' => 50, 'distance' => 2, 'no_limit' => true ], 'asYouType' => false, 'searchBoolean' => env('TNTSEARCH_BOOLEAN', false), 'maxDocs' => env('TNTSEARCH_MAX_DOCS', 500), ],

To prevent your search indexes being commited to your project repository, add the following line to your .gitignore file., (*11)

/storage/*.index, (*12)

The asYouType option can be set per model basis, see the example below., (*13)

Usage

After you have installed scout and the TNTSearch driver, you need to add the Searchable trait to your models that you want to make searchable. Additionaly, define the fields you want to make searchable by defining the toSearchableArray method on the model:, (*14)

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Laravel\Scout\Searchable;

class Post extends Model
{
    use Searchable;

    public $asYouType = true;

    /**
     * Get the indexable data array for the model.
     *
     * @return array
     */
    public function toSearchableArray()
    {
        $array = $this->toArray();

        // Customize array...

        return $array;
    }
}

Then, sync the data with the search service like:, (*15)

php artisan scout:import App\\Post, (*16)

If you have a lot of records and want to speed it up you can run (note that with this you can no longer use model-relations in your toSearchableArray()):, (*17)

php artisan tntsearch:import App\\Post, (*18)

After that you can search your models with:, (*19)

Post::search('Bugs Bunny')->get();, (*20)

Scout status

php artisan scout:status, (*21)

With this simple command you'll get a quick overview of your search indices., (*22)

Image of Scout Status Command, (*23)

Or you can pass a searchable model argument:, (*24)

php artisan scout:status "App\Models\Post", (*25)

If your models are not in the default location app or one of its subdirectories, you may set the modelPath option, (*26)

// config/scout.php
'tntsearch' => [
    // ...
    'modelPath' => 'models',
],

Image of Scout Status Command, (*27)

Constraints

Additionally to where() statements as conditions, you're able to use Eloquent queries to constrain your search. This allows you to take relationships into account., (*28)

If you make use of this, the search command has to be called after all queries have been defined in your controller., (*29)

The where() statements you already know can be applied everywhere., (*30)

namespace App\Http\Controllers;

use App\Post;

class PostController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        $post = new Post;

        // filter out posts to which the given topic is assigned
        if($request->topic) {
            $post = $post->whereNotIn('id', function($query){
                $query->select('assigned_to')->from('comments')->where('topic','=', request()->input('topic'));
            });
        }

        // only posts from people that are no moderators
        $post = $post->byRole('moderator','!=');

        // when user is not admin filter out internal posts
        if(!auth()->user()->hasRole('admin'))
        {
            $post= $post->where('internal_post', false);
        }

        if ($request->searchTerm) {
            $constraints = $post; // not necessary but for better readability
            $post = Post::search($request->searchTerm)->constrain($constraints);
        }

        $post->where('deleted', false);

        $post->orderBy('updated_at', 'asc');

        $paginator = $post->paginate(10);
        $posts = $paginator->getCollection();

        // return posts
    }
}

Adding via Query

The searchable() method will chunk the results of the query and add the records to your search index., (*31)

$post = Post::find(1);

// You may also add record via collection...
$post->searchable();

// OR

$posts = Post::where('year', '>', '2018')->get();

// You may also add records via collections...
$posts->searchable();

When using constraints apply it after the constraints are added to the query, as seen in the above example., (*32)

OrderBy

An orderBy() statement can now be applied to the search query similar to the where() statement., (*33)

When using constraints apply it after the constraints are added to the query, as seen in the above example., (*34)

Sponsors

Become a sponsor and get your logo on our README on Github with a link to your site. [Become a sponsor], (*35)

Credits

Contributors

This project exists thanks to all the people who contribute. , (*36)

Backers

Thank you to all our backers! 🙏 [Become a backer], (*37)

, (*38)

The Versions

30/07 2018

dev-master

9999999-dev

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

  Sources   Download

MIT

The Requires

 

The Development Requires

by TNT Studio

laravel search scout tntsearch

27/06 2018

v3.0.7

3.0.7.0

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

  Sources   Download

MIT

The Requires

 

The Development Requires

by TNT Studio

laravel search scout tntsearch

18/12 2017

v3.0.6

3.0.6.0

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

  Sources   Download

MIT

The Requires

 

The Development Requires

by TNT Studio

laravel search scout tntsearch

08/12 2017

v3.0.5

3.0.5.0

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

  Sources   Download

MIT

The Requires

 

The Development Requires

by TNT Studio

laravel search scout tntsearch

31/08 2017

v3.0.4

3.0.4.0

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

  Sources   Download

MIT

The Requires

 

The Development Requires

by TNT Studio

laravel search scout tntsearch

30/08 2017

v3.0.3

3.0.3.0

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

  Sources   Download

MIT

The Requires

 

The Development Requires

by TNT Studio

laravel search scout tntsearch

25/07 2017

v3.0.2

3.0.2.0

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

  Sources   Download

MIT

The Requires

 

The Development Requires

by TNT Studio

laravel search scout tntsearch

09/07 2017

v3.0.1

3.0.1.0

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

  Sources   Download

MIT

The Requires

 

The Development Requires

by TNT Studio

laravel search scout tntsearch

26/04 2017

v3.0.0

3.0.0.0

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

  Sources   Download

MIT

The Requires

 

The Development Requires

by TNT Studio

laravel search scout tntsearch

20/04 2017

v2.0.5

2.0.5.0

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

  Sources   Download

MIT

The Requires

 

The Development Requires

by TNT Studio

laravel search scout tntsearch

31/03 2017

v2.0.4

2.0.4.0

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

  Sources   Download

MIT

The Requires

 

The Development Requires

by TNT Studio

laravel search scout tntsearch

09/03 2017

v2.0.3

2.0.3.0

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

  Sources   Download

MIT

The Requires

 

The Development Requires

by TNT Studio

laravel search scout tntsearch

07/01 2017

v2.0.2

2.0.2.0

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

  Sources   Download

MIT

The Requires

 

The Development Requires

by TNT Studio

laravel search scout tntsearch

29/12 2016

v2.0.1

2.0.1.0

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

  Sources   Download

MIT

The Requires

 

The Development Requires

by TNT Studio

laravel search scout tntsearch

22/12 2016

v2.0.0

2.0.0.0

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

  Sources   Download

MIT

The Requires

 

The Development Requires

by TNT Studio

laravel search scout tntsearch

19/12 2016

v1.1.6

1.1.6.0

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

  Sources   Download

MIT

The Requires

 

The Development Requires

by TNT Studio

laravel search scout tntsearch

24/10 2016

v1.1.5

1.1.5.0

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

  Sources   Download

MIT

The Requires

 

The Development Requires

by TNT Studio

laravel search scout tntsearch

21/10 2016

v1.1.4

1.1.4.0

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

  Sources   Download

MIT

The Requires

 

The Development Requires

by TNT Studio

laravel search scout tntsearch

01/10 2016

v1.1.3

1.1.3.0

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

  Sources   Download

MIT

The Requires

 

The Development Requires

by TNT Studio

laravel search scout tntsearch

01/10 2016

dev-analysis-86331W

dev-analysis-86331W

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

  Sources   Download

MIT

The Requires

 

The Development Requires

by TNT Studio

laravel search scout tntsearch

21/09 2016

v1.1.2

1.1.2.0

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

  Sources   Download

MIT

The Requires

 

The Development Requires

by TNT Studio

laravel search scout tntsearch

18/09 2016

v1.1.1

1.1.1.0

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

  Sources   Download

MIT

The Requires

 

The Development Requires

by TNT Studio

laravel search scout tntsearch

18/09 2016

dev-analysis-8LmWkw

dev-analysis-8LmWkw

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

  Sources   Download

MIT

The Requires

 

The Development Requires

by TNT Studio

laravel search scout tntsearch

25/08 2016

v1.1.0

1.1.0.0

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

  Sources   Download

MIT

The Requires

 

The Development Requires

by TNT Studio

laravel search scout tntsearch

25/08 2016

dev-analysis-q1kD5w

dev-analysis-q1kD5w

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

  Sources   Download

MIT

The Requires

 

The Development Requires

by TNT Studio

laravel search scout tntsearch

25/08 2016

v1.0.9

1.0.9.0

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

  Sources   Download

MIT

The Requires

 

The Development Requires

by TNT Studio

laravel search scout tntsearch

25/08 2016

dev-analysis-qJD9xn

dev-analysis-qJD9xn

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

  Sources   Download

MIT

The Requires

 

The Development Requires

by TNT Studio

laravel search scout tntsearch

24/08 2016

v1.0.8

1.0.8.0

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

  Sources   Download

MIT

The Requires

 

The Development Requires

by TNT Studio

laravel search scout tntsearch

24/08 2016

dev-analysis-zY69Qj

dev-analysis-zY69Qj

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

  Sources   Download

MIT

The Requires

 

The Development Requires

by TNT Studio

laravel search scout tntsearch

23/08 2016

v1.0.7

1.0.7.0

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

  Sources   Download

MIT

The Requires

 

The Development Requires

by TNT Studio

laravel search scout tntsearch

23/08 2016

dev-analysis-8Pe7EL

dev-analysis-8Pe7EL

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

  Sources   Download

MIT

The Requires

 

The Development Requires

by TNT Studio

laravel search scout tntsearch

23/08 2016

v1.0.6

1.0.6.0

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

  Sources   Download

MIT

The Requires

 

The Development Requires

by TNT Studio

laravel search scout tntsearch

23/08 2016

v1.0.5

1.0.5.0

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

  Sources   Download

MIT

The Requires

 

The Development Requires

by TNT Studio

laravel search scout tntsearch

23/08 2016

v1.0.4

1.0.4.0

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

  Sources   Download

MIT

The Requires

 

The Development Requires

by TNT Studio

laravel search scout tntsearch

23/08 2016

v1.0.3

1.0.3.0

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

  Sources   Download

MIT

The Requires

 

The Development Requires

by TNT Studio

laravel search scout tntsearch

19/08 2016

v1.0.2

1.0.2.0

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

  Sources   Download

MIT

The Requires

 

The Development Requires

by TNT Studio

laravel search scout tntsearch

19/08 2016

dev-analysis-z3GJ69

dev-analysis-z3GJ69

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

  Sources   Download

MIT

The Requires

 

The Development Requires

by TNT Studio

laravel search scout tntsearch

16/08 2016

v1.0.1

1.0.1.0

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

  Sources   Download

MIT

The Requires

 

The Development Requires

by TNT Studio

laravel search scout tntsearch

16/08 2016

v1.0.0

1.0.0.0

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

  Sources   Download

MIT

The Requires

 

The Development Requires

by TNT Studio

laravel search scout tntsearch