pmatseykanets / laravel-scout-postgres

PostgreSQL Full Text Search Engine for Laravel Scout
MIT License
159 stars 36 forks source link

Making querying method configurable #20

Closed pmatseykanets closed 6 years ago

pmatseykanets commented 6 years ago

This long coming PR should hopefully address #10 and #14

// plainto_tsquery()
$results = App\Post::search('cat rat')->usingPlainQuery()->get()

// plainto_tsquery()
$results = App\Post::search('cat rat')->usingPhraseQuery()->get()

// to_tsquery()
$results = App\Post::search('fat & (cat | rat)')->usingTsQuery()->get()

// DYI using a callback
use ScoutEngines\Postgres\TsQuery\ToTsQuery;

$results = App\Post::search('fat & (cat | rat)', function ($builder, $config) {
    return new ToTsQuery($builder->query, $config);
})->get();

It's possible to configure the default querying method in scout.php

    'pgsql' => [
        'connection' => 'pgsql',
        'maintain_index' => true,
        'search_config' => 'english',
        // Possible values are plainquery|phrasequery|tsquery. Default - plainquery
        'search_using' => 'tsquery',
    ],
tortuetorche commented 6 years ago

@pmatseykanets I'm going to test this pull request. Thank you for this new feature!

tortuetorche commented 6 years ago

If I understand well this pull request, it only allows to customize the text search part of the SQL query, but not the entire query, isn't it?

pmatseykanets commented 6 years ago

@tortuetorche Yes, in its current form it only allows you to pick the function that produces the tsquery, but I should've been clearer in my comment to #19 if we pass $query and $bindings into the closure it's becomes possible to customize (to some extent) the overall query.