定制 soliyer/laravel-fuzzy-search 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

soliyer/laravel-fuzzy-search

最新稳定版本:1.0.0

Composer 安装命令:

composer require soliyer/laravel-fuzzy-search

包简介

A Laravel package providing a fuzzy search trait for Eloquent models to easily implement search functionality with support for concatenated attributes.

README 文档

README

This Laravel package provides a FuzzySearchable trait for Eloquent models, enabling easy implementation of search functionality with support for concatenated attributes. It's designed to enhance search experiences in Laravel applications by allowing more flexible and user-friendly search queries, including partial matches and concatenated field searches.

Installation

To install the package via Composer, run the following command:

composer require soliyer/laravel-fuzzy-search

Make sure your Laravel version is compatible with this package by checking the Laravel version requirements in the composer.json.

Usage

Basic Usage

To add fuzzy search capabilities to your Eloquent models, simply use the FuzzySearchable trait and define the attributes you want to make searchable:

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Soliyer\LaravelFuzzySearch\Traits\FuzzySearchable;

class Post extends Model
{
    use FuzzySearchable;

    protected $fillable = ['title', 'body', 'author', 'first_name', 'last_name'];

    // Specify the attributes you want to make searchable
    protected $searchable_attributes = ['title', 'body'];
}

You can now perform fuzzy searches on your model like so:

$posts = Post::fuzzySearch('Laravel')->get();

This will search the title and body attributes of the Post model for the term 'Laravel', allowing for partial matches and enhancing the search experience.

Searching Concatenated Attributes If you want to search across concatenated attributes (e.g., first and last name), define your searchable attributes as follows:

protected $searchable_attributes = [
    ['first_name', 'last_name'], // This will concatenate first_name and last_name with a space in between
    'email',
    'company'
];

Key Points:

  • Fillable Array: This is just an example. Replace or remove the $fillable property based on your actual model requirements.
  • Searchable Attributes: Adapt the protected $searchable_attributes array to match the specific attributes you wish to make searchable in your models.

Then, performing a fuzzy search will include these concatenated fields in the search criteria.

Advanced Usage

The FuzzySearchable trait is flexible; you can further customize search behavior by extending the trait or directly in your model methods.

Contributing

Contributions are welcome and fully credited. Please feel free to fork the repository, make your changes, and submit a pull request on GitHub.

For major changes, please open an issue first to discuss what you would like to change. Make sure to update tests as appropriate.

Security

If you discover any security-related issues, please email vafaei39@gmail.com instead of using the public issue tracker.

Credits

Soheil Vafaei - Package Author Special thanks to all contributors who participated in the development of this package.

License

The Laravel Fuzzy Search package is open-sourced software licensed under the MIT license.

统计信息

  • 总下载量: 21
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-03-03