Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function build(ScoreBuilder $scoreBuilder, Select $select, RequestQueryInterface $query, $conditionType)
 {
     /** @var $query \Magento\Framework\Search\Request\Query\Match */
     $queryValue = $this->prepareQuery($query->getValue(), $conditionType);
     $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;
     }
     $matchQuery = $this->fulltextHelper->getMatchQuery($columns, $queryValue, $this->fulltextSearchMode);
     $scoreBuilder->addCondition($matchQuery, true);
     if ($fieldIds) {
         $matchQuery = sprintf('(%s AND search_index.attribute_id IN (%s))', $matchQuery, implode(',', $fieldIds));
     }
     $select->where($matchQuery);
     return $select;
 }
Esempio n. 2
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;
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 public function build(ScoreBuilder $scoreBuilder, Select $select, RequestQueryInterface $query, $conditionType)
 {
     /** @var $query \Magento\Framework\Search\Request\Query\Match */
     $queryValue = $this->prepareQuery($query->getValue(), $conditionType);
     $fieldList = [];
     foreach ($query->getMatches() as $match) {
         $fieldList[] = $match['field'];
     }
     $resolvedFieldList = $this->resolver->resolve($fieldList);
     $queryBoost = $query->getBoost();
     $scoreBuilder->addCondition($this->fulltextHelper->getMatchQuery($resolvedFieldList, $queryValue, Fulltext::FULLTEXT_MODE_BOOLEAN), $queryBoost !== null ? $queryBoost : 1);
     $select = $this->fulltextHelper->match($select, $resolvedFieldList, $queryValue, true, Fulltext::FULLTEXT_MODE_BOOLEAN);
     return $select;
 }
Esempio n. 4
0
 /**
  * {@inheritdoc}
  */
 public function build(ScoreBuilder $scoreBuilder, Select $select, RequestQueryInterface $query, $conditionType)
 {
     /** @var $query \Magento\Framework\Search\Request\Query\Match */
     foreach ($query->getMatches() as $match) {
         $mode = Select::FULLTEXT_MODE_NATURAL;
         if ($conditionType === Bool::QUERY_CONDITION_NOT) {
             $match['value'] = '-' . $match['value'];
             $mode = Select::FULLTEXT_MODE_BOOLEAN;
         }
         $scoreBuilder->addCondition($select->getMatchQuery($match['field'], $match['value'], $mode), isset($match['boost']) ? $match['boost'] : 1);
         $select->match($match['field'], $match['value'], true, $mode);
     }
     return $select;
 }
Esempio n. 5
0
 /**
  * @param SphinxQL              $select
  * @param RequestQueryInterface $query
  * @return SphinxQL
  */
 public function build(SphinxQL $select, RequestQueryInterface $query)
 {
     /** @var \Magento\Framework\Search\Request\Query\Match $query */
     $fieldList = [];
     foreach ($query->getMatches() as $match) {
         $fieldList[] = $match['field'];
     }
     $resolvedFieldList = $this->resolver->resolve($fieldList);
     $fieldIds = [];
     $columns = [];
     /** @var \Mirasvit\SearchSphinx\Model\Adapter\Field\Field $field */
     foreach ($resolvedFieldList as $field) {
         if ($field->getType() === FieldInterface::TYPE_FULLTEXT && $field->getAttributeId()) {
             $fieldIds[] = $field->getAttributeId();
         }
         $column = $field->getColumn();
         $columns[$column] = $column;
     }
     $queryValue = $this->queryHelper->buildQuery($query->getValue());
     $matchQuery = $this->buildMatchQuery($queryValue, $select);
     $select->match($columns, new QLExpression($matchQuery));
     return $select;
 }