Пример #1
0
 /**
  * {@inheritdoc}
  */
 public function build(ScoreBuilder $scoreBuilder, Select $select, RequestQueryInterface $query, $conditionType)
 {
     /** @var $query \Magento\Framework\Search\Request\Query\Match */
     $fieldList = [];
     foreach ($query->getMatches() as $match) {
         $fieldList[] = $match['field'];
     }
     $resolvedFieldList = $this->resolver->resolve($fieldList);
     $fieldIds = [];
     $columns = [];
     foreach ($resolvedFieldList as $field) {
         if ($field->getType() === FieldInterface::TYPE_FULLTEXT && $field->getAttributeId()) {
             $fieldIds[] = $field->getAttributeId();
         }
         $column = $field->getColumn();
         $columns[$column] = $column;
     }
     $exactMatchQuery = $this->getExactMatchQuery($columns, $query->getValue());
     $scoreQuery = $this->getScoreQuery($columns, $query->getValue());
     $scoreBuilder->addCondition(new \Zend_Db_Expr($scoreQuery), true);
     if ($query->getValue() != $this->queryHelper->singularize($query->getValue())) {
         $scoreQuery = $this->getScoreQuery($columns, $this->queryHelper->singularize($query->getValue()));
         $scoreBuilder->addCondition(new \Zend_Db_Expr($scoreQuery), true);
     }
     if ($fieldIds) {
         $select->where(sprintf('search_index.attribute_id IN (%s)', implode(',', $fieldIds)));
     }
     $select->having(new \Zend_Db_Expr($exactMatchQuery))->group('entity_id');
     return $select;
 }