Loading repository data…
Loading repository data…
mdiyakov / repository
Symfony 2/3 bundle for integration Doctrine entities with Solr
A transparent discovery signal based on current public GitHub metadata.
This score does not audit code, security, maintainers, documentation quality, or suitability. Verify the repository and its current documentation before adoption.
DoctrineSolrBundle is a Symfony bundle designed to mitigate Solr usage in symfony projects
$ composer require mdiyakov/doctrine-solr-bundle
Composer will install the bundle to your project's vendor/mdiyakov/doctrine-solr-bundle directory.
Enable the bundle in the kernel :
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Nelmio\SolariumBundle\NelmioSolariumBundle(),
new Mdiyakov\DoctrineSolrBundle\MdiyakovDoctrineSolrBundle(),
// ...
);
}
You have to install "NelmioSolariumBundle" also because it's used by MdiyakovDoctrineSolrBundle
DoctrineSolrBundle is using "NelmioSolariumBundle" for solarium integration. So you need to set a configuration to use it. Here is minimum config:
nelmio_solarium: ~
The default solr endpoint will be used in this case (http://localhost:8983/solr)
Init bundle configuration in config.yml. Quick example:
mdiyakov_doctrine_solr:
indexed_entities:
my_entity:
class: AppBundle\Entity\MyEntity
schema: my_schema
config:
- { name: config_field_name, value: config_field_value }
schemes:
my_schema:
document_unique_field: { name: 'uid' }
config_entity_fields:
- { config_field_name: 'config_field_name', document_field_name: 'discriminator', discriminator: true }
fields:
- { entity_field_name: 'id', document_field_name: 'document_id', field_type: int, entity_primary_key: true }
- { entity_field_name: 'title', document_field_name: 'document_title', suggester: 'title' }
As a result "id" and "title" fields of "AppBundle\Entity\MyEntity" will be synced with Solr each time "AppBundle\Entity\MyEntity" is created, updated or removed.
If you use doctrine/orm < 2.5 then you have to add an annotation to "AppBundle\Entity\MyEntity" class:
@ORM\EntityListeners({"Mdiyakov\DoctrineSolrBundle\EventListener\DoctrineEntityListener"})
To search "AppBundle\Entity\MyEntity" use the following code:
// MyController
//...
// @var \Mdiyakov\DoctrineSolrBundle\Finder\ClassFinder $finder
$finder = $this->get('ds.finder')->getClassFinder(MyEntity::class);
/** @var MyEntity[] $searchResults */
$searchResults = $finder->findSearchTermByFields($searchTerm, ['title']);
//...