YiiSolr

A wrapper for the pecl solr library that provides common Yii constructs, such as models, data providers etc

  • 所有者: phpnode/YiiSolr
  • 平台:
  • 许可证:
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

Introduction

A Yii package that provides a wrapper for the pecl solr library (http://www.php.net/manual/en/book.solr.php) to make fast searching with Yii really easy.
The wrapper allows the use of familiar Yii constructs such as models, data providers etc with a solr index.

Installation

First install the pecl solr extension

If this command fails, you may find it easier to compile the pecl solr extension from source.

If you do not already have a packages directory and alias set up, first create a directory called "packages" in your application folder.
Then add an alias to your main config, e.g.

Now extract the files to packages/solr

Running unit tests

The unit tests depend on sqlite to provide the test data, please ensure the php PDO sqlite module is installed before continuing.

The unit tests also depend on the example index that ships with solr.
Go to your solr installation directory and in the "example" folder run

This should start the solr server running on port 8983 by default. If you're using a different port, please configure it in the packages/solr/tests/common.php file.

Now go to your application tests directory, usually protected/tests and run the following command:

This will run the unit tests, if all went well they should all pass, otherwise please check your configuration.

Configuring your solr connection

Before we can use solr in our application, we must configure a connection to use.
In the application config, add the following

This will configure an application component called "solr".
If you're dealing with more than one index, define a new solr connection for each one, giving each a unique name.

Indexing a document with solr

To add a document to solr we use the {@link ASolrDocument} class.
Example:

Remember - Your changes won't appear in solr until a commit occurs.
If you need your data to appear immediately, use the following syntax:

If you need to deal with multiple solr indexes, it's often best to define a model for
each index you're dealing with. To do this we extend ASolrDocument in the same way that we would extend CActiveRecord when defining a model
For example:

Searching solr

To find documents in solr, we use the following methods:

The most useful of these methods are find() and findAll(). Both these methods take a criteria parameter, this criteria parameter should be an instance of {@link ASolrCriteria}.
Example: Find all documents with the name "test"

Alternative method:

Example: Find a job with the unique id of 123

Example: Find the total number of jobs in the index

Using data providers

Often we need to use a data provider to retrieve paginated lists of results.
Example:

Removing items from the index

To remove an item from the index, use the following syntax:

主要指标

概览
名称与所有者phpnode/YiiSolr
主编程语言PHP
编程语言PHP (语言数: 1)
平台
许可证
所有者活动
创建于2011-10-18 16:09:56
推送于2016-10-24 15:33:14
最后一次提交2014-06-29 14:52:14
发布数0
用户参与
星数46
关注者数12
派生数17
提交数76
已启用问题?
问题数11
打开的问题数6
拉请求数5
打开的拉请求数1
关闭的拉请求数1
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?