Download the PHP package daanbiesterbos/solr-bundle without Composer
On this page you can find all versions of the php package daanbiesterbos/solr-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download daanbiesterbos/solr-bundle
More information about daanbiesterbos/solr-bundle
Files in daanbiesterbos/solr-bundle
Package solr-bundle
Short Description Symfony Solr integration bundle
License MIT
Homepage https://github.com/daanbiesterbos/SolrBundle
Informations about the package solr-bundle
SolrBundle
Introduction
This is a FORK from https://github.com/floriansemm/SolrBundle. 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 is a 3 step process:
- Download SolrBundle
- Enable the Bundle
- Configure the SolrBundle
- Configure your entity
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:
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
Add the bundle to config/bundles.php
Step 3: Configure the SolrBundle
Finally, configure the bundle:
Default values will be used for any option left out.
With DSN
Any values in schema
, host
, port
and path
option, will be ignored if you use the dsn
option.
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)
.
The bundle handles now updates / inserts / deletions for your configured entity.
Annotation reference
@Solr\Document
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
If you specify your own repository, the repository must extend the FS\SolrBundle\Repository\Repository
class.
index
property
It is possible to specify a core the document will be indexed in:
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.
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
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.
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
This annotation should be added to properties that should be indexed. You should specify the type
option for the annotation.
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
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
Set this property if you want to index collections with nested Objects.
Object relations
For more information read the more detailed "How to index relation" guide
@Solr\SynchronizationFilter(callback="shouldBeIndexed")
annotation
In some cases, an entity should not be indexed. For this, you have the SynchronizationFilter
annotation to run a filter-callback.
The callback property specifies an callable function, which should return a boolean value, specifying whether a concrete entity should be indexed.
Queries
Query a field of a document
Querying the index is done via the solr.client
service:
or
Query all fields of a document
The previous examples were only querying the title
field. You can also query all fields with a string.
Define a custom query string
If you need more flexiblity in your queries you can define your own query strings:
The QueryBuilder
The query-builder based on https://github.com/minimalcode-org/search Criteria API.
To keep your code clean you should move the select-criteria in a repository-class:
Configure HydrationModes
HydrationMode tells the bundle how to create an entity from a document.
FS\SolrBundle\Doctrine\Hydration\HydrationModes::HYDRATE_INDEX
- use only the data from solrFS\SolrBundle\Doctrine\Hydration\HydrationModes::HYDRATE_DOCTRINE
- merge the data from solr with the entire doctrine-entity
With a custom query:
With a custom document-repository you have to set the property $hydrationMode
itself:
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
In your repository you have full access to the querybuilder.
Commands
Here's all the commands provided by this bundle:
solr:index:clear
- delete all documents in the indexsolr:index:populate
- synchronize the db with the indexsolr:schema:show
- shows your configured documents
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 some solution how to sync your DB with Solr.
Extend Solarium
To extend Solarium with your own plugins, create a tagged service:
To hook into the Solarium events create a common Symfony event-listener:
Document helper
Retrieve the last insert entity-id
All versions of solr-bundle with dependencies
solarium/solarium Version ^4.0
symfony/dependency-injection Version ^4.4|^5
symfony/cache Version ^4.4|^5
symfony/http-kernel Version ^4.4|^5
symfony/config Version ^4.4|^5
symfony/doctrine-bridge Version ^4.4|^5
minimalcode/search Version ^1.0
ramsey/uuid Version ^3.5|^4.1
myclabs/deep-copy Version ^1.6
doctrine/annotations Version ^1.7