You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+118-1Lines changed: 118 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -54,7 +54,124 @@ Specify the database connection that should be used to access indexed documents
54
54
55
55
## Configuration
56
56
57
-
TBD
57
+
### Configuring PostgreSQL
58
+
59
+
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.
60
+
61
+
To check the current value
62
+
63
+
```sql
64
+
SHOW default_text_search_config;
65
+
66
+
```
67
+
68
+
69
+
70
+
71
+
### Prepare the schema
72
+
73
+
By default the engine expects that parsed documents (model data) are stored in the same table as the Model in a column `searchable` of type `tsvector`. You'd need to create this column and an index in your schema. You can choose between `GIN` and `GiST` indexes in PostgreSQL.
74
+
75
+
```php
76
+
class CreatePostsTable extends Migration
77
+
{
78
+
public function up()
79
+
{
80
+
Schema::create('posts', function (Blueprint $table) {
You may fine tune the engine behavior for a particular Model by implemeting `searchableOptions()` in your Model.
121
+
122
+
```php
123
+
class Post extends Model
124
+
{
125
+
use Searchable;
126
+
127
+
...
128
+
public function searchableOptions()
129
+
{
130
+
return [
131
+
// You may wish to change the default name of the column
132
+
// that holds parsed documents
133
+
'column' => 'indexable',
134
+
// You may want to store the index outside of the Model table
135
+
// In that case let the engine know by setting this parameter to true.
136
+
'external' => true,
137
+
// If you don't want scout to maintain the index for you
138
+
// You can turn it off either for a Model or globally
139
+
'maintain_index' => true,
140
+
// Ranking groups that will be assigned to fields
141
+
// when document is being parsed.
142
+
// Available groups: A, B, C and D.
143
+
'rank' => [
144
+
'fields' => [
145
+
'title' => 'A',
146
+
'content' => 'B',
147
+
'author' => 'D',
148
+
'tags' => 'C',
149
+
],
150
+
// Ranking weights for searches.
151
+
// [D-weight, C-weight, B-weight, A-weight].
152
+
// Default [0.1, 0.2, 0.4, 1.0].
153
+
'weights' => [0.1, 0.2, 0.4, 1.0],
154
+
// Ranking function [ts_rank | ts_rank_cd]. Default ts_rank.
155
+
'function' => 'ts_rank_cd',
156
+
// Normalization index. Default 0.
157
+
'normalization' => 32,
158
+
],
159
+
];
160
+
}
161
+
}
162
+
...
163
+
```
164
+
165
+
If you decide to keep your Model's index outside of the Model's table you can let engine know that you want to push additional fields in the index table that you can than use to filter the result set by using `where()` with the Scout `Builder`. In this case you'd need to implement `searchableAdditionalArray()` on your Model. Of course the schema for the external table should include these additional columns.
0 commit comments