YiiSolr

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

  • Owner: phpnode/YiiSolr
  • Platform:
  • License::
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

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:

Main metrics

Overview
Name With Ownerphpnode/YiiSolr
Primary LanguagePHP
Program languagePHP (Language Count: 1)
Platform
License:
所有者活动
Created At2011-10-18 16:09:56
Pushed At2016-10-24 15:33:14
Last Commit At2014-06-29 14:52:14
Release Count0
用户参与
Stargazers Count46
Watchers Count12
Fork Count17
Commits Count76
Has Issues Enabled
Issues Count11
Issue Open Count6
Pull Requests Count5
Pull Requests Open Count1
Pull Requests Close Count1
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private