Skip to content

Add “none” Full-Text Mode (raw to_tsquery) to allow prefix operators (:*) #121

@opheus2

Description

@opheus2

Feature Request: Add mode = none to whereFullText() for raw to_tsquery

Hi! 👋

I’d like to propose adding support for a “none” mode to the full-text query grammar so that whereFullText() can optionally use raw to_tsquery instead of plainto_tsquery, phraseto_tsquery, or websearch_to_tsquery.

Why this is needed

PostgreSQL’s prefix search (:*) is not recognized by:

  • plainto_tsquery
  • phraseto_tsquery
  • websearch_to_tsquery

These functions all treat characters like : and * as literal text, not operators.
This means you cannot perform a prefix search like:

to_tsquery('english', 'Ent:*')

when using the current whereFullText() implementation.

Prefix searching is an extremely common use case (autocomplete, partial-name search, etc.), and the only way to get it is through raw to_tsquery.

Proposed Enhancement

In GrammarFullText@whereFullText, allow:

['mode' => 'none']

to select:

$mode = 'to_tsquery';

Example change:

if (($where['options']['mode'] ?? []) === 'none') {
    $mode = 'to_tsquery';
}

Example Usage

$q->whereFullText('full_name', "{$prefix}:*", [
    'mode' => 'none',
]);

Which would compile to:

to_tsvector('english', full_name) @@ to_tsquery('english', 'Ent:*')

This gives developers a clean and safe way to use native tsquery syntax—especially prefix operators—without manually writing raw SQL.

Willing to contribute

I’m happy to open a PR implementing this addition if you think it fits the project direction.

Thanks for maintaining this excellent package!


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions