A scout DB fulltext-based driver that store index data in related tables

Overview

A scout DB fulltext-based driver that store index data in related tables

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This package provide a Laravel/Scout Engine based on database/fulltext only, but work in a different way compared to the default database Engine.

You don't need to add fulltext indexes to your tables: the data used for search will be stored in a table with a polymorphic relation.

This provide several advantages:

  • you don't need to change current tables's schema
  • it's easy to add metadata
  • indexing process can be deferred in jobs, so it will not slow down database inserts/updates

Installation

You can install the package via composer:

composer require ivanomatteo/laravel-scout-fulltext-engine

You can publish and run the migrations with:

php artisan vendor:publish --tag="laravel-scout-fulltext-engine-migrations"
php artisan migrate

You can publish the config file with:

php artisan vendor:publish --tag="laravel-scout-fulltext-engine-config"

This is the contents of the published config file:

use IvanoMatteo\LaravelScoutFullTextEngine\Parsers\Extractors\CompositeNameExtractor;
use IvanoMatteo\LaravelScoutFullTextEngine\Parsers\Query\QueryParserMysqlFullTextBool;

return [
 'scout_engine_name' => 'scout-fulltext-engine',

    'fulltext_options' => [

        'mode' => 'boolean',

        /*
            Note on bind_mode == 'join': 
                it will try to modify selected columns by
                adding "model_table.*" if no column was selected or
                adding "model_table." prefix to selected columns.
                In some cases, for example when using DB::raw(), 
                you must be careful because the query will be a join, 
                and you have to avoid column names collisions
        */
        'bind_mode' => 'exists', // 'exists' | 'join'

        /* 
            By default fulltext searches will return records
            ordered by match score: 
                but in some case you may want the records to be ordered by 
                multiple fields, for example: match_score, name
                in these cases is necessary to be explicit
            !!! only supported with bind_mode = 'join' 
        */
        'order_by_score' => false,

        // this will add a field named 'fulltext_score' to the results.
        // it can be useful for tuning fulltext searches
        // !!! only supported with bind_mode = 'join'
        'add_select_score' => false,
    ],


    'pre_processing' => [
        'query' => [
            // the parser will process the text passed to 
            // search function preparing it for the specific 
            // fulltext query type
            'parser' => QueryParserMysqlFullTextBool::class,

            // extractors will extrapolate metadata from the 
            // query text 
            'extractors' => [
                [
                    // composite name extractor will find words
                    // composed by 1 or 2 characters followed by
                    // a word longer than 2 characters, for example:
                    // from "Robert De Niro" --> "De_niro"
                    //
                    // This is useful to overcome fulltext default min-length 
                    // settings that ignore words < 3 chars 
                    // (but it will work only if used also in index data section)
                    'class' => CompositeNameExtractor::class,

                    // true -> will prepend "+", for boolean mode, but depends by the parser class
                    'must_match' => false, 
                    
                    // true -> will append "*", for boolean mode, but depends by the parser class
                    'starts_with' => true, 
                ]
            ],
        ],
        'index_data' => [
            'extractors' => [
                //this will add extracted metadata to te index
                CompositeNameExtractor::class,
            ],
        ],
    ],

];

Storing indexed data in different tables

It's also possible use different tables to store indexed data:

  • creating another table with the same structure of "full_text_entries"
  • the model (that should extend FullTextEntry)

and adding this method to your models:

public function getFullTextEntryModel()
{
    return FullTextEntry2::class;
}

Usage

Simply configure Laravel Scout to use this driver: (in your .env file)

SCOUT_DRIVER=scout-fulltext-engine

and refer to laravel scout documentation for standard usage.

Direct Search Mode

This package also provide a "direct search" mode: you just need to add DirectSearch Trait to your Model:

use Laravel\Scout\Searchable;
use IvanoMatteo\LaravelScoutFullTextEngine\Concerns\DirectSearch;

class MyModel extends Model
{
    use Searchable;
    use DirectSearch;

}

In this way you will get:

  • fullTextEntry(): relation to indexed table
  • directSearch(): scope, that you can use intead of search()

Scout's search() function, returns an instance of Laravel\Scout\Builder that has limited functionalities.

directSearch() instead, will return an instance of Illuminate\Database\Eloquent\Builder that allow you to build your query as usual.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

Comments
Releases(0.1.12)
Owner
Ivano Matteo
https://www.linkedin.com/in/ivano-matteo-1a159b44/
Ivano Matteo
Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

TNTSearch Driver for Laravel Scout - Laravel 5.3 - 8.0 This package makes it easy to add full text search support to your models with Laravel 5.3 to 8

TNT Studio 1k Dec 27, 2022
Laravel Scout provides a driver based solution to searching your Eloquent models.

Introduction Laravel Scout provides a simple, driver-based solution for adding full-text search to your Eloquent models. Once Scout is installed and c

The Laravel Framework 1.3k Dec 31, 2022
Fulltext indexing and searching for Laravel

Laravel fulltext index and search This package creates a MySQL fulltext index for models and enables you to search through those. Install Install with

SWIS 171 Jan 4, 2023
Elasticsearch driver for Laravel Scout

Elasticsearch driver for Laravel Scout. Contents Compatibility Installation Configuration Basic Usage Advanced Search Migrations Pitfalls Compatibilit

Ivan Babenko 197 Dec 19, 2022
[Deprecated] We now recommend using Laravel Scout, see =>

[DEPRECATED] Algolia Search API Client for Laravel Algolia Search is a hosted full-text, numerical, and faceted search engine capable of delivering re

Algolia 240 Nov 25, 2022
Search among multiple models with ElasticSearch and Laravel Scout

For PHP8 support use php8 branch For Laravel Framework < 6.0.0 use 3.x branch The package provides the perfect starting point to integrate ElasticSear

Sergey Shlyakhov 592 Dec 25, 2022
The official SingleStore Laravel driver.

SingleStore Driver for Laravel This repository contains a SingleStore Driver for Laravel. Install You can install the package via composer: composer r

SingleStore Labs 197 Jan 1, 2023
Store and retrieve objects from Algolia or Elasticsearch

Store and retrieve objects from a search index This is an opinionated Laravel 5.1 package to store and retrieve objects from a search index. Currently

Spatie 440 Dec 30, 2022
This package offers advanced functionality for searching and filtering data in Elasticsearch.

Scout Elasticsearch Driver ?? Introducing a new Elasticsearch ecosystem for Laravel. ?? This package offers advanced functionality for searching and f

Ivan Babenko 1.2k Dec 20, 2022
A metadata catalog and search engine for geospatialized data

resto is a metadata catalog and a search engine dedicated to geospatialized data. Originally, it’s main purpose it to handle Earth Observation satellite imagery but it can be used to store any kind of metadata localized in time and space.

Jerome Gasperi 50 Nov 17, 2022
Illusionist Searcher - Generates database queries based on search syntax

Illusionist Searcher Generates database queries based on search syntax. English | 中文 ✨ Features Zero configuration Compatible with laravel/scout and l

A doer with magic 2 Feb 24, 2022
This script was made to aid the process of migrating PHP and MySQL based websites

This script was made to aid the process of migrating PHP and MySQL based websites. Works with most common CMSes.

interconnect/it 3.9k Jan 5, 2023
Think-scout - A driver based solution to searching your models. Inspired By Laravel Scout

前言 whereof/think-scout根据thinkphp设计思想参考laravel/scout进行扩展 whereof/think-scout 为模型的全文搜索提供了一个简单的、基于驱动程序的解决方案。 目前,Scout 自带了一个 Elasticsearch 驱动;而编写自定义驱动程序很简

wangzhiqiang 6 Mar 18, 2022
A super simple package allowing for use MySQL 'USE INDEX' and 'FORCE INDEX' statements.

Laravel MySQL Use Index Scope A super simple package allowing for use MySQL USE INDEX and FORCE INDEX statements. Requirements PHP ^7.4 | ^8.0 Laravel

Vasyl 29 Dec 27, 2022
Get mobile app version and other related data from Google Play Store, Apple App Store and Huawei AppGallery

Mobile App Version Get mobile app version and other related data from Google Play Store, Apple App Store and Huawei AppGallery. Installation Add to co

Omer Salaj 11 Mar 15, 2022
YCOM Impersonate. Login as selected YCOM user 🧙‍♂️in frontend.

YCOM Impersonate Login as selected YCOM user in frontend. Features: Backend users with admin rights or YCOM[] rights, can be automatically logged in v

Friends Of REDAXO 17 Sep 12, 2022
Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

TNTSearch Driver for Laravel Scout - Laravel 5.3 - 8.0 This package makes it easy to add full text search support to your models with Laravel 5.3 to 8

TNT Studio 1k Dec 27, 2022
Laravel Scout provides a driver based solution to searching your Eloquent models.

Introduction Laravel Scout provides a simple, driver-based solution for adding full-text search to your Eloquent models. Once Scout is installed and c

The Laravel Framework 1.3k Dec 31, 2022
Driver for Laravel Scout search package based on tntsearch

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

TNT Studio 1k Dec 27, 2022
Fulltext indexing and searching for Laravel

Laravel fulltext index and search This package creates a MySQL fulltext index for models and enables you to search through those. Install Install with

SWIS 171 Jan 4, 2023