You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
glmdev 529f22c4b9
updated to new standard
8 years ago
src README 8 years ago
tests updated to new standard 8 years ago
CONTRIBUTING.md updated to new standard 8 years ago
LICENSE.md updated to new standard 8 years ago
README.md updated to new standard 8 years ago
composer.json updated to new standard 8 years ago

README.md

element/search

Latest Version on Packagist License: AGPL v3 Author Build Status

This is a simple hit based search engine for Eloquent models. It can take a string and will search the given set of models for each word in that string. It prioritizes models based on the number of times each word in the search string is found in the searchable fields in the model, with more emphasis on longer words, and less on shorter.

Install

The search Element is available on composer. To install it, simply run:

$ composer require element/search

Then, add the following line to the $providers array in the config/app.php file:

Element\Search\SearchServiceProvider::class,

Use

Making your models searchable is easy. The models simply need to implement the Element\Search\SearchableContract interface. Then, add the getSearchable() method to the model. This method should return an array of the names of the Model's fields that the search engine can search. These fields should hold string/text data only.

For Example:

<?php

namespace App;

use Element\Search\SearchableContract;
use Illuminate\Database\Eloquent\Model;

class BlogPost extends Model implements SearchableContract {
    protected $fillable = [ 'date-created', 'date-published', 'title', 'body',
                            'author', 'image', 'viewcount' ];

    public static function getSearchable(){
        return [ 'title', 'body', 'author' ];
    }

    public static function search( $string ){
        return Search::search( new self, $string );
    }
}

In the model above, we can see from the getSearchable() function that the Search Engine will search the 'title', 'body', and 'author' fields.

The second function is optional, but it allows you to call the search function statically from the model, rather than the search facade.

ie:

App\BlogPost::search('search string');

The Search Facade

The Element Search plugin adds a Search facade to the Laravel app. This allows you to call a search on any model from anywhere using the following function:

Search::search( new App\ModelName, 'search string');

Where App\ModelName is a new instance of the model you wish to search, and 'search string' is any string you wish to search for. Additionally, you don't have to worry about removing punctuation or capital letters from your search string, the function does it automatically.

The search function, whether in the model, or called from the facade, returns the models in the form of a \Laravel\Database\Eloquent\Collection collection. This allows you to perform all the usual functions you would be able to perform on a database query.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email glmdev@outlook.com instead of using the issue tracker.

Credits

License

The search Element is licensed under the GNU Affero General Public License, version 3.0.

element/search
    Copyright (C) 2016 Garrett Mills

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.