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?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?