mirror of
https://github.com/Alfresco/SearchServices.git
synced 2025-10-01 14:41:19 +00:00
SEARCH-2126: Address formatting issues.
This commit is contained in:
@@ -610,78 +610,73 @@ public class AlfrescoSearchHandler extends RequestHandlerBase implements
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Facet SOLR Queries are omitting facet results with count equals to 0 as general rule.
|
||||
* SOLR Queries executed on a Shard environment, don't include these results but the same
|
||||
* query executed on a single server environment are adding these elements to the response.
|
||||
*
|
||||
* This method removes every facet query having count equals to 0 to provide the same
|
||||
* behaviour in both cases.
|
||||
*
|
||||
* A query like the following, will return only Facet Queries having elements:
|
||||
*
|
||||
* "facetQueries" : [
|
||||
* { "query" : "content.size:[0 TO 102400]", "label" : "small"},
|
||||
* { "query" : "content.size:[102400 TO 1048576]", "label" : "medium"},
|
||||
* { "query" : "content.size:[1048576 TO 16777216]", "label" : "large"}
|
||||
* ]
|
||||
*
|
||||
* For instance, if there are only results with "small" key, the result will be:
|
||||
*
|
||||
* "facetQueries": [
|
||||
* {
|
||||
* "label": "small",
|
||||
* "filterQuery": "content.size:[0 TO 102400]",
|
||||
* "count": 5
|
||||
* }
|
||||
*
|
||||
* @param rsp
|
||||
*/
|
||||
public static final String FACET_COUNTS_KEY = "facet_counts";
|
||||
public static final String FACET_QUERIES_KEY = "facet_queries";
|
||||
public static final String FACET_CONTEXT_KEY = "_facet.context";
|
||||
@SuppressWarnings("unchecked")
|
||||
/**
|
||||
* Facet SOLR Queries are omitting facet results with count equals to 0 as general rule.
|
||||
* SOLR Queries executed on a Shard environment, don't include these results but the same
|
||||
* query executed on a single server environment are adding these elements to the response.
|
||||
* This method removes every facet query having count equals to 0 to provide the same
|
||||
* behaviour in both cases.
|
||||
*
|
||||
* A query like the following, will return only Facet Queries having elements:
|
||||
* "facetQueries" : [
|
||||
* { "query" : "content.size:[0 TO 102400]", "label" : "small"},
|
||||
* { "query" : "content.size:[102400 TO 1048576]", "label" : "medium"},
|
||||
* { "query" : "content.size:[1048576 TO 16777216]", "label" : "large"}
|
||||
* ]
|
||||
*
|
||||
* For instance, if there are only results with "small" key, the result will be:
|
||||
* "facetQueries": [
|
||||
* {
|
||||
* "label": "small",
|
||||
* "filterQuery": "content.size:[0 TO 102400]",
|
||||
* "count": 5
|
||||
* }
|
||||
* ]
|
||||
*
|
||||
*/
|
||||
public static final String FACET_COUNTS_KEY = "facet_counts";
|
||||
public static final String FACET_QUERIES_KEY = "facet_queries";
|
||||
public static final String FACET_CONTEXT_KEY = "_facet.context";
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void removeFacetQueriesWithCountZero(SolrQueryResponse rsp)
|
||||
{
|
||||
|
||||
{
|
||||
NamedList<Object> facetCounts = (NamedList<Object>) rsp.getValues().get(FACET_COUNTS_KEY);
|
||||
|
||||
if (facetCounts != null)
|
||||
{
|
||||
|
||||
NamedList<Object> facetQueries = (NamedList<Object>) facetCounts.get(FACET_QUERIES_KEY);
|
||||
|
||||
if (facetQueries != null)
|
||||
{
|
||||
List<String> keyCountsToRemove = new ArrayList<>();
|
||||
|
||||
|
||||
facetQueries.forEach(facetQuery -> {
|
||||
if ((Integer) facetQuery.getValue() == 0)
|
||||
{
|
||||
keyCountsToRemove.add(facetQuery.getKey());
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if (!keyCountsToRemove.isEmpty())
|
||||
{
|
||||
keyCountsToRemove.forEach(key -> facetQueries.remove(key));
|
||||
|
||||
((NamedList<Object>)rsp.getValues().get(FACET_COUNTS_KEY)).remove(FACET_QUERIES_KEY);
|
||||
((NamedList<Object>)rsp.getValues().get(FACET_COUNTS_KEY)).add(FACET_QUERIES_KEY, facetQueries);
|
||||
|
||||
|
||||
((NamedList<Object>) rsp.getValues().get(FACET_COUNTS_KEY)).remove(FACET_QUERIES_KEY);
|
||||
((NamedList<Object>) rsp.getValues().get(FACET_COUNTS_KEY)).add(FACET_QUERIES_KEY,
|
||||
facetQueries);
|
||||
|
||||
BasicResultContext result = (BasicResultContext) rsp.getResponse();
|
||||
FacetContext facetContext = (FacetContext) result.getRequest().getContext().get(FACET_CONTEXT_KEY);
|
||||
facetContext.getAllQueryFacets().removeIf(queryFacet ->
|
||||
keyCountsToRemove.contains(queryFacet.getKey())
|
||||
);
|
||||
FacetContext facetContext = (FacetContext) result.getRequest().getContext()
|
||||
.get(FACET_CONTEXT_KEY);
|
||||
facetContext.getAllQueryFacets()
|
||||
.removeIf(queryFacet -> keyCountsToRemove.contains(queryFacet.getKey()));
|
||||
result.getRequest().getContext().put(FACET_CONTEXT_KEY, facetContext);
|
||||
|
||||
|
||||
log.debug("In SOLR query '" + result.getRequest() + "', Facet Queries results having labels "
|
||||
+ keyCountsToRemove + " have been removed from results");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ////////////////////// SolrInfoMBeans methods //////////////////////
|
||||
|
||||
|
Reference in New Issue
Block a user