n my liferay instance, there a listing page e-services and I implement it like this:
- adding a search bar component
- adding a category facet compnent
- adding a search result component
- adding a search options and allow empty search
- adding a blueprint options and make a blueprint that query on e-service strucure only
there is a behavior which is not good, when I type anything on search bar like “hhhh” and there is no content, the category facet disappear, I want to prevent this behavior
2 Answers
2
Hey @mahmoud.khalil - so, this behaviour is by design. If you look at any of the OOTB Widget Templates for the Category Facet widget (and indeed many of the other Search Widgets) you’ll see that most of the rendering is only done if there are Categories in the assets returned by your search.
You can find some of the OOTB templates by navigating to the “Global” site, opening the Site menu, and going to Design → Templates → Widget Templates. A good example is the “Compact Layout” (make sure the type is “Category Facet Template”.
The logic here is simple - you get to filter by the Categories that exist on the assets in the search, so if there are no categories, there’s nothing to filter on.
So, the Freemarker (the bit that matters) looks like:
<ul class="list-unstyled">
<#if entries?has_content>
<#list entries as entry>
<li class="facet-value">
With no entries (no Categories for all the assets in the search results) you’ll get an empty unordered list.
You can of course create your own templates, and do anything you want. My advise is to not edit the OOTB templates, but to copy them and create your own. You could simply add an <#else> block and output anything you want (like maybe “No categories found” or something).
The same thing will happen with the Tag Facet, the Custom Facet and so on.
Hope this helps!
Cheers,
Ben
Hi @turnstok ,
Thanks for the clarification — that makes sense regarding how the facet entries are built from the current result set.
I tried the template-level approach (<#else> block), but it doesn’t solve this behavior on this case because the widget template itself is not rendered when there are no results.
After digging deeper into the source, it looks like the behavior comes earlier from the Category Facet’s view.jsp in Liferay Portal source
if (assetCategoriesSearchFacetDisplayContext.isRenderNothing()) {
return;
}
and:
<c:when test="<%= assetCategoriesSearchFacetDisplayContext.isRenderNothing() %>"> <aui:input ... /> </c:when>
So it seems the Freemarker template never gets invoked when isRenderNothing() is true, which is why customizing the OOTB template doesn’t help here.
Do you know if there’s another supported way to override or bypass this behavior without extending/overriding the widget itself?
Thanks in advance.
may be try creating custom template, select vocabulary and in category facet set term frequency to 0
– Priyank_GajeraThanks, @Priyank_Gajera! Setting the Frequency Threshold to 0 in the Category Facet configuration solved my problem.
– mahmoud.khalil