New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

sciku1/laravel-match-against

Laravel builder match against eloquent syntax and related.
1,810 6
Install
composer require sciku1/laravel-match-against
Latest Version:0.1.1
Laravel:5
License:MIT
Last Updated:Sep 27, 2018
Links: GitHub  ·  Packagist
Maintainer: sciku1

Laravel Match Against

A simple macro for doing match against fulltext searches with the Eloquent ORM api, currently in beta.

Requirements

  • Laravel 5.x
  • MySQL 3.3+

composer require sciku1/laravel-match-against

Laravel 5.5

You're done!

Laravel 5.x

You must register the service provider in your config/app.php

'providers' => [
    ...
    Sciku1\LaravelMatchAgainst\Providers\MatchAgainstServiceProvider::class,
]

Usage

To run match against queries, the field must have a fulltext index, currently there only way to do this is

DB::statement('ALTER TABLE `table_name` ADD FULLTEXT index_name(col1, col2)');

Order

The default behaviour is to order. Example:

Model::match(['col1', 'col2'])->against('search terms')->get();

will generate

SELECT * FROM models ORDER BY (MATCH (col1) AGAINST ('search terms')) DESC, (MATCH (col2) AGAINST ('search terms')) DESC

Where

To limit the results, you must use whereAgainst()

Model::match(['col1', 'col2'])->whereAgainst('search terms')->get();

will generate

SELECT * FROM models WHERE (MATCH (col1) AGAINST ('search terms')) > 0, (MATCH (col2) AGAINST ('search terms')) > 0

Related Packages

kevinsimard/laravel-builder-macros

Laravel builder macros for the Eloquent ORM

351 7
ems/versatile

Extensions for Laravels Eloquent ORM

8,592 0
hugorut/filterable

A laravel package for working with query filtering

20 0
rtablada/ordered-eloquent

An extension of Eloquent ORM for automatically ordering results

18 3
jimbolino/laravel-model-builder

builds eloquent models based on the tables and relations found in your mysql dat...

11,846 30

Version History

Version Released Laravel License
0.1.1 5.* MIT
0.1.0 5.* MIT