-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.php
35 lines (28 loc) · 984 Bytes
/
search.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
require 'vendor/autoload.php';
$searchAdapterProvider = new \Adapter\SearchAdapterProvider(
new \Adapter\ElasticSearchAdapter(\Builder\ElasticSearchBuilder::connect())
);
$productService = new \Service\ProductService($searchAdapterProvider);
$search = (isset($_POST['search'])) ? $_POST['search'] : "";
$field = (isset($_POST['field'])) ? $_POST['field'] : "";
$fields = [ "isbn^1", "categories^3", "authors^5", "title^7" ];
if (!empty($field)) {
$fields = [$field];
}
$query = [
'index' => 'book_index',
'body' => [
'from' => 0,
'size' => 10,
'query' => [
'multi_match' => [
'query' => $search,
"minimum_should_match" => '50%', #ref: 50% https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-minimum-should-match.html
"fields" => $fields
],
]
]
];
$search = $productService->searchProduct($query);
echo json_encode($search);