Developers

License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

<!-- Field to use to determine and enforce document uniqueness.
Unless this field is marked with required="false", it will be a required field
--><uniqueKey>sf_unique_id</uniqueKey><!-- field for the QueryParser to use when an explicit fieldname is absent --><defaultSearchField>sf_text</defaultSearchField><!-- copyField commands copy one field to another at the time a document
is added to the index. It's used either to index the same field differently,
or to add multiple fields to the same field for easier/faster searching.
--><copyFieldsource="*_t"dest="sf_text"/><copyFieldsource="*_s"dest="sf_text" /

Before starting Solr, you need to create the log directory.

$ mkdir log/solr

Once your configuration is correct, you can start Solr. Of course, you need a java installation.

About logging

When you start Solr, two kind of log files will be created: Solr log, and Jetty log. With the embedded installation, all logs will be created in /var/www/youproject/log/solr.
Don't forget to create this directory.

Rebuild your model, load your data, et voilÃ !
Each time a Post object is created/updated/deleted, the Solr index will be automaticaly updated.

Maybe you don't want your content to be indexed real-time (e.g, if you use data import handler, see below) ?
Set the realtime option to false.

Post:
actAs:
Solr:
fields: [ title, body ]
realtime: false

Field mapping

In the previous example, the plugin will try to index the title and body fields into Solr.
You have to manualy define those names in the Solr schema
(in tjSolrDoctrineBehaviorPlugin/lib/vendor/solr/solr/conf/schema.xml), or indexing will fail :

Configuring each field in the Solr schema can be a pain. That's why this plugin allows you to use
Solr's dynamic fields.

If your model field's name matches some specific pattern, the Solr field will be automaticaly created.
For example, each field suffixed with "_t" will be created with a "text" type, and copied into the "sf_text"
default search field.

Working with I18n

The body field will be automaticaly indexed as many times as there are defined languages.
Field name will be suffixed with the language in Solr. If you want to perform a search for a
specific language, use an explicit field name in your query.

Notice that the default search field is a concatenation of all text fields, and it is optimized to
work with english text. As soon as you index i18n content, you should always explicitly set the language.

Instead of a dummy php array, the plugin can also generate a Doctrine_Query object,
which you can manipulate as usual. For instance, you can modify sorting options, paginate the list,
add other criterias, etc.

Note that you have to enable the Timestampable template for the delta import to work.

Transactions

Solr supports transactions. By default, the plugins sends a commit message after every index operation.
However, you may want to perform many operations in one time, then it is more efficient to send only one
commit when the job's done.

Testing the plugin

This plugins comes with an auto-generated (with the sfTaskExtraPlugin) fixtures project, to run the tests
without touching your own app. Tests are not included in the package version, so you'll have to checkout
the trunk version.

Before you run the tests, make sure Solr is running is accessible.
Note that those tests are written to be run with lime 2 (alpha1).

WARNING : By default, the tests will be run over the default Solr index. Make sure you won't lose any data.

Here's how you can easily run the plugin test suite :

export the SYMFONY shell var to the symfony lib path. Example :

$ export SYMFONY='/var/www/myproject/lib/vendor/symfony-1.4.1/lib/'

Setup the database for testing

The plugin's tests are made to run against an independant db. You have to create it before anything else.