getMapping() public method

Search request container mapping.
public getMapping ( ) : Smile\ElasticsuiteCore\Api\Index\MappingInterface
return Smile\ElasticsuiteCore\Api\Index\MappingInterface
Esempio n. 1
0
 /**
  * Prepare filter condition from an array as used into addFieldToFilter.
  *
  * @SuppressWarnings(PHPMD.ElseExpression)
  *
  * @param ContainerConfigurationInterface $containerConfig Search request container configuration.
  * @param array                           $filters         Filters to be built.
  *
  * @return QueryInterface
  */
 public function create(ContainerConfigurationInterface $containerConfig, array $filters)
 {
     $queries = [];
     $mapping = $containerConfig->getMapping();
     foreach ($filters as $fieldName => $condition) {
         if ($condition instanceof QueryInterface) {
             $queries[] = $condition;
         } else {
             $mappingField = $mapping->getField($fieldName);
             $queries[] = $this->prepareFieldCondition($mappingField, $condition);
         }
     }
     $filterQuery = current($queries);
     if (count($queries) > 1) {
         $filterQuery = $this->queryFactory->create(QueryInterface::TYPE_BOOL, ['must' => $queries]);
     }
     return $filterQuery;
 }
 /**
  * Build the list of buckets from the mapping.
  *
  * @param ContainerConfigurationInterface $containerConfiguration Search request configuration
  * @param array                           $aggregations           Facet definitions.
  * @param array                           $filters                Facet filters to be added to buckets.
  *
  * @return BucketInterface[]
  */
 public function buildAggregations(ContainerConfigurationInterface $containerConfiguration, array $aggregations, array $filters)
 {
     $buckets = [];
     $mapping = $containerConfiguration->getMapping();
     foreach ($aggregations as $fieldName => $aggregationParams) {
         $bucketType = $aggregationParams['type'];
         try {
             $field = $mapping->getField($fieldName);
             $bucketParams = $this->getBucketParams($field, $aggregationParams, $filters);
             if (isset($bucketParams['filter'])) {
                 $bucketParams['filter'] = $this->createFilter($containerConfiguration, $bucketParams['filter']);
             }
             if (isset($bucketParams['nestedFilter'])) {
                 $nestedFilter = $this->createFilter($containerConfiguration, $bucketParams['nestedFilter']);
                 $bucketParams['nestedFilter'] = $nestedFilter->getQuery();
             }
         } catch (\Exception $e) {
             $bucketParams = $aggregationParams['config'];
         }
         $buckets[] = $this->aggregationFactory->create($bucketType, $bucketParams);
     }
     return $buckets;
 }
Esempio n. 3
0
 /**
  * Build sort orders from array of sort orders definition.
  *
  * @param ContainerConfigurationInterface $containerConfig Request configuration.
  * @param array                           $orders          Sort orders definitions.
  *
  * @return SortOrderInterface[]
  */
 public function buildSordOrders(ContainerConfigurationInterface $containerConfig, array $orders)
 {
     $sortOrders = [];
     $mapping = $containerConfig->getMapping();
     $orders = $this->addDefaultSortOrders($orders, $mapping);
     foreach ($orders as $fieldName => $sortOrderParams) {
         $factory = $this->standardOrderFactory;
         try {
             $sortField = $mapping->getField($fieldName);
             $sortOrderParams = $this->getSortOrderParams($sortField, $sortOrderParams);
             if (isset($sortOrderParams['nestedPath'])) {
                 $factory = $this->nestedOrderFactory;
             }
             if (isset($sortOrderParams['nestedFilter'])) {
                 $nestedFilter = $this->queryBuilder->create($containerConfig, $sortOrderParams['nestedFilter']);
                 $sortOrderParams['nestedFilter'] = $nestedFilter->getQuery();
             }
         } catch (\LogicException $e) {
             $sortOrderParams['field'] = $fieldName;
         }
         $sortOrders[] = $factory->create($sortOrderParams);
     }
     return $sortOrders;
 }
Esempio n. 4
0
 /**
  * Build an array of weighted fields to be searched with the ability to apply a filter callback method and a default field.
  *
  * @param ContainerConfigurationInterface $containerConfig Search request container config.
  * @param string                          $analyzer        Target analyzer.
  * @param callable                        $filterCallback  Field filter callback.
  * @param string|null                     $defaultField    Default search field.
  * @param integer                         $boost           Additional boost applied to the fields (multiplicative).
  *
  * @return array
  */
 private function getWeightedFields(ContainerConfigurationInterface $containerConfig, $analyzer = FieldInterface::ANALYZER_STANDARD, $filterCallback = null, $defaultField = null, $boost = 1)
 {
     $weightedFields = [];
     if ($defaultField !== null) {
         if ($analyzer != FieldInterface::ANALYZER_STANDARD) {
             $defaultField = sprintf("%s.%s", $defaultField, $analyzer);
         }
         $weightedFields[$defaultField] = 1;
     }
     $fields = $containerConfig->getMapping()->getFields();
     if ($filterCallback) {
         $fields = array_filter($fields, $filterCallback);
     }
     foreach ($fields as $field) {
         $mappingProperty = $field->getMappingProperty($analyzer);
         if ($mappingProperty && ($defaultField === null || $field->getSearchWeight() != 1)) {
             $weightedFields[$mappingProperty] = $field->getSearchWeight() * $boost;
         }
     }
     return $weightedFields;
 }