<commit_before>
[![Build Status](https://secure.travis-ci.org/floriansemm/SolrBundle.png?branch=master)](http://travis-ci.org/floriansemm/SolrBundle) 
[![Latest Stable Version](https://poser.pugx.org/floriansemm/solr-bundle/v/stable.svg)](https://packagist.org/packages/floriansemm/solr-bundle)
[![Total Downloads](https://poser.pugx.org/floriansemm/solr-bundle/downloads.svg)](https://packagist.org/packages/floriansemm/solr-bundle)

This Bundle provides a simple API to index and query a Solr Index. 

And do not forget to join the Gitter chat [![join the chat at https://gitter.im/floriansemm/SolrBundle](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/floriansemm/SolrBundle?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

# Configuration

The bundle requires a working doctrine-orm or doctrine-mongodb configuration. There are no differences in the use.

## Install the Bundle

Bundle

1.  Register bundle in AppKernel.php

# app/AppKernel.php

```php
$bundles = array(
    // ...
    new FS\SolrBundle\FSSolrBundle(),
    // ...
);
```

2.  Add Bundle to autoload

	A. Via composer, add in your composer.json

	composer require floriansemm/solr-bundle

	or

        "require": {
            // ...  
            "floriansemm/solr-bundle": "dev-master"
        }
        
	B.  or manually, in app/autoload.php
	
	i. In symfony 2.1.4 (supposing you clone the bundle in vendor/floriansemm/solr-bundle/FS/, making available vendor/floriansemm/solr-bundle/FS/SolrBundle/FSSolrBundle.php)

        $loader->add('FS\\SolrBundle', array(__DIR__.'/../vendor/floriansemm/solr-bundle'));		

	ii. in older version it could be

        $loader->registerNamespaces(array(
            // ...
            'FS' => __DIR__.'/../vendor/bundles',
            // ...
        ));

## Multiple Indexes

You have to setup the connection options

    # app/config/config.yml
    fs_solr:
      endpoints:
        core1:
          host: host
          port: 8983
          path: /solr/core1
          core: corename
          timeout: 5
        core2:
          host: host
          port: 8983
          path: /solr/core2
          core: corename
          timeout: 5

With this config you can setup two cores: `core1` and `core2`. See section `Specify cores` for more information.

# Usage #

## Annotations

To put an entity to the index, you must add some annotations to your entity:

```php
	// your Entity

	// ....
	use FS\SolrBundle\Doctrine\Annotation as Solr;
	
	/**
	 * @Solr\Document(repository="Full\Qualified\Class\Name")
	 * @ORM\Table()
	 */
	class Post
	{
		/**
		 * @Solr\Id
		 *
		 * @ORM\Column(name="id", type="integer")
		 * @ORM\Id
		 * @ORM\GeneratedValue(strategy="AUTO")
		 */

		private $id;
		/**
		 *
		 * @Solr\Field(type="string")
		 *
		 * @ORM\Column(name="title", type="string", length=255)
		 */
		private $title = '';

		/**
		* 
		* @Solr\Field(type="string")
		*
		* @ORM\Column(name="text", type="text")
		*/
		private $text = '';

		/**
		* @Solr\Field(type="date")
		*
		* @ORM\Column(name="created_at", type="datetime")
		*/
		private $created_at = null;
	}
```

### Supported field types

Currently is a basic set of types implemented.

- string
- text
- date
- integer
- float
- double
- long
- boolean

It is possible to use custum field types (schema.xml).

### Filter annotation

In some cases a entity should not be index. For this you have the `SynchronizationFilter` Annotation.

```php
	/**
	* @Solr\Document
	* @Solr\SynchronizationFilter(callback="shouldBeIndex")
	*/
	class SomeEntity
	{
		/**
		* @return boolean
		*/
		public function shouldBeIndex()
		{
			// put your logic here
		}
	}
```

The callback property specifies an callable function, which decides whether the should index or not. 	

### Specify cores

It is possible to specify a core dedicated to a document

```php
       /**
    	* @Solr\Document(index="core0")
    	*/
    	class SomeEntity
    	{
    	    // ...
    	}
```

All documents will be indexed in the core `core0`. If your entities/document have different languages then you can setup
a callback method, which returns the preferred core for the entity.

```php
       /**
    	* @Solr\Document(indexHandler="indexHandler")
    	*/
    	class SomeEntity
    	{
    	    public function indexHandler()
    	    {
    	        if ($this->language == 'en') {
    	            return 'core0';
    	        }
    	    }
    	}
```

Each core must setup up in the config.yml under `endpoints`. If you leave the `index` or `indexHandler` property empty,<commit_msg>updated syntax highligthing<commit_after>
[![Build Status](https://secure.travis-ci.org/floriansemm/SolrBundle.png?branch=master)](http://travis-ci.org/floriansemm/SolrBundle) 
[![Latest Stable Version](https://poser.pugx.org/floriansemm/solr-bundle/v/stable.svg)](https://packagist.org/packages/floriansemm/solr-bundle)
[![Total Downloads](https://poser.pugx.org/floriansemm/solr-bundle/downloads.svg)](https://packagist.org/packages/floriansemm/solr-bundle)

This Bundle provides a simple API to index and query a Solr Index. 

And do not forget to join the Gitter chat [![join the chat at https://gitter.im/floriansemm/SolrBundle](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/floriansemm/SolrBundle?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

# Configuration

The bundle requires a working doctrine-orm or doctrine-mongodb configuration. There are no differences in the use.

## Install the Bundle

Bundle

1.  Register bundle in AppKernel.php

# app/AppKernel.php

```php
$bundles = array(
    // ...
    new FS\SolrBundle\FSSolrBundle(),
    // ...
);
```

2.  Add Bundle to autoload

	A. Via composer, add in your composer.json

```sh
composer require floriansemm/solr-bundle
```
	or

        "require": {
            // ...  
            "floriansemm/solr-bundle": "dev-master"
        }
        
	B.  or manually, in app/autoload.php
	
	i. In symfony 2.1.4 (supposing you clone the bundle in vendor/floriansemm/solr-bundle/FS/, making available vendor/floriansemm/solr-bundle/FS/SolrBundle/FSSolrBundle.php)

```php
$loader->add('FS\\SolrBundle', array(__DIR__.'/../vendor/floriansemm/solr-bundle'));		
```
	ii. in older version it could be

```php
$loader->registerNamespaces(array(
    // ...
    'FS' => __DIR__.'/../vendor/bundles',
    // ...
));
```

## Multiple Indexes

You have to setup the connection options

```config
    # app/config/config.yml
    fs_solr:
      endpoints:
        core1:
          host: host
          port: 8983
          path: /solr/core1
          core: corename
          timeout: 5
        core2:
          host: host
          port: 8983
          path: /solr/core2
          core: corename
          timeout: 5
```

With this config you can setup two cores: `core1` and `core2`. See section `Specify cores` for more information.

# Usage #

## Annotations

To put an entity to the index, you must add some annotations to your entity:

```php
// your Entity

// ....
use FS\SolrBundle\Doctrine\Annotation as Solr;
	
/**
* @Solr\Document(repository="Full\Qualified\Class\Name")
* @ORM\Table()
*/
class Post
{
    /**
     * @Solr\Id
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */

    private $id;
    /**
     *
     * @Solr\Field(type="string")
     *
     * @ORM\Column(name="title", type="string", length=255)
     */
    private $title = '';

    /**
     * 
     * @Solr\Field(type="string")
     *
     * @ORM\Column(name="text", type="text")
     */
    private $text = '';

   /**
    * @Solr\Field(type="date")
    *
    * @ORM\Column(name="created_at", type="datetime")
    */
    private $created_at = null;
}
```

### Supported field types

Currently is a basic set of types implemented.

- string
- text
- date
- integer
- float
- double
- long
- boolean

It is possible to use custum field types (schema.xml).

### Filter annotation

In some cases a entity should not be index. For this you have the `SynchronizationFilter` Annotation.

```php
/**
 * @Solr\Document
 * @Solr\SynchronizationFilter(callback="shouldBeIndex")
 */
class SomeEntity
{
    /**
     * @return boolean
    */
    public function shouldBeIndex()
    {
        // put your logic here
    }
}
```

The callback property specifies an callable function, which decides whether the should index or not. 	

### Specify cores

It is possible to specify a core dedicated to a document

```php
/**
 * @Solr\Document(index="core0")
 */
class SomeEntity
{
    // ...
}
```

All documents will be indexed in the core `core0`. If your entities/document have different languages then you can setup
a callback method, which returns the preferred core for the entity.

```php
/**
 * @Solr\Document(indexHandler="indexHandler")
 */
class SomeEntity
{
    public function indexHandler()
    {
        if ($this->language == 'en') {
            return 'core0';
        }
    }
}
```

Each core must setup up in the config.yml under `endpoints`. If you leave the `index` or `indexHandler` property empty,
{'fraction_non_alphanumeric': 0.13822656850895507, 'fraction_numerical': 0.0063729260520821885, 'mean_word_length': 2.6909975669099757, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 16, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '156624', 'n_tokens_mistral': 3194, 'n_tokens_neox': 2955, 'n_words': 753}