/** * Retrieve base params for a sort order field. * * @param FieldInterface $field Sort order field. * @param array $sortOrderParams Sort order params. * * @return array */ private function getSortOrderParams(FieldInterface $field, array $sortOrderParams) { $sortOrderParams['field'] = $field->getMappingProperty(FieldInterface::ANALYZER_SORTABLE); if ($field->isNested() && !isset($sortOrderParams['nestedPath'])) { $sortOrderParams['nestedPath'] = $field->getNestedPath(); } return $sortOrderParams; }
/** * Preprocess aggregations params before they are used into the aggregation factory. * * @param FieldInterface $field Bucket field. * @param array $aggregationParams Aggregation params. * @param array $filters Filter applied to the search request. * * @return array */ private function getBucketParams(FieldInterface $field, array $aggregationParams, array $filters) { $bucketField = $field->getMappingProperty(FieldInterface::ANALYZER_UNTOUCHED); if ($bucketField === null) { throw new \LogicException("Unable to init the filter field for {$field->getName()}"); } $bucketParams = ['field' => $bucketField, 'name' => $field->getName(), 'metrics' => [], 'filter' => array_diff_key($filters, [$field->getName() => true])]; $bucketParams += $aggregationParams['config']; if (empty($bucketParams['filter'])) { unset($bucketParams['filter']); } if ($field->isNested() && !isset($bucketParams['nestedPath'])) { $bucketParams['nestedPath'] = $field->getNestedPath(); } elseif ($field->isNested() === false && isset($bucketParams['nestedPath'])) { unset($bucketParams['nestedPath']); } return $bucketParams; }
/** * Transform the condition into a search request query object. * * @param FieldInterface $field Filter field. * @param array|string $condition Filter condition. * * @return QueryInterface */ private function prepareFieldCondition(FieldInterface $field, $condition) { $queryType = QueryInterface::TYPE_TERMS; $condition = $this->prepareCondition($condition); if (count(array_intersect(['gt', 'gte', 'lt', 'lte'], array_keys($condition))) >= 1) { $queryType = QueryInterface::TYPE_RANGE; $condition = ['bounds' => $condition]; } $condition['field'] = $field->getMappingProperty(FieldInterface::ANALYZER_UNTOUCHED); if ($condition['field'] === null) { $condition['field'] = $field->getMappingProperty(FieldInterface::ANALYZER_STANDARD); } if (in_array('queryText', array_keys($condition))) { $queryType = QueryInterface::TYPE_MATCH; $condition['minimumShouldMatch'] = '100%'; } $query = $this->queryFactory->create($queryType, $condition); if ($field->isNested()) { $queryParams = ['path' => $field->getNestedPath(), 'query' => $query]; $query = $this->queryFactory->create(QueryInterface::TYPE_NESTED, $queryParams); } return $query; }