Enables full-text search capabilities in Winter.

Overview

Search Plugin

Build Status MIT License Discord

Adds full-text searching capabilities to Winter, built on the foundations of Laravel Scout. The plugin acts primarily as a wrapper for Laravel Scout, and provides its entire suite of functionality within Winter's architecture, but also includes additional capabilities to make its use in Winter even easier.

Getting started

To install the plugin, you may install it through the Winter CMS Marketplace, or you may install it using Composer:

composer require winter/wn-search-plugin

Then, run the migrations to ensure the plugin is enabled:

php artisan winter:up

Configuration

Configuration for this plugin is chiefly done through the search.php configuration file. You can publish this configuration into your project's config directory by running the following command:

php artisan vendor:publish --provider="Winter\Search\Plugin"

This will create your own configuration file at config/winter/search/search.php, in which you will be able to override all default configuration values.

Usage

As this is a wrapper, you can use all the base functionality that Laravel Scout provides. There are only a couple of subtle differences with the Search plugin's implementation:

  • Configuration values are stored within the search key. Wherever there is mention of a scout configuration value, you must use search instead.
  • Soft deleted models are determined by the usage of the Winter\Storm\Database\Traits\SoftDelete trait, not the base Laravel SoftDeletes trait.

To make a particular model searchable, you simply add the Winter\Search\Traits\Searchable trait to that model. This trait will register a model observer that will automatically synchronise the model records to an index:

<?php

namespace Winter\Plugin\Models;

use Model;
use Winter\Search\Traits\Searchable;

class MyModel extends Model
{
    use Searchable;
}

As the model is created, updated or deleted, the index will automatically be updated to reflect the state of that model record.

Configuring searchable data

By default, the entire model is converted to an array form and persisted in the search index. If you would like to limit the data that is stored in the index, you can provide a $searchable property in the model. This property will represent all the model attributes that you would like to store in the index:

<?php

namespace Winter\Plugin\Models;

use Model;
use Winter\Search\Traits\Searchable;

class Post extends Model
{
    use Searchable;

    public $searchable = [
        'title',
        'summary'
    ];
}

If you want even more control over the data, you may override the toSearchableArray method:

<?php

namespace Winter\Plugin\Models;

use Model;
use Winter\Search\Traits\Searchable;

class Post extends Model
{
    use Searchable;

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

        // Customize the data array...

        return $array;
    }
}

Configuring the model ID

Normally, the primary key of the model will act as the model's unique ID that is stored in the search index. If you wish to use another column to act as the identifier for a model, you may override the getSearchKey and getSearchKeyName methods to customise this behaviour.

<?php

namespace Winter\Plugin\Models;

use Model;
use Winter\Search\Traits\Searchable;

class User extends Model
{
    use Searchable;

    /**
     * Get the value used to index the model.
     *
     * @return mixed
     */
    public function getSearchKey()
    {
        return $this->email;
    }

    /**
     * Get the key name used to index the model.
     *
     * @return mixed
     */
    public function getSearchKeyName()
    {
        return 'email';
    }
}
You might also like...
A TYPO3 extension that integrates the Apache Solr search server with TYPO3 CMS. dkd Internet Service GmbH is developing the extension. Community contributions are welcome. See CONTRIBUTING.md for details.
A TYPO3 extension that integrates the Apache Solr search server with TYPO3 CMS. dkd Internet Service GmbH is developing the extension. Community contributions are welcome. See CONTRIBUTING.md for details.

Apache Solr for TYPO3 CMS A TYPO3 extension that integrates the Apache Solr enterprise search server with TYPO3 CMS. The extension has initially been

A site search engine
A site search engine

THIS PACKAGE IS IN DEVELOPMENT, DO NOT USE IN PRODUCTION YET A site search engine This package can crawl your entire site and index it. Support us We

Support search in flarum by sonic

flarum-sonic Support search by Sonic Install Sonic following this guide Install the extension: composer require ganuonglachanh/sonic Change info in a

Your personal job-search assistant

JobsToMail Your personal job-search assistant About JobsToMail is an open source web application that allows users to sign up to receive emails with j

Search among multiple models with ElasticSearch and Laravel Scout
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

This is an open source demo of smart search feature implemented with Laravel and Selectize plugin
This is an open source demo of smart search feature implemented with Laravel and Selectize plugin

Laravel smart search implementation See demo at: http://demos.maxoffsky.com/shop-search/ Tutorial at: http://maxoffsky.com/code-blog/laravel-shop-tuto

Laravel package to search through multiple Eloquent models. Supports sorting, pagination, scoped queries, eager load relationships and searching through single or multiple columns.

Laravel Cross Eloquent Search This Laravel package allows you to search through multiple Eloquent models. It supports sorting, pagination, scoped quer

This modules provides a Search API Backend for Elasticsearch.

Search API ElasticSearch This modules provides a Search API Backend for Elasticsearch. This module uses the official Elasticsearch PHP Client. Feature

Laravel Searchable - This package makes it easy to get structured search from a variety of sources
Laravel Searchable - This package makes it easy to get structured search from a variety of sources

This package makes it easy to get structured search from a variety of sources. Here's an example where we search through some model

Owner
Winter CMS
Free, open-source, self-hosted, community-driven CMS platform based on the Laravel PHP Framework
Winter CMS
Noteplan full-text search for Alfred - some assembly required

Noteplan FTS for Alfred Noteplan full-text search for Alfred - some assembly required. Work in progress, mostly working. Usage n [Search phrase] - Ful

Adam Kiss 6 Nov 28, 2022
Laravel search is package you can use it to make search query easy.

Laravel Search Installation First, install the package through Composer. composer require theamasoud/laravel-search or add this in your project's comp

Abdulrahman Masoud 6 Nov 2, 2022
SphinxQL Query Builder generates SphinxQL, a SQL dialect, which is used to query the Sphinx search engine. (Composer Package)

Query Builder for SphinxQL About This is a SphinxQL Query Builder used to work with SphinxQL, a SQL dialect used with the Sphinx search engine and it'

FoolCode 318 Oct 21, 2022
Sphinx Search library provides SphinxQL indexing and searching features

Sphinx Search Sphinx Search library provides SphinxQL indexing and searching features. Introduction Installation Configuration (simple) Usage Search I

Ripa Club 62 Mar 14, 2022
A search package for Laravel 5.

Search Package for Laravel 5 This package provides a unified API across a variety of different full text search services. It currently supports driver

Mark Manos 354 Nov 16, 2022
A php trait to search laravel models

Searchable, a search trait for Laravel Searchable is a trait for Laravel 4.2+ and Laravel 5.0 that adds a simple search function to Eloquent Models. S

Nicolás López Jullian 2k Dec 27, 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
Unmaintained: Laravel Searchy makes user driven searching easy with fuzzy search, basic string matching and more to come!

!! UNMAINTAINED !! This package is no longer maintained Please see Issue #117 Here are some links to alternatives that you may be able to use (I do no

Tom Lingham 533 Nov 25, 2022
Kirby docs search workflow for Alfred

Kirby Docs search workflow for Alfred 4 An ultra-fast Kirby Docs search workflow for Alfred 4 Installation Download the latest version Install the wor

Adam Kiss 30 Dec 29, 2022
Build and execute an Elasticsearch search query using a fluent PHP API

PACKAGE IN DEVELOPMENT, DO NOT USE YET Build and execute ElasticSearch queries using a fluent PHP API This package is a lightweight query builder for

Spatie 94 Dec 14, 2022