Hi, this is a very sneaky issue I faced while creating a template that makes use of the Reference module (v3.4.57).
Here is the context
I want to include a basic “advanced search” form in my item/browse template to simplify the way visitors make searches. This way, a visitor can browse the items in a unique page, be they resulting from a search or from an item set.
The result of my efforts look like this when you browse an item set:
and if you click on the “advanced search” link:
Let’s focus on the facet-like lists that let the visitor select item sets in the first list and then refine the selection using the second list:
These facets are “homemade”, the second one being built on the resultsets returned by the 2 calls to the references()->list() method in the following code:
<!-- template begin: common/search/search-facet -->
<?php
// get the references for the facet using the "query_full" query
$refFacetFull = $this->references()->list($facetConfig['metadata'], $facetConfig['query_full'], null);
// get the references for the facet using the real filtered query
$refFacetFiltered = $this->references()->list($facetConfig['metadata'], $query, null);
...
Why call the method 2 times? Because we need to display all the categories, even if the items count is 0, and these ones are not returned by the method.
To achieve this, the first call uses a basic query (named query_full in the code above) which does only specify the site id, and the second call uses the “real” query to get the list of the corresponding categories with the number of occurences.
Then, the facet is built by creating a merged list where each entry in the first resultset that is not present in the second is shown as a disabled checkbox showing 0 result, and each entry of the second resultset appears as an enabled checkbox showing the number of occurences.
Nice, so where is the problem?
Well when I first ran this code, the result was the following:
Here, you see that the second facet shows the result of the first query - the basic one - and not the expected result, as if the second call to the references()->list() method gives the same result as the first one, even if the queries are different. And this is really what it does: if you debug the 2 resultsets, they are exactly the sames, and so there is a bug somewhere in the References module.
So what?
After diving deep into the code, I finally found this in the src/Stdlib/References.php file (in the previous versions of the module, this file was located in src/Mvc/Controller/Plugin) :
protected function searchQuery(QueryBuilder $qb, ?string $type = null): self
{
// When facets are searched, the same query can be used multiple times,
// so store results. It may improve performance with big bases when
// using a query with "contains" (in), so sql "like". Nevertheless, it
// is useful only when parameters are the same, that is not frequent.
// The dql is not available with dbal connection query builder.
static $sqlToIds = [];
...
![]()
As you can guess, my very first and immediate action was to shout some words which can’t be reproduced here
. And the second was to wipe out this troublesome, cumbersome, poisonous “static” word, which solved my problem ![]()
Hope this can help anyone looking to develop their own browse/search/facet-style templates.



