PHPackages                             daanbiesterbos/solr-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Search &amp; Filtering](/categories/search)
4. /
5. daanbiesterbos/solr-bundle

ActiveSymfony-bundle[Search &amp; Filtering](/categories/search)

daanbiesterbos/solr-bundle
==========================

Symfony Solr integration bundle

v2.0.4(5y ago)020.3k2MITPHPPHP ^7.3

Since Oct 25Pushed 5y agoCompare

[ Source](https://github.com/DaanBiesterbos/SolrBundle)[ Packagist](https://packagist.org/packages/daanbiesterbos/solr-bundle)[ Docs](https://github.com/daanbiesterbos/SolrBundle)[ RSS](/packages/daanbiesterbos-solr-bundle/feed)WikiDiscussions master Synced 4d ago

READMEChangelog (5)Dependencies (15)Versions (53)Used By (0)

SolrBundle
==========

[](#solrbundle)

[![Build SolrBundle](https://github.com/DaanBiesterbos/SolrBundle/actions/workflows/build.yaml/badge.svg)](https://github.com/DaanBiesterbos/SolrBundle/actions/workflows/build.yaml)[![Latest Stable Version](https://camo.githubusercontent.com/797907fd9f02a961db487331bba5730d06281da9cc80055bbba05f7ec8f42413/68747470733a2f2f706f7365722e707567782e6f72672f6461616e62696573746572626f732f736f6c722d62756e646c652f762f737461626c652e737667)](https://packagist.org/packages/daanbiesterbos/solr-bundle)[![Total Downloads](https://camo.githubusercontent.com/6b97d169eea33a0dbb5d55fc5aea56fef36cf092d12f3ecb04ef41036491ec1a/68747470733a2f2f706f7365722e707567782e6f72672f6461616e62696573746572626f732f736f6c722d62756e646c652f646f776e6c6f6164732e737667)](https://packagist.org/packages/daanbiesterbos/solr-bundle)

Introduction
------------

[](#introduction)

**This is a FORK from . The original bundle seems to abandoned. I forked the bundle to solve a pretty bad performance issue. Feel free to use this bundle or use the original bundle instead.**

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

Installation
------------

[](#installation)

Installation is a 3 step process:

1. Download SolrBundle
2. Enable the Bundle
3. Configure the SolrBundle
4. Configure your entity

### Step 1: Install SolrBundle

[](#step-1-install-solrbundle)

This bundle is available on Packagist. You can install it using Composer. If you have not yet installed the Solr Bundle, this will be easy. Run the following command:

```
composer require daanbiesterbos/solr-bundle
```

**Important:**If you are currently using the original bundle the update is slightly more tricky.

When you remove the old bundle **or** when you change the bundle in composer.json, you'll run into issues. Symfony will temporarily not support the fs\_solr configuration. Also, composer will automatically remove the bundle from bundles.php. In my opinion this is the most reliable way to migrate from the original bundle.

- Open composer.json.
- Rename *floriansemm/solr-bundle* to *daanbiesterbos/solr-bundle*.
- Run `composer update --no-scripts`, this will avoid a failing cache:clear command.
- Open *config/bundles.php*
- Add the bundle (again)

### Step 2: Enable the bundle

[](#step-2-enable-the-bundle)

Add the bundle to *config/bundles.php*

```
return [
    FS\SolrBundle\FSSolrBundle::class => ['all' => true],
];
```

### Step 3: Configure the SolrBundle

[](#step-3-configure-the-solrbundle)

Finally, configure the bundle:

```
# app/config/config.yml
fs_solr:
    endpoints:
        core0:
            schema: http
            host: host
            port: 8983
            path: /solr/core0
            core: corename
            timeout: 5
```

Default values will be used for any option left out.

#### With DSN

[](#with-dsn)

```
# app/config/config.yml
fs_solr:
    endpoints:
        core0:
            dsn: http://host:8983/solr
            core: core0
            timeout: 5
```

Any values in `schema`, `host`, `port` and `path` option, will be ignored if you use the `dsn` option.

### Step 4: Configure your entities

[](#step-4-configure-your-entities)

To make an entity indexed, you must add some annotations to your entity. Basic configuration requires two annotations: `@Solr\Document()`, `@Solr\Id()`. To index data add `@Solr\Field()` to your properties.

If you want to index documents without any database, then you have to use the same annotations. Make sure you have set a Id or set `@Solr\Id(generateId=true)`.

```
// ....
use FS\SolrBundle\Doctrine\Annotation as Solr;

/**
* @Solr\Document()
* @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", getter="format('Y-m-d\TH:i:s.z\Z')")
    *
    * @ORM\Column(name="created_at", type="datetime")
    */
    private $created_at = null;
}
```

The bundle handles now updates / inserts / deletions for your configured entity.

Annotation reference
====================

[](#annotation-reference)

`@Solr\Document` annotation
---------------------------

[](#solrdocument-annotation)

This annotation denotes that an entity should be indexed as a document. It has several optional properties:

- `repository`
- `index`
- `indexHandler`

### Setting custom repository class with `repository` option

[](#setting-custom-repository-class-with-repository-option)

If you specify your own repository, the repository must extend the `FS\SolrBundle\Repository\Repository` class.

```
/**
 * @Solr\Document(repository="My/Custom/Repository")
 */
class SomeEntity
{
    // ...
}
```

### `index` property

[](#index-property)

It is possible to specify a core the document will be indexed in:

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

### `indexHandler` property

[](#indexhandler-property)

By default, all documents will be indexed in the core `core0`. If your entities/documents have different languages, then you can setup a callback method, which should return the core the entity will be indexed in.

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

Each core must be set up in `config.yml` under `endpoints`. If you leave the `index` or `indexHandler` property empty, then the default core will be used (first one in the `endpoints` list). To index a document in all cores, use `*` as index value.

`@Solr\Id` annotation
---------------------

[](#solrid-annotation)

This annotation is required to index an entity. The annotation has no properties. You should add this annotation to the field that will be used as the primary identifier for the entity/document.

```
class Post
{
    /**
     * @Solr\Id
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */

    private $id;
}
```

### `generateId` option

[](#generateid-option)

Set this option to true and a the bundle will generate a Id for you. Use this option if you have no underlying DB which generates incremental Ids for you.

`@Solr\Field` annotation
------------------------

[](#solrfield-annotation)

This annotation should be added to properties that should be indexed. You should specify the `type` option for the annotation.

### `type` property

[](#type-property)

Currently, a basic set of types is implemented:

- string(s)
- text(s)
- date(s)
- integer(s)
- float(s)
- double(s)
- long(s)
- boolean(s)

If you have a customized `schema.xml` than you don't need to setup a field-type.

### `fieldModifier` property

[](#fieldmodifier-property)

Solr supports partial updates of fields in an existing document. Supported values are:

- set
- add (multivalue field only, adds a value(s) to a existing list)
- remove (multivalue field only, removes a value(s) from existing list)
- inc (integer field only)

### `nestedClass` property

[](#nestedclass-property)

Set this property if you want to index collections with nested Objects.

### Object relations

[](#object-relations)

[For more information read the more detailed "How to index relation" guide](Resources/doc/index_relations.md)

### `@Solr\SynchronizationFilter(callback="shouldBeIndexed")` annotation

[](#solrsynchronizationfiltercallbackshouldbeindexed-annotation)

In some cases, an entity should not be indexed. For this, you have the `SynchronizationFilter` annotation to run a filter-callback.

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

The callback property specifies an callable function, which should return a boolean value, specifying whether a concrete entity should be indexed.

Queries
-------

[](#queries)

### Query a field of a document

[](#query-a-field-of-a-document)

Querying the index is done via the `solr.client` service:

```
$query = $this->get('solr.client')->createQuery('AcmeDemoBundle:Post');
$query->addSearchTerm('title', 'my title');
$query->addSearchTerm('collection_field', array('value1', 'value2'));

$result = $query->getResult();
```

or

```
$posts = $this->get('solr.client')->getRepository('AcmeDemoBundle:Post')->findOneBy(array(
    'title' => 'my title',
    'collection_field' => array('value1', 'value2')
));
```

### Query all fields of a document

[](#query-all-fields-of-a-document)

The previous examples were only querying the `title` field. You can also query all fields with a string.

```
$query = $this->get('solr.client')->createQuery('AcmeDemoBundle:Post');
$query->queryAllFields('my title');

$result = $query->getResult();
```

### Define a custom query string

[](#define-a-custom-query-string)

If you need more flexiblity in your queries you can define your own query strings:

```
$query = $this->get('solr.client')->createQuery('AcmeDemoBundle:Post');
$query->setCustomQuery('id:post_* AND (author_s:Name1 OR author_s:Name2)');

$result = $query->getResult();
```

### The QueryBuilder

[](#the-querybuilder)

The query-builder based on [https://github.com/minimalcode-org/search](/minimalcode-org/search) Criteria API.

```
$queryBuilder = $this->get('solr.client')->getQueryBuilder('AcmeDemoBundle:Post');
$result = $queryBuilder
    ->where('author')
        ->is('Name1')
    ->orWhere('author')
        ->is('Name2')
    ->getQuery()
    ->getResult();
```

To keep your code clean you should move the select-criteria in a repository-class:

```
class YourRepository extends Repository
{
    public function findAuthor($name1, $name2)
    {
        return $this->getQueryBuilder()
            ->where('author')
                ->is($name1)
            ->orWhere('author')
                ->is($name2)
            ->getQuery()
            ->getResult();
    }
}
```

### Configure HydrationModes

[](#configure-hydrationmodes)

HydrationMode tells the bundle how to create an entity from a document.

1. `FS\SolrBundle\Doctrine\Hydration\HydrationModes::HYDRATE_INDEX` - use only the data from solr
2. `FS\SolrBundle\Doctrine\Hydration\HydrationModes::HYDRATE_DOCTRINE` - merge the data from solr with the entire doctrine-entity

With a custom query:

```
$query = $this->get('solr.client')->createQuery('AcmeDemoBundle:Post');
$query->setHydrationMode($mode)
```

With a custom document-repository you have to set the property `$hydrationMode` itself:

```
public function find($id)
{
    $this->hydrationMode = HydrationModes::HYDRATE_INDEX;

    return parent::find($id);
}
```

Repositories
------------

[](#repositories)

Your should define your own repository-class to make your custom queries reuseable. How to configure a repository for a document have a look at [the annotation section](https://github.com/floriansemm/SolrBundle#setting-custom-repository-class-with-repository-option)

```
namespace AppBundle\Search;

use FS\SolrBundle\Repository\Repository;

class ProviderRepository extends Repository
{
    public function findPost($what)
    {
        $query = $this->solr->createQuery('AcmeDemoBundle:Post');
        // some query-magic here

        return $query->getResult();
    }
}
```

In your repository you have full access to the querybuilder.

Commands
--------

[](#commands)

Here's all the commands provided by this bundle:

- `solr:index:clear` - delete all documents in the index
- `solr:index:populate` - synchronize the db with the index
- `solr:schema:show` - shows your configured documents

### Indexing huge sets of entities

[](#indexing-huge-sets-of-entities)

The `solr:index:populate` command works well for sets up to 300k entities, everthing large makes the command very slow. You can find [here](Resources/doc/indexing.md) some solution how to sync your DB with Solr.

Extend Solarium
---------------

[](#extend-solarium)

To extend Solarium with your own plugins, create a tagged service:

```

```

To hook into the [Solarium events](http://solarium.readthedocs.io/en/stable/customizing-solarium/#plugin-system) create a common Symfony event-listener:

```

```

Document helper
---------------

[](#document-helper)

### Retrieve the last insert entity-id

[](#retrieve-the-last-insert-entity-id)

```
$helper = $this->get('solr.client')->getDocumentHelper();
$id = $helper->getLastInsertDocumentId();
```

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~62 days

Recently: every ~22 days

Total

50

Last Release

1873d ago

Major Versions

0.9 → 1.02014-01-20

v1.6.5 → v2.0-alpha12016-12-28

v1.7.1 → v2.0.02020-12-29

PHP version history (7 changes)0.1PHP &gt;=5.3.2

1.3PHP &gt;=5.4.5

1.5PHP &gt;=5.5.9

v1.6.5PHP &gt;=5.5.9 | ^7.0

v2.0-alpha1PHP ^7.0

v2.0.0PHP ^7.3

v2.0.1PHP ^7.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3858692?v=4)[Daan Biesterbos](/maintainers/DaanBiesterbos)[@DaanBiesterbos](https://github.com/DaanBiesterbos)

---

Top Contributors

[![floriansemm](https://avatars.githubusercontent.com/u/1059500?v=4)](https://github.com/floriansemm "floriansemm (46 commits)")[![royopa](https://avatars.githubusercontent.com/u/442991?v=4)](https://github.com/royopa "royopa (9 commits)")[![zquintana](https://avatars.githubusercontent.com/u/130444?v=4)](https://github.com/zquintana "zquintana (9 commits)")[![bb-fuf](https://avatars.githubusercontent.com/u/5476934?v=4)](https://github.com/bb-fuf "bb-fuf (8 commits)")[![patrikorup](https://avatars.githubusercontent.com/u/2561991?v=4)](https://github.com/patrikorup "patrikorup (2 commits)")[![marfillaster](https://avatars.githubusercontent.com/u/121793?v=4)](https://github.com/marfillaster "marfillaster (2 commits)")[![jkwakman](https://avatars.githubusercontent.com/u/9083060?v=4)](https://github.com/jkwakman "jkwakman (2 commits)")[![dcaillibaud](https://avatars.githubusercontent.com/u/1430515?v=4)](https://github.com/dcaillibaud "dcaillibaud (2 commits)")[![frne](https://avatars.githubusercontent.com/u/724395?v=4)](https://github.com/frne "frne (2 commits)")[![kix](https://avatars.githubusercontent.com/u/345754?v=4)](https://github.com/kix "kix (1 commits)")[![nathankot](https://avatars.githubusercontent.com/u/1400871?v=4)](https://github.com/nathankot "nathankot (1 commits)")[![intel352](https://avatars.githubusercontent.com/u/77607?v=4)](https://github.com/intel352 "intel352 (1 commits)")[![arcanis](https://avatars.githubusercontent.com/u/1037931?v=4)](https://github.com/arcanis "arcanis (1 commits)")[![chellem](https://avatars.githubusercontent.com/u/570856?v=4)](https://github.com/chellem "chellem (1 commits)")[![davidvartanian](https://avatars.githubusercontent.com/u/1845242?v=4)](https://github.com/davidvartanian "davidvartanian (1 commits)")[![gigo6000](https://avatars.githubusercontent.com/u/387648?v=4)](https://github.com/gigo6000 "gigo6000 (1 commits)")[![gitter-badger](https://avatars.githubusercontent.com/u/8518239?v=4)](https://github.com/gitter-badger "gitter-badger (1 commits)")[![alcaeus](https://avatars.githubusercontent.com/u/383198?v=4)](https://github.com/alcaeus "alcaeus (1 commits)")[![jakesylvestre](https://avatars.githubusercontent.com/u/6392429?v=4)](https://github.com/jakesylvestre "jakesylvestre (1 commits)")[![josephwoodward](https://avatars.githubusercontent.com/u/1237341?v=4)](https://github.com/josephwoodward "josephwoodward (1 commits)")

---

Tags

searchsymfonyindexsolr

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/daanbiesterbos-solr-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/daanbiesterbos-solr-bundle/health.svg)](https://phpackages.com/packages/daanbiesterbos-solr-bundle)
```

###  Alternatives

[floriansemm/solr-bundle

Symfony Solr integration bundle

12280.2k2](/packages/floriansemm-solr-bundle)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[cmsig/seal-symfony-bundle

An integration of CMS-IG SEAL search abstraction into Symfony Framework.

15195.8k5](/packages/cmsig-seal-symfony-bundle)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[a2lix/translation-form-bundle

Translate your doctrine objects easily with some helpers

3376.9M38](/packages/a2lix-translation-form-bundle)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

7310.3k29](/packages/open-dxp-opendxp)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
