aternovtsii / search-bundle
Symfony bundle for easy integration with elastic/opensearch search engine and doctrine
Installs: 211
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 1
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=8.2
- doctrine/orm: ^3.0
- murtukov/php-code-generator: ^0.1
- symfony/dependency-injection: ^6.4 || ^7.0
- symfony/event-dispatcher: ^6.4 || ^7.0
- symfony/filesystem: ^6.4 || ^7.0
- symfony/orm-pack: ^2.4
- symfony/translation-contracts: ^3.4
Suggests
- elasticsearch/elasticsearch: For integration with elasticsearch search engine
- opensearch-project/opensearch-php: For integration with opensearch search engine
README
composer require aternovtsii/search-bundle
To enable bundle add the following to your config/bundles.php file
<?php return [ // ... ATSearchBundle\ATSearchBundle::class => ['all' => true], ];
To enable additional doctrine filters add the following to your config/doctrine.yaml file
doctrine: orm: dql: numeric_functions: IFNULL: ATSearchBundle\Doctrine\Extensions\Query\IfNull JSON_CONTAINS: ATSearchBundle\Doctrine\Extensions\Query\JsonContains RAND: ATSearchBundle\Doctrine\Extensions\Query\Rand
Configure bundle in your config/packages/at_search.yaml file
at_search: search: enabled: true client: OpenSearch\Client # OpenSearch\Client or Elasticsearch\Client mappings: App: namespace: App\Entity dir: '%kernel.project_dir%/src/Entity'
To create OpenSearch Client add the following to your config/services.yaml file
OpenSearch\Client: factory: ['OpenSearch\ClientBuilder', 'fromConfig'] arguments: $config: hosts: ['%env(OPENSEARCH_URL)%']
To create ElasticSearch Client add the following to your config/services.yaml file
Elasticsearch\Client: factory: ['Elasticsearch\ClientBuilder', 'fromConfig'] arguments: $config: hosts: ['%env(ELASTICSEARCH_URL)%']
Usage example
<?php namespace App\Entity; use ATSearchBundle\Annotation as ATSearch; use Doctrine\ORM\Mapping as ORM; #[ATSearch\Index] #[ORM\Entity] class User { #[ATSearch\FieldId] #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column] public ?int $id = null; #[ATSearch\FieldString] #[ORM\Column(length: 128)] public ?string $firstName = null; #[ATSearch\FieldMultiString(subFields: 'email')] #[ORM\OneToMany(mappedBy: 'user', targetEntity: Email::class)] public Collection $emails;
To enable default reindex based on Doctrine events add the following to your config/packages/at_search.yaml file
at_search: search: enable_update_events: true # default false