Skip to content

Commit 81b97a4

Browse files
committed
make the search config configurable
1 parent 1755360 commit 81b97a4

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
All notable changes to `pmatseykanets/laravel-hipchat-slash` will be documented in this file
44

55
## [Unreleased]
6+
### Added
7+
- Configurable search config
68

79
## [0.3.0](https://github.com/pmatseykanets/laravel-scout-postgres/releases/tag/v0.3.0) - 2017-01-04
810
### Changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ Specify the database connection that should be used to access indexed documents
5858
// You may want to update index documents directly in PostgreSQL (i.e. via triggers).
5959
// In this case you can set this value to false.
6060
'maintain_index' => true,
61+
// You can override the default text search configuration. Null uses the default.
62+
'search_configuration' => null,
6163
],
6264
...
6365
```
@@ -66,7 +68,7 @@ Specify the database connection that should be used to access indexed documents
6668

6769
### Configuring PostgreSQL
6870

69-
Make sure that an appropriate [default text search configuration](https://www.postgresql.org/docs/9.5/static/runtime-config-client.html#GUC-DEFAULT-TEXT-SEARCH-CONFIG) is set globbaly (in `postgresql.conf`), for a particular database (`ALTER DATABASE ... SET ...`) or alternatively set `default_text_search_config` in each session.
71+
Make sure that an appropriate [default text search configuration](https://www.postgresql.org/docs/9.5/static/runtime-config-client.html#GUC-DEFAULT-TEXT-SEARCH-CONFIG) is set globbaly (in `postgresql.conf`), for a particular database (`ALTER DATABASE ... SET default_text_search_config TO ...`) or alternatively set `default_text_search_config` in each session.
7072

7173
To check the current value
7274

src/PostgresEngine.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,16 @@ protected function toVector(Model $model)
109109
return $value === null ? '' : $value;
110110
});
111111

112+
$searchConfig = config('scout.pgsql.search_configuration');
113+
114+
$searchConfigString = '';
115+
if ($searchConfig !== null) {
116+
$searchConfigString = "'" . $searchConfig . "',";
117+
}
118+
112119
$select = $fields->keys()
113120
->map(function ($key) use ($model) {
114-
$vector = 'to_tsvector(?)';
121+
$vector = "to_tsvector($searchConfigString ?)";
115122
if ($label = $this->rankFieldWeightLabel($model, $key)) {
116123
$vector = "setweight($vector, '$label')";
117124
}
@@ -207,10 +214,17 @@ protected function performSearch(Builder $builder, $perPage = 0, $page = 1)
207214

208215
$indexColumn = $this->getIndexColumn($builder->model);
209216

217+
$searchConfig = config('scout.pgsql.search_configuration');
218+
219+
$searchConfigString = '';
220+
if ($searchConfig !== null) {
221+
$searchConfigString = "'" . $searchConfig . "',";
222+
}
223+
210224
// Build the query
211225
$query = $this->database
212226
->table($builder->index ?: $builder->model->searchableAs())
213-
->crossJoin($this->database->raw('plainto_tsquery(?) query'))
227+
->crossJoin($this->database->raw("plainto_tsquery($searchConfigString ?) query"))
214228
->select($builder->model->getKeyName())
215229
->selectRaw("{$this->rankingExpression($builder->model, $indexColumn)} AS rank")
216230
->selectRaw('COUNT(*) OVER () AS total_count')

0 commit comments

Comments
 (0)