private function basicQueryGenerator($section)
{
// get section params contains section search fields and aggs
$sectionParams = $this->getSearchParamsBag()[$section];
// calculate from field from page
$from = ($this->getPage() - 1) * $this->getSearchSize();
// get size field
$size = $this->getSearchSize();
// set from field to query array
$queryArray['from'] = $from;
// set size field to query array
$queryArray['size'] = $size;
// foreach section field add query to native query array
foreach ($sectionParams['fields'] as $field) {
$searchField = $field;
// default boost is 1
$boost = 1;
// if $field is array 0 is field and 1 is boost int
if (is_array($field)) {
$searchField = $field[0];
$boost = (int) $field[1];
}
// if query is empty find all section results
if (empty($this->query)) {
$queryArray['query']['filtered']['query']['bool']['should'][] = ['match_all' => []];
} else {
/**
* find query via query_string type query
* look for more
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html
*/
$queryArray['query']['filtered']['query']['bool']['should'][] = ['query_string' => ['query' => $section . '.' . $searchField . ':' . $this->query, 'boost' => $boost]];
}
}
// if requested agg bag is not empty
if (!empty($this->requestAggsBag)) {
// for each bag aggregation
foreach ($this->requestAggsBag as $requestAggKey => $requestAgg) {
// if requested agg. is not our specified agg. continue then
if (!in_array($requestAggKey, $sectionParams['aggs'])) {
continue;
}
/**
* add filter for each spesified agg.
* look for more
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-filtered-query.html
*/
foreach ($requestAgg as $aggValue) {
$queryArray['query']['filtered']['filter']['bool']['must'][] = ['term' => [$section . '.' . $requestAggKey => $aggValue]];
}
}
}
// inject all aggs. to native query with specified aggs
if ($this->setupAggs) {
foreach ($sectionParams['aggs'] as $agg) {
$queryArray['aggs'][$agg] = ['terms' => ['field' => $section . '.' . $agg]];
}
}
return $queryArray;
}