aschmelyun / sphinxsearch
Laravel ^5.4 版本的 Sphinxsearch 扩展包
dev-master
2022-03-21 08:21 UTC
Requires
- php: >=5.3.0
- gigablah/sphinxphp: 2.0.8
- illuminate/support: ^5.0|^6.0|^7.0|^8.0|^9.0
This package is auto-updated.
Last update: 2024-09-21 14:12:29 UTC
README
这是一个简单的 Laravel 5.4 扩展包,用于向 Sphinx Search 发送查询。
受到 sngrl/sphinxsearch 的启发,并且使其也适用于 Laravel 5.4。
安装
在您的控制台中运行以下命令以从 Packagist 拉取扩展包。
composer require cugr/sphinxsearch:dev-master
更新 composer 后,将 ServiceProvider 添加到 config/app.php 文件中的 "providers" 数组中。
'providers' => [ /*** Some others providers ***/ CuGR\SphinxSearch\SphinxSearchServiceProvider::class, ],
您可以将此行添加到可能使用 SphinxSearch 的文件中。
use CuGR\SphinxSearch\SphinxSearch;
配置
要使用 Sphinx Search,您需要配置索引以及应该查询的模型。为此,将配置发布到您的应用程序中。
php artisan vendor:publish --provider="CuGR\SphinxSearch\SphinxSearchServiceProvider"
这将在配置目录下创建一个名为 config/sphinxsearch.php
的文件。根据需要修改。
使用方法
基本查询(原始 Sphinx 结果)
$sphinx = new SphinxSearch(); // or $sphinx = new SphinxSearch('connection_name'); $results = $sphinx->search('my query', 'index_name')->query();
基本查询(使用 Eloquent)
$results = $sphinx->search('my query', 'index_name')->get();
使用限制和过滤器查询另一个 Sphinx 索引。
$results = $sphinx->search('my query', 'index_name') ->limit(30) ->filter('attribute', array(1, 2)) ->range('int_attribute', 1, 10) ->get();
指定匹配和排序类型的查询。
$result = $sphinx->search('my query', 'index_name') ->setFieldWeights( array( 'partno' => 10, 'name' => 8, 'details' => 1 ) ) ->setMatchMode(\Sphinx\SphinxClient::SPH_MATCH_EXTENDED) ->setSortMode(\Sphinx\SphinxClient::SPH_SORT_EXTENDED, "@weight DESC") ->get(true); //passing true causes get() to respect returned sort order
许可
CuGR Sphinx Search 是开源软件,遵循 MIT 许可协议