bambi/bambi-postgres-text-search-bundle

Symfony bundle that integrates PostgreSQL text search features.

v0.0.6 2022-09-24 10:43 UTC

This package is auto-updated.

Last update: 2024-04-24 14:01:51 UTC


README

Symfony bundle that integrates PostgreSQL full-text search functionality in Api-Platform.

This bundle has been developed for and tested with PostgreSQL 12.

Work in Progress!

This bundle is still in a very early stage of development.

Installation

composer require bambi/bambi-postgres-text-search-bundle

Basic Usage

namespace App\Entity;

class Author
{
    private string $name;
    
    ...
}

class Book
{
    private string $name;
    private string $isbn;
    private Author $author;
    
    ...
}
<services>
    <service id="app.book.text_search_match_filter"
             parent="bambi_postgres_text_search.filter.text_search_match_filter">
        
        <!-- Properties that should be searched -->
        <argument type="collection">
            <argument>name</argument>
            <argument>isbn</argument>
            <!-- You can also search fields of associated entities -->
            <argument>author.name</argument>
        </argument>
        
        <!-- Optionally you can configure the parameter name (default="ts_query") for the for the API,
         the config string (default="'english'") used by Postgres for text search and if the column you
         are searching is already vectorized (default=false). -->
        <argument key="$textSearchParameterName" type="string">postgres_text_search</argument>
        <argument key="$postgresTsConfigString" type="string">'german'</argument>
        <argument key="$preVectorized">true</argument>

        <tag name="api_platform.filter" />
    </service>
</services>

Bear in mind that the value for postgresTsConfigString is directly passed on to your Postgres Database. Don't forget Quotes if you want to pass a literal value ('german' instead of german)

<resource class="App\Entity\Book">
    <collectionOperations>
        <collectionOperation name="get">
            <attribute name="method">GET</attribute>
            ...
            <attribute name="filters">
                <attribute>app.book.text_search_match_filter</attribute>
            </attribute>
        </collectionOperation>
    </collectionOperations>
</resource>

You can access this filter via: GET /api/books?postgres_text_search=QUERY_STRING