Entity
    Preparing search index...

    Interface TrigramSearchSpecification<TFields, TSelectedFields>

    Search specification for similarity search using PostgreSQL trigram similarity.

    interface TrigramSearchSpecification<
        TFields extends Record<string, any>,
        TSelectedFields extends keyof TFields = keyof TFields,
    > {
        extraOrderByFields?: readonly EntityLoaderSearchFieldSpecification<
            TFields,
            TSelectedFields,
        >[];
        fields: readonly EntityLoaderSearchFieldSpecification<
            TFields,
            TSelectedFields,
        >[];
        strategy: TRIGRAM_SEARCH;
        term: string;
        threshold: number;
    }

    Type Parameters

    • TFields extends Record<string, any>
    • TSelectedFields extends keyof TFields = keyof TFields

    Hierarchy (View Summary)

    Index
    extraOrderByFields?: readonly EntityLoaderSearchFieldSpecification<
        TFields,
        TSelectedFields,
    >[]

    Optional additional fields to order by after similarity score and before ID for tie-breaking. These fields are independent of search fields and can be used to provide meaningful ordering when multiple results have the same similarity score.

    The fields to search within.

    strategy: TRIGRAM_SEARCH

    Similarity search using PostgreSQL trigram similarity. Results are ordered by exact match priority, then by similarity score, then by specified extra order by fields if provided, then by ID for tie-breaking and stable pagination. Note that trigram similarity search can be significantly slower than ILIKE search, especially on large datasets without appropriate indexes, and results may not be as relevant as more advanced full-text search solutions. It is recommended to use this strategy only when ILIKE search does not meet the application's needs and to ensure appropriate database indexing for performance.

    term: string

    The search term to search for. Must be a non-empty string.

    threshold: number

    Similarity threshold for trigram matching. Must be between 0 and 1, where:

    • 0 matches everything
    • 1 requires exact match

    Recommended threshold values:

    • 0.3: Loose matching, allows more variation (default PostgreSQL similarity threshold)
    • 0.4-0.5: Moderate matching, good balance for most use cases
    • 0.6+: Strict matching, requires high similarity