AI OnAI Off
Hi,
I created a hierarchical facet for Find a while ago: https://github.com/x2find/HierarchicalFacet2Find that will do what you are trying to achieve (that the subsection count will be dependet on the "top" section). Try it out. It is olso on the EPiServer nuget feed: http://nuget.episerver.com/en/OtherPages/Package/?packageId=HierarchicalFacet2Find
/Henrik
Hello,
I have an interesting scenario and wondered if anyone could offer some advice on the best approach to resolve.
I have a navigation structure and need to reproduce this as a faceted search navigation. At the moment I am doing the following:
- Getting the top level pages and binding to a repeater
- On the item data bound event I am checking if the current top level page is selected, if it is I bind the child pages of the selected item to a nested repeater
- this provides something like the following:
Section 1
Section 2 (selected)
Sub section 1
Sub section 2
Sub section 3
Sub section 4
Section 3
Section 4
In addition to this I am performing a search and displaying results for the section or sub section selected which works and brings back the correct number of results for pages in section or sub section.
For the navigation above I need to include the number of results for each section and sub section after the link e.g. Section 1 (17) and I have a method to do this as follows:
- I populate a UnifiedSearchResults object on page load:
UnfilteredResults =
SearchClient.Instance.UnifiedSearchFor(this.SearchTerm)
.TermsFacetFor(x => x.SearchSection)
.TermsFacetFor(x => x.SearchSubsection)
.GetResult();
- I use this on the databinding event of the repeaters to find the count based on section and subsection and add it to the text of the link control e.g. for a sub section:
protected string SetSearchSubCategoryLinkTextResults(string currentLinkText, string searchCategory, string searchSubCategory)
{
int sectionCount = 0;
if (UnfilteredResults != null)
{
foreach (var sectionGroup in UnfilteredResults.TermsFacetFor(x => x.SearchSection))
{
if (searchCategory == sectionGroup.Term)
{
foreach (var sectionSubGroup in UnfilteredResults.TermsFacetFor(x => x.SearchSubsection))
{
if (searchSubCategory == sectionSubGroup.Term.ToLower())
{
sectionCount = sectionSubGroup.Count;
break;
}
}
break;
}
}
}
return String.Format("{0} ({1})", currentLinkText, sectionCount.ToString());
}
Now this works unless I have the sub sections with the same name under different sections (a valid scenario), when it adds them together for the sub sections with the same name e.g.
Section 1
Sub section 1 - 2 results
Sub section 2 - 4 results
Section 2
Sub section 1 - 3 results
Sub section 3 - 6 results
Displays as
Section 1
Sub section 1 (5)- 2 results
Sub section 2 (4)- 4 results
Section 2
Sub section 1 (5)- 3 results
Sub section 3 (6) - 6 results
Note both Sub section 1 displays 5 as it's the sum of the result counts for Section 1 > Sub section 1 and Section 2 > Sub section 1
I'm sure there must be a better and more elegant way to acheive this. Can anyone offer any suggestions?
Thanks in advance,
Mark