ramzi-alqrainy/solr-php

Apache Solr 安装中用于索引和搜索文档的 PHP 库。

dev-master 2018-12-22 20:30 UTC

This package is not auto-updated.

Last update: 2024-09-21 21:44:58 UTC


README

Apache Solr 安装中用于索引和搜索文档的 PHP 库。

功能

  1. 兼容 Solr 7.x
  2. 查询、删除、优化。
  3. 使用 curl 而不是 file_get_content 来实现快速。
  4. 使用 json 进行索引而不是 xml,同时你也可以使用 xml。

安装

在你的项目中安装 Composer

curl -sS https://getcomposer.org/installer | php

在你的项目中安装 Solr PHP 客户端库

vim composer.json

"require": {

    "Ramzi-Alqrainy/solr-php": "dev-master",
    
}

$ php composer.phar install

如何使用

使用此库进行 Solr 的普通查询非常简单,以下是一个示例

		// Build Solr query
		$options = array (
				'qf' => 'contact_ss ',
				'q.op' => 'OR',
				'defType' => 'edismax',
				'sort' => 'contact_id desc',
		);
Yii::$app->solr->get ( $query, $offset, $limit, $options );
var_dump($results->response->numFound);

查询 Apache Solr 所需的步骤。应使用 Yii::$app->solr(或你在配置中命名的 Solr 应用组件)。

要设置应用程序,只需将其添加到配置中。例如

    'components' => [
    	'solr'=>[
    		'class'=>'common\components\ApacheSolr',
    		'host'=>'localhost',
    		'port'=>8983,
    		'indexPath'=>'/solr/collection1'
    	],