Download the PHP package nramos/search-indexer without Composer
On this page you can find all versions of the php package nramos/search-indexer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nramos/search-indexer
More information about nramos/search-indexer
Files in nramos/search-indexer
Package search-indexer
Short Description A Doctrine entity indexer supporting Meilisearch and extensible for other indexing systems.
License MIT
Homepage https://github.com/n-ramos/search-indexer
Informations about the package search-indexer
This documentation is available in:
🇬🇧 English
🇫🇷 Français
🇫🇷 Français
Le package nramos/search-indexer
permet d'indexer des entités Doctrine sur différents systèmes d'indexation via des annotations. Actuellement, un adaptateur pour Meilisearch est disponible, mais la structure permet d'ajouter d'autres systèmes d'indexation à l'avenir.
Installation
Installez le package via Composer :
Configuration
Déclarer le service dans services.yaml:
Exemple pour Meilisearch:
Déclarer l'index sur une entité
Utilisez l'annotation #[SearchIndex]
sur une classe pour définir un index. Par exemple :
- indexName : le nom de l'index sur le système d'indexation.
- autoIndex : définit si les entités doivent être automatiquement indexées lors des insertions et des mises à jour. Si false, vous devrez gérer l'indexation manuellement.
Configurer les propriétés à indexer
Utilisez l'annotation
#[SearchProperty]
sur les propriétés de l'entité pour définir comment celles-ci seront indexées :
Il faut obligatoirement ajouter une clé primaire à l'indexer :
Configurer les propriétés à indexer
- propertyName : nom de la propriété à indexer.
- filterable : si la propriété peut être utilisée dans les filtres de recherche.
- sortable : si la propriété peut être utilisée pour trier les résultats.
- searchable : si la propriété peut être utilisée dans la recherche textuelle. -relationProperties : spécifie les clés à extraire dans le cas d'une relation (par ex. ManyToMany).
Gérer les relations
Lorsque vous avez des relations comme ManyToMany, vous pouvez spécifier des relationProperties pour indexer des valeurs provenant de la relation. Par exemple :
Dans cet exemple, la propriété name des entités liées à Heating sera indexée sous le nom heatings
.
Désactiver l'auto-indexation
Si vous ne souhaitez pas utiliser l'indexation automatique fournie par le package, vous pouvez désactiver l'auto-indexation en définissant autoIndex: false
dans l'annotation #[SearchIndex]
et en créant un subscriber personnalisé pour gérer l'indexation.
Utilisation des filtres de recherche
Le package propose une interface SearchFilterInterface pour faciliter la création de requêtes complexes. Un adaptateur pour Meilisearch est disponible par défaut. Voici un exemple d'utilisation avec Meilisearch :
Exécution de la recherche
Pour exécuter la recherche, vous devez implémenter l'interface SearchClientInterface. Un client Meilisearch est fourni par le package sous la classe MeilisearchClient
. Voici un exemple :
Exemple d'entité
Voici un exemple d'entité avec les annotations pour l'indexation :
Aller plus loin
Créer un subscriber personnalisé
Pour gérer l'indexation manuellement, vous pouvez créer un subscriber personnalisé pour écouter les événements Doctrine et appeler l'indexation manuellement. Voici un exemple implémenté globalement :
Effectuer une multi recherche
Pour effectuer une recherche multi-index, vous pouvez utiliser la méthode searchMulti
du client. Voici un exemple :
Créer un adaptateur pour un autre système d'indexation
Vous pouvez vous baser sur la class MeilisearchClient. Veillez à bien changer le services dans votre fichier services.yaml:
Conclusion
Le package nramos/search-indexer vous permet d'indexer vos entités de manière flexible et automatique via des annotations. Il supporte actuellement Meilisearch, mais peut être étendu pour d'autres systèmes d'indexation.
🇬🇧 English
The nramos/search-indexer
package allows indexing Doctrine entities on different indexing systems via annotations. Currently, an adapter for Meilisearch is available, but the structure allows adding other indexing systems in the future.
Installation
Install the package via Composer:
Configuration
Declare the service in services.yaml
:
Example for Meilisearch:
Declare the index on an entity
Use the #[SearchIndex]
annotation on a class to define an index. For example:
- indexName: The name of the index in the indexing system.
- autoIndex: Defines whether entities should be automatically indexed on inserts and updates. If false, you will need to manage indexing manually.
Configure the properties to index
Use the #[SearchProperty]
annotation on entity properties to define how they will be indexed:
You must add a primary key to the index:
Configure indexed properties
- propertyName: Name of the property to index.
- filterable: Whether the property can be used in search filters.
- sortable: Whether the property can be used to sort results.
- searchable: Whether the property can be used in text search.
- relationProperties: Specifies keys to extract in case of a relation (e.g., ManyToMany).
Handling relations
For relations like ManyToMany, you can specify relationProperties
to index values from the related entity. Example:
In this example, the name
property of related Heating
entities will be indexed under heatings
.
Disable auto-indexing
If you don't want to use the package's automatic indexing, you can disable it by setting autoIndex: false
in the #[SearchIndex]
annotation and creating a custom subscriber to handle indexing manually.
Using search filters
The package provides a SearchFilterInterface
to simplify creating complex queries. A Meilisearch adapter is available by default. Here is an example usage with Meilisearch:
Executing a search
To execute a search, you need to implement the SearchClientInterface
. A Meilisearch client is provided in the package under MeilisearchClient
. Example:
Example entity
Here is an example entity with indexing annotations:
Going further
Create a custom subscriber
To manually manage indexing, create a custom subscriber to listen to Doctrine events and trigger indexing manually. Example:
Perform multi-index search
Use the searchMulti
method to search across multiple indexes:
Create an adapter for another indexing system
Use the MeilisearchClient
class as a reference and update services.yaml
:
Conclusion
The nramos/search-indexer
package allows flexible and automatic entity indexing via annotations. It currently supports Meilisearch but can be extended to other indexing systems.
All versions of search-indexer with dependencies
symfony/dependency-injection Version ^6.2|^7.1
symfony/config Version ^6.2|^7.1
doctrine/orm Version ^3.2
doctrine/doctrine-bundle Version ^2.0
symfony/http-client Version ^6.2|^7.1
symfony/http-kernel Version ^6.2|^7.1
symfony/framework-bundle Version ^6.2|^7.1
symfony/dotenv Version ^6.2|^7.1
symfony/monolog-bundle Version ^3.10