Skip to content

Conversation

@alexsegura
Copy link
Contributor

@alexsegura alexsegura commented Nov 24, 2022

Hi,

I'm running multiple instances of the same webapp against a unique Typesense server, and I'm using namespaces/prefixes for collection names. For example let's say I have a products collection, there would be collections prefixed by the app name (app_A_products, app_B_products, etc). Also, on my dev environment, I have a specific collection for tests (i.e app_products_test).

All of this is made dynamic by using env vars.

Of course, I would like to use the "generic" name (i.e products) inside my code, while having TypesenseBundle classes target the expected collection.


I noticed there is a collection_name parameter which seems designed for this, but is unused. So I tried to make it work.
Not sure what I did is 100% correct as I'm not an expert in Symfony dependency injection.

As a result, with the following configuration:

parameters:
    env(APP_NAME): "app_A"
    typesense_products_collection_name: "%env(APP_NAME)%_products"

acseo_typesense:
    collections:
        products:
            collection_name: '%typesense_products_collection_name%'
            entity: 'App\Entity\Product'
            fields:
                id:
                    name: id
                    type: primary
                sortable_id:
                    entity_attribute: id
                    name: sortable_id
                    type: int32
                name:
                    name: name
                    type: string
            default_sorting_field: sortable_id
  • When calling $collectionManager->createCollection('products') (for example), it actually creates the app_A_products collection
  • I have a service typesense.finder.products which actually targets the collection app_A_products

Related to #22

@npotier
Copy link
Member

npotier commented Dec 20, 2022

Closed in favor of #65

@npotier npotier closed this Dec 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants