Skip to content

Commit

Permalink
Merge pull request #3483 from rbayet/fix-analytics-only-first-page-fo…
Browse files Browse the repository at this point in the history
…r-avg-count

[Analytics] Ignore non-first page for avg. count/0 result pages
  • Loading branch information
rbayet authored Jan 10, 2025
2 parents 31ecb8a + ec65e08 commit 39bc417
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,21 +141,50 @@ protected function getFilteredResultCountMetric()
'filter' => $this->queryFactory->create(
QueryInterface::TYPE_BOOL,
[
'must' => [
$this->getIsFirstPageQuery(),
],
'mustNot' => [
$this->queryFactory->create(
QueryInterface::TYPE_NESTED,
[
'path' => 'page.product_list.filters',
'query' => $this->queryFactory->create(
QueryInterface::TYPE_EXISTS,
['field' => 'page.product_list.filters']
),
]
),
$this->hasNavigationFiltersQuery(),
],
]
),
]
);
}

/**
* Return "only first page" query.
*
* @return QueryInterface
*/
protected function getIsFirstPageQuery()
{
return $this->queryFactory->create(
QueryInterface::TYPE_TERM,
[
'field' => 'page.product_list.current_page',
'value' => 1,
]
);
}

/**
* Return query indicating there are active product list filters.
*
* @return QueryInterface
*/
protected function hasNavigationFiltersQuery()
{
return $this->queryFactory->create(
QueryInterface::TYPE_NESTED,
[
'path' => 'page.product_list.filters',
'query' => $this->queryFactory->create(
QueryInterface::TYPE_EXISTS,
['field' => 'page.product_list.filters']
),
]
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Smile\ElasticsuiteAnalytics\Model\Search\Usage\Terms\AggregationProvider as TermsAggregationProvider;
use Smile\ElasticsuiteCore\Search\Request\BucketInterface;
use Smile\ElasticsuiteCore\Search\Request\MetricInterface;
use Smile\ElasticsuiteCore\Search\Request\QueryInterface;

/**
* Aggregation provider for terms that always return 0 results
Expand All @@ -34,6 +35,7 @@ public function getAggregation()
$aggParams = [
'field' => 'search_query_void.sortable',
'name' => 'search_terms',
'filter' => $this->getIsFirstPageQuery(),
'metrics' => $this->getMetrics(),
'pipelines' => $this->getPipelines(),
'sortOrder' => ['unique_sessions' => 'desc'],
Expand Down

0 comments on commit 39bc417

Please sign in to comment.