2016-03-01 79 views
0

我無法將構面添加到查詢中。我嘗試如何向查詢添加構面(solr)

$query = new Query; 
$query->facetBuilders = [ new \eZ\Publish\API\Repository\Values\Content\Query\FacetBuilder\FieldFacetBuilder]; 


services: 
    myservice: 
    class: mynamespace\FacetHandler 
    tags: 
     - {name: ezpublish.search.solr.content.facet_builder_visitor} 

而且我得到了錯誤 「故意不落實:沒有遊客爲:的eZ \發佈\ API \庫\值\內容\查詢\ FacetBuilder \ FieldFacetBuilder」

我也有試過標籤「ezpublish.search.solr.content.facet_builder_visitor.aggregate」

我做錯了什麼?

回答

0

你需要交出你想應用這個方面的領域。 在你的情況可能是這樣的:

$query = new Query; 
$query->facetBuilders = [ new \eZ\Publish\API\Repository\Values\Content\Query\FacetBuilder\FieldFacetBuilder(
    [ 
     'fieldPaths' => 'article/title' 
    ] 
)]; 

「文章」是類的類型標識符爲篩選。我還沒有嘗試,如果你真的可以使用它沒有類限制。 「title」定義了用於該方面的字段標識符。

您也可以使用regexsort(除fieldPaths - 鍵進行過濾和排序結果。 爲sort的可能值列爲FieldFacetBuilder -class

希望這有助於常數。

0

配置你的領域類,如下

parameters: 
    ezpublish.search.solr.query.content.facet_builder_visitor.field.class: Your\Bundle\Query\Content\FacetBuilderVisitor\Field 

如下定義服務:

ezpublish.search.solr.query.content.facet_builder_visitor.field: 
    class: "%ezpublish.search.solr.query.content.facet_builder_visitor.field.class%" 
    tags: 
     - {name: ezpublish.search.solr.query.content.facet_builder_visitor} 

實現類

<?php 

/** 
* 
*/ 
namespace Your\Bundle\Query\Content\FacetBuilderVisitor; 

use EzSystems\EzPlatformSolrSearchEngine\Query\FacetBuilderVisitor; 
use eZ\Publish\API\Repository\Values\Content\Query\FacetBuilder; 
use eZ\Publish\API\Repository\Values\Content\Search\Facet; 

/** 
* Visits the Field facet builder. 
*/ 
class Field extends FacetBuilderVisitor 
{ 
    /** 
    * CHeck if visitor is applicable to current facet result. 
    * 
    * @param string $field 
    * 
    * @return bool 
    */ 
    public function canMap($field) 
    { 
     return $field === 'field_id'; 
    } 

    /** 
    * Map Solr facet result back to facet objects. 
    * 
    * @param string $field 
    * @param array $data 
    * 
    * @return Facet 
    */ 
    public function map($field, array $data) 
    { 
     return new Facet\FieldFacet(
      array(
       'name' => 'field', 
       'entries' => $this->mapData($data), 
      ) 
     ); 
    } 

    /** 
    * Check if visitor is applicable to current facet builder. 
    * 
    * @param FacetBuilder $facetBuilder 
    * 
    * @return bool 
    */ 
    public function canVisit(FacetBuilder $facetBuilder) 
    { 
     return $facetBuilder instanceof FacetBuilder\FieldFacetBuilder; 
    } 

    /** 
    * Map field value to a proper Solr representation. 
    * 
    * @param FacetBuilder $facetBuilder; 
    * 
    * @return string 
    */ 
    public function visit(FacetBuilder $facetBuilder) 
    { 
     return array(
      'facet.field' => 'field_id', 
      'f.field_id.facet.limit' => $facetBuilder->limit, 
      'f.field_id.facet.mincount' => $facetBuilder->minCount, 
     ); 
    } 
} 

沒有更多的例外,現在;),但不工作:「(https://doc.ez.no/display/DEVELOPER/Browsing%2C+finding%2C+viewing#Browsing,finding,viewing-PerformingaFacetedSearch