質問編集履歴

1

カスタムエンジンのsearchコードの追加

2019/06/17 08:59

投稿

zushi0905
zushi0905

スコア683

test CHANGED
File without changes
test CHANGED
@@ -141,3 +141,125 @@
141
141
 
142
142
 
143
143
  curlでは正常に検索も行えていますが、laravelを使って表示が上手くいきません。どこが問題かも検討が付かず困っています。ご教授よろしくお願い致します。
144
+
145
+
146
+
147
+ ### 追記
148
+
149
+ ** ElasticSearcEngin **
150
+
151
+ ```
152
+
153
+ /**
154
+
155
+ * Perform the given search on the engine.
156
+
157
+ *
158
+
159
+ * @param \Laravel\Scout\Builder $builder
160
+
161
+ * @return mixed
162
+
163
+ */
164
+
165
+ public function search(Builder $builder)
166
+
167
+ {
168
+
169
+ return $this->performSearch($builder, array_filter([
170
+
171
+ 'filters' => $this->filters($builder),
172
+
173
+ 'limit' => $builder->limit,
174
+
175
+ ]));
176
+
177
+ }
178
+
179
+
180
+
181
+ /**
182
+
183
+ * @param \Laravel\Scout\Builder $builder
184
+
185
+ * @param array $options
186
+
187
+ * @return array|mixed
188
+
189
+ */
190
+
191
+ protected function performSearch(Builder $builder, $options = [])
192
+
193
+ {
194
+
195
+ $params = [
196
+
197
+ 'index' => $this->index,
198
+
199
+ 'type' => $builder->index ?: $builder->model->searchableAs(),
200
+
201
+ 'body' => [
202
+
203
+ 'query' => [
204
+
205
+ 'bool' => [
206
+
207
+ 'must' => [
208
+
209
+ 'term' => [
210
+
211
+ 'title' => "{$builder->query}",
212
+
213
+ ]
214
+
215
+ ],
216
+
217
+ ],
218
+
219
+ ],
220
+
221
+ ]
222
+
223
+ ];
224
+
225
+
226
+
227
+ if ($sort = $this->sort($builder)) {
228
+
229
+ $params['body']['sort'] = $sort;
230
+
231
+ }
232
+
233
+
234
+
235
+ if (isset($options['filters']) && count($options['filters'])) {
236
+
237
+ $params['body']['query']['bool']['filter'] = $options['filters'];
238
+
239
+ }
240
+
241
+
242
+
243
+ if ($builder->callback) {
244
+
245
+ return call_user_func(
246
+
247
+ $builder->callback,
248
+
249
+ $this->elastic,
250
+
251
+ $builder->query,
252
+
253
+ $params
254
+
255
+ );
256
+
257
+ }
258
+
259
+
260
+
261
+ return $this->elastic->search($params);
262
+
263
+ }
264
+
265
+ ```