Exemplo n.º 1
0
 /**
  * adds current attribute facet condition to product collection
  *
  * @return Hackathon_ElasticgentoCore_Model_Catalog_Layer_Filter_Attribute
  */
 public function addFacetToCollection()
 {
     $facet = new \Elastica\Facet\Terms($this->getAttributeModel()->getAttributeCode());
     $facet->setField($this->getAttributeModel()->getAttributeCode());
     $facet->setSize(10);
     $this->getLayer()->getProductCollection()->addFacet($facet);
     return $this;
 }
Exemplo n.º 2
0
 /**
  *
  * @see FacetInterface::getFacet
  */
 public function getFacet($fieldName, \Elastica\Filter\AbstractFilter $mainFilter)
 {
     $rawFieldName = $this->getRawFieldName($fieldName);
     $mainFilter = $this->prepareMainFilter($mainFilter, $rawFieldName);
     $facet = new \Elastica\Facet\Terms($fieldName);
     $facet->setField($rawFieldName);
     $facet->setSize($this->options['size']);
     $facet->setFilter($mainFilter);
     return $facet;
 }
Exemplo n.º 3
0
 /**
  * Adds facet condition to product collection.
  *
  * @return Hackathon_ElasticgentoCore_Model_Catalog_Layer_Filter_Category
  * @todo add filter for current category childen
  */
 public function addFacetToCollection()
 {
     /** @var $category Mage_Catalog_Model_Category */
     #$category = $this->getCategory();
     #$childrenCategories = $category->getChildrenCategories();
     /** @todo refactor */
     #$useFlat = (bool)Mage::getStoreConfig('catalog/frontend/flat_catalog_category');
     #$categories = ($useFlat) ? array_keys($childrenCategories) : array_keys($childrenCategories->toArray());
     $facet = new \Elastica\Facet\Terms('categories');
     $facet->setField('categories');
     $facet->setSize(10);
     $this->getLayer()->getProductCollection()->addFacet($facet);
     return $this;
 }
Exemplo n.º 4
0
 /**
  * get attribute sets for current collection
  *
  * @return mixed
  */
 public function getSetIds()
 {
     if (false == $this->isLoaded()) {
         $tmpSize = $this->getPageSize();
         $this->setPageSize(0);
         $facet = new \Elastica\Facet\Terms('attribute_set_id');
         $facet->setField('attribute_set_id');
         $facet->setSize(10);
         $this->addFacet($facet);
         $this->load();
         $this->removeFacet($facet->getName());
         $this->setPageSize($tmpSize);
         $this->_setIsLoaded(false);
     }
     if (0 == count($this->_setIds)) {
         foreach ($this->_responseFacets['attribute_set_id']['terms'] as $term) {
             $this->_setIds[$term['term']] = $term['term'];
         }
     }
     return $this->_setIds;
 }
 public function search($queryString, $opts, $highlight)
 {
     $query = new \Elastica\Query();
     list($searchQuery, $highlights) = $this->parseQueryString($queryString, $opts);
     $query->setQuery($searchQuery);
     $language = new \Elastica\Facet\Terms('language');
     $language->setField('language');
     $language->setSize(500);
     $query->addFacet($language);
     $group = new \Elastica\Facet\Terms('group');
     $group->setField('group');
     // Would like to prioritize the top level groups and not show subgroups
     // if the top group has only few hits, but that doesn't seem to be possile.
     $group->setSize(500);
     $query->addFacet($group);
     $query->setSize($opts['limit']);
     $query->setFrom($opts['offset']);
     // BoolAnd filters are executed in sequence per document. Bool filters with
     // multiple must clauses are executed by converting each filter into a bit
     // field then anding them together. The latter is normally faster if either
     // of the subfilters are reused. May not make a difference in this context.
     $filters = new \Elastica\Filter\Bool();
     $language = $opts['language'];
     if ($language !== '') {
         $languageFilter = new \Elastica\Filter\Term();
         $languageFilter->setTerm('language', $language);
         $filters->addMust($languageFilter);
     }
     $group = $opts['group'];
     if ($group !== '') {
         $groupFilter = new \Elastica\Filter\Term();
         $groupFilter->setTerm('group', $group);
         $filters->addMust($groupFilter);
     }
     // Check that we have at least one filter to avoid invalid query errors.
     if ($language !== '' || $group !== '') {
         $query->setPostFilter($filters);
     }
     list($pre, $post) = $highlight;
     $query->setHighlight(array('pre_tags' => array($pre), 'post_tags' => array($post), 'fields' => $highlights));
     try {
         return $this->getType()->getIndex()->search($query);
     } catch (\Elastica\Exception\ExceptionInterface $e) {
         throw new TTMServerException($e->getMessage());
     }
 }