hotrush / sphinxsearch
Laravel 5 中查询 Sphinxsearch 的包
0.1.0
2018-01-15 20:20 UTC
Requires
- php: >=5.3.0
- gigablah/sphinxphp: 2.0.8
- illuminate/support: ~5.0
This package is auto-updated.
Last update: 2024-09-25 06:54:04 UTC
README
Simple Laravel 5 包,用于执行 Sphinx Search 查询。受 scalia/sphinxsearch 包的 Laravel 4 版本启发。
此包创建是为了导入到 packagist.org 网站,并允许通过 Composer 进行安装(https://getcomposer.org.cn/)。
有关带标签版本的原始 sngrl/sphinxsearch
安装
composer require hotrush/sphinxsearch
更新 composer 后,将 ServiceProvider 添加到 config/app.php 文件中的 "providers" 数组
'providers' => array( /*** Some others providers ***/ sngrl\SphinxSearch\SphinxSearchServiceProvider::class, ),
您可以将此行添加到可能使用 SphinxSearch 的文件中
use sngrl\SphinxSearch\SphinxSearch;
配置
要使用 Sphinx Search,您需要配置索引和查询的模型。为此,将配置发布到您的应用程序。
php artisan vendor:publish --provider=sngrl\SphinxSearch\SphinxSearchServiceProvider --force
这将创建 config/sphinxsearch.php 文件。根据需要修改主机和端口,并配置索引,将它们绑定到表和 id 列。
return array ( 'host' => '127.0.0.1', 'port' => 9312, 'indexes' => array ( 'my_index_name' => array ( 'table' => 'my_keywords_table', 'column' => 'id' ), ) );
或者禁用模型查询,仅获取结果 id 列表。
return array ( 'host' => '127.0.0.1', 'port' => 9312, 'indexes' => array ( 'my_index_name' => FALSE, ) );
用法
基本查询(原始 Sphinx 结果)
$sphinx = new SphinxSearch(); $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
许可证
Sngrl Sphinx Search 是开源软件,许可协议为 MIT 许可证