wneuteboom/sphinxsearch

Laravel 包,用于在 Laravel 5 Lumen 中查询 Sphinxsearch

dev-master 2017-10-25 10:05 UTC

This package is auto-updated.

Last update: 2024-09-22 18:51:18 UTC


README

这是一个简单的 Laravel 5 Lumen 包,用于向 Sphinx Search 发送查询。该包是从 sngrl/sphinxsearch 包 fork 的,用于 Laravel 5。

创建此包是为了将其导入到 packagist.org 网站,并允许通过 Composer 进行安装(https://getcomposer.org.cn/)。

安装

在您的 composer.json 文件中添加此包

	"require": {
        /*** Some others packages ***/
		"wneuteboom/sphinxsearch": "dev-master",
	},

在控制台中运行 composer update 命令以拉取最新的 Sphinx Search 版本。

或者在控制台中运行以下命令

composer require wneuteboom/sphinxsearch-lumen:dev-master

更新 composer 后,将 ServiceProvider 添加到 config/app.php 中的 "providers" 数组中

	'providers' => array(
        /*** Some others providers ***/
        WNeuteboom\SphinxSearch\SphinxSearchServiceProvider::class,
    ),

您可以将此行添加到可能使用 SphinxSearch 的文件中

use WNeuteboom\SphinxSearch;

配置

要使用 Sphinx Search,您需要配置您的索引以及它应该查询的模型。为此,将配置发布到您的应用中。

php artisan vendor:publish --provider=WNeuteboom\SphinxSearch\SphinxSearchServiceProvider --force

这将创建文件 config/sphinxsearch.php。根据需要修改主机和端口。

return array (
	'host'    => '127.0.0.1',
	'port'    => 9312,
	'timeout' => 30
);

使用方法

基本查询(原始 Sphinx 结果)

$sphinx = new SphinxSearch();
	
$sphinx
	->index('products')
	->select('id, name')
	->weights([
		'name' => 1
	])
	->search("string to search")
	->skip(0)
	->take(100)
	->get();

基本查询(使用 Eloquent)

$sphinx = new SphinxSearch;
$sphinx
	->index('products')
	->select('id, name')
	->table(\App\SpecificModel)
	->weights([
		'name' => 1
	])
	->search("string to search")
	->skip(0)
	->take(100)
	->get();

许可证

WNeuteboom Sphinx Search 是开源软件,许可协议为 MIT 许可证