cugr//sphinxsearch

Laravel ^5.4 的 Sphinxsearch 扩展包

dev-master 2017-08-18 03:36 UTC

This package is not auto-updated.

Last update: 2024-09-28 20:44:52 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 许可证 授权。