2017 © Pedro Peláez
 

library fulltext

Easily add fulltext search capabilities to your Eloquent models

image

filippo-toso/fulltext

Easily add fulltext search capabilities to your Eloquent models

  • Friday, February 9, 2018
  • by filippo.toso
  • Repository
  • 0 Watchers
  • 1 Stars
  • 13 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 0 % Grown

The README.md

Fulltext

A simple way to add fulltext capabilities to your Eloquent models (just for MySQL for the moment)., (*1)

Requirements

  • PHP 5.6+
  • Laravel 5.0+

Installing

Use Composer to install it:, (*2)

composer require filippo-toso/fulltext

Using It

Create a fulltext index in your migrations:, (*3)

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

use FilippoToso\Fulltext\FullText;

class AddIndexesToUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        // Create a fulltext index in the users table for the first_name and last_name columns
        FullText::fullTextIndex('users', ['first_name', 'last_name']);

        // You can also specify a name for the index with the third parameter
        FullText::fullTextIndex('users', ['city', 'address', 'country'], 'search_address');

    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {

        Schema::table('users', function (Blueprint $table) {
            $table->dropIndex(['first_name', 'last_name']);
            $table->dropIndex('search_address');
        });

    }

}

Enable fulltext functions within the User model (for instance):, (*4)

namespace App;

use Illuminate\Database\Eloquent\Model;
use FilippoToso\FullText\Traits\FullText;

class User extends Model
{
    use FullText;
}

Use the FullText trait's features:, (*5)

// Use the whereMatch() scope to search for all users named "filippo"
$users = App\User::select('*')
                ->whereMatch(['first_name', 'last_name'], 'filippo')
                ->get();

// Include in the result the score column with the matching score
$users = App\User::select('*')
                ->whereMatch(['first_name', 'last_name'], 'filippo')
                ->selectMatchScore(['first_name', 'last_name'], 'filippo')
                ->get();

// You can also include the name of the score column with the third parameter of selectMatchScore()
$users = App\User::select('*')
                ->whereMatch(['first_name', 'last_name'], 'filippo')
                ->selectMatchScore(['first_name', 'last_name'], 'filippo', 'matching_score')
                ->get();

The Versions

09/02 2018

dev-master

9999999-dev

Easily add fulltext search capabilities to your Eloquent models

  Sources   Download

MIT

The Requires

 

by Filippo Toso

09/02 2018

v1.0.7

1.0.7.0

Easily add fulltext search capabilities to your Eloquent models

  Sources   Download

MIT

The Requires

 

by Filippo Toso

22/01 2018

v1.0.6

1.0.6.0

Easily add fulltext search capabilities to your Eloquent models

  Sources   Download

MIT

The Requires

 

by Filippo Toso

14/01 2018

v1.0.5

1.0.5.0

Easily add fulltext search capabilities to your Eloquent models

  Sources   Download

MIT

The Requires

 

by Filippo Toso

12/01 2018

v1.0.4

1.0.4.0

Easily add fulltext search capabilities to your Eloquent models

  Sources   Download

MIT

The Requires

 

by Filippo Toso

12/01 2018

v1.0.3

1.0.3.0

Easily add fulltext search capabilities to your Eloquent models

  Sources   Download

MIT

The Requires

 

by Filippo Toso

12/01 2018

v1.0.1

1.0.1.0

A simple way to copy/move files between different Laravel Storage disks

  Sources   Download

MIT

The Requires

 

by Filippo Toso

12/01 2018

v1.0.0

1.0.0.0

A simple way to copy/move files between different Laravel Storage disks

  Sources   Download

MIT

The Requires

 

by Filippo Toso