Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making querying method configurable #20

Merged
merged 3 commits into from
Mar 2, 2018

Conversation

pmatseykanets
Copy link
Owner

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
Copy link
Contributor

tortuetorche commented Mar 1, 2018

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

@tortuetorche
Copy link
Contributor

tortuetorche commented Mar 1, 2018

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
Copy link
Owner Author

@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.

@pmatseykanets pmatseykanets merged commit 4c79e5c into master Mar 2, 2018
@pmatseykanets pmatseykanets deleted the configurable-querying-method branch September 16, 2019 05:32
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.

None yet

2 participants