acadea / fullsite-search
Laravel 包,基于 Laravel Scout 实现全站搜索。将“搜索一切”功能箱带到 Laravel 应用中。
v1.0.2
2021-10-05 00:24 UTC
Requires
- php: ^7.4|^8.0
- illuminate/contracts: ^8.0
- laravel/scout: ^8.3|^9.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16
- orchestra/testbench: ^6.0
- phpunit/phpunit: ^9.3
- vimeo/psalm: ^3.11
This package is auto-updated.
Last update: 2024-09-27 08:47:38 UTC
README
Laravel 包,基于 Laravel Scout 实现全站搜索。将“搜索一切”功能箱带到 Laravel 应用中。
支持我们
在我的 Medium 博客中了解这个包背后的想法
在 YouTube 上关注我们: https://www.youtube.com/channel/acadeaio
给我们买杯咖啡: https://www.buymeacoffee.com/acadea
Paypal: https://www.paypal.com/donate/?hosted_button_id=HPD9HHN3HBPDC
快速开始
// Expect a collection of models in the search result $results = \Acadea\FullSite\FullSiteSearch::search('in');
每个返回的模型都有 3 个额外的属性
- a.
match
-- 来自我们数据库记录的匹配 + 邻近文本 - b.
model
-- 相关模型名称 - c.
view_link
-- 用户在前端导航以查看资源的 URL
作为 API 响应返回结果
// Controller return \Acadea\FullSite\Resources\SiteSearchResource::collection($results);
为了您的方便,我们已经为您启动了 API 端点。您可以在配置文件中禁用此功能。只需将 fullsite-search.api.disabled
配置设置为 true
。
示例
URL: /api/site-search?search=in
我们得到
{ "data": [ { "id": 2, "match": "...ER happen in a frighte...", "model": "Post", "view_link": "http://127.0.0.1:8000/posts/2" }, { "id": 4, "match": "Drawling, Stretching, ...", "model": "Post", "view_link": "http://127.0.0.1:8000/posts/4" }, { "id": 6, "match": "...ed to her in the dista...", "model": "Post", "view_link": "http://127.0.0.1:8000/posts/6" } ] }
安装
您可以通过 composer 安装此包
composer require acadea/fullsite-search
您可以使用以下命令发布配置文件
php artisan vendor:publish --provider="Acadea\FullSite\FullSiteServiceProvider" --tag="config"
这是已发布的配置文件的内容
return [ // path to your models directory, relative to /app 'model_path' => 'Models', 'api' => [ // enable api endpoint 'disabled' => false, // the api endpoint uri 'url' => '/api/site-search', ], // you can put any models that you want to exclude from the search here 'exclude' => [ // example: // \App\Models\Comment::class ], // the number of neighbouring characters that you want to include in the match field of API response 'buffer' => 10, // this is where you define where should the search result leads to. // the link should navigate to the resource view page // by default, we use `/<model-name>/<model-id>` , you can define anything here // We will replace `{id}` or `{ id }` with the model id 'view_mapping' => [ // \App\Models\Comment::class => '/comments/view/{id}' ], ];
测试
composer test
更新日志
请参阅更新日志了解最近更改的详细信息。
贡献
请参阅贡献指南以获取详细信息。
安全漏洞
请查看我们的安全策略了解如何报告安全漏洞。
鸣谢
许可证
MIT 许可证 (MIT)。有关更多信息,请参阅许可证文件。