Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
FilterAggregation example
public
function
handle
(
CriteriaPartInterface
$criteriaPart
,
Criteria
$criteria
,
Search
$search
,
ShopContextInterface
$context
)
{
$aggregation
=
new
ValueCountAggregation
(
'has_available_variant_count'
)
;
$aggregation
->
setField
(
'hasAvailableVariant'
)
;
$filter
=
new
FilterAggregation
(
'has_available_variant_filter'
)
;
$filter
->
setFilter
(
new
TermQuery
(
'hasAvailableVariant', true
)
)
;
$filter
->
addAggregation
(
$aggregation
)
;
$search
->
addAggregation
(
$filter
)
;
}
/** * {@inheritdoc} */
public
function
hydrate
(
array
$elasticResult
,
public
function
handle
(
CriteriaPartInterface
$criteriaPart
,
Criteria
$criteria
,
Search
$search
,
ShopContextInterface
$context
)
{
$aggregation
=
new
ValueCountAggregation
(
'shipping_free_count'
)
;
$aggregation
->
setField
(
'shippingFree'
)
;
$filterAgg
=
new
FilterAggregation
(
'shipping_free_filter'
)
;
$filterAgg
->
setFilter
(
new
TermQuery
(
'shippingFree', true
)
)
;
$filterAgg
->
addAggregation
(
$aggregation
)
;
$search
->
addAggregation
(
$filterAgg
)
;
}
/** * {@inheritdoc} */
public
function
hydrate
(
array
$elasticResult
,
CombinedConditionFacet
$criteriaPart
,
Criteria
$criteria
,
Search
$search
,
ShopContextInterface
$context
)
: void
{
$query
=
$this
->combinedConditionQueryBuilder->
build
(
$criteriaPart
->
getConditions
(
)
,
$criteria
,
$context
)
;
$filter
=
new
FilterAggregation
(
$criteriaPart
->
getName
(
)
)
;
$filter
->
setFilter
(
$query
)
;
$search
->
addAggregation
(
$filter
)
;
}
}
$field
.= '.raw';
}
$aggregation
=
new
TermsAggregation
(
$criteriaPart
->
getName
(
)
)
;
$aggregation
->
setField
(
$field
)
;
$aggregation
->
addParameter
(
'size', self::AGGREGATION_SIZE
)
;
break
;
case
ProductAttributeFacet::MODE_BOOLEAN_RESULT:
$count
=
new
ValueCountAggregation
(
$criteriaPart
->
getName
(
)
. '_count'
)
;
$count
->
setField
(
$field
)
;
$aggregation
=
new
FilterAggregation
(
$criteriaPart
->
getName
(
)
)
;
$aggregation
->
setFilter
(
new
ExistsQuery
(
$field
)
)
;
$aggregation
->
addAggregation
(
$count
)
;
break
;
case
ProductAttributeFacet::MODE_RANGE_RESULT:
$aggregation
=
new
TermsAggregation
(
$criteriaPart
->
getName
(
)
)
;
$aggregation
->
setField
(
$field
)
;
$aggregation
->
addParameter
(
'size', self::AGGREGATION_SIZE
)
;
break
;
default
: