Facet Total incorrect with multiselect field.
Closed this issue · 4 comments
Hi,
I am hoping this is a config issue or search issue.
I have managed to get the facets return data and worked really well and quite easy to get setup.
I then noticed that some of the totals were not correct.
I tracked this down to my facet field is a multiselect selecting form Umbraco nodes I use for taxonomy.
I noticed that if only one item (category) was selected this gets included in the total.
If I selected more than one item (category) then both of the selected values are not included in the total.
So for example I have 5 blog articles
Blog 1 - Category = 'Test Blog Category 1'
Blog 2 - Category = 'Test Blog Category 1'
Blog 3 - Category = 'Test Blog Category 2'
Blog 4 - Category = 'Test Blog Category 3'
Blog 5 - Category = 'Test Blog Category 1 and Test Blog Category 2'
The facet total for 'Test Blog Category 1' would be 2 when it should be 3.
The facet total for 'Test Blog Category 2' would be 1 when it should be 2.
Because the data in Blog 5's category selection would not be included in the facet search results.
Here is my search code. I am hoping there is an extra setting I can enable to make this function as required.
var facetCriteria = facetSearcher.CreateQuery(IndexTypes.Content, BooleanOperation.And);
var facetQuery = facetCriteria.NodeTypeAlias("blogDetailsPage");//considering blog pages only in the search
facetQuery.And().Facet("categories");
var facetResults = facetQuery.Execute().GetFacet("categories");
Kind Regards
David
Hello @DavidArmitage,
Thanks for using Examine Facets! 😊
Facets are calculated based on the tokens for each field in your index. Put simply, in default configuration, whitespace is used to determine where each term starts and ends.
For example, a field with the value "Category-1 and Category-2"
would create 2 facets "Category-1","Category-2"
("and" is ignored as a stop word). Without the dashes, the numbers would be ignored - e.g. "Category 1 and Category 2"
would create 2 facets "Category","1","2"
. You can manipulate your fields to get them into the right shape for faceting at index time.
If you are using Umbraco, I highly recommend installing my Facet Extensions and Search Extensions projects. These include a super clean way way to index pickers into a searchable and facetable format - simply set the field type to "picker" and the rest is handled for you.
Hope this helps!
Cheers,
Callum
Thanks for the information.
Yes I am using Umbraco 8. I will try and implement these tomorrow.
One question.
So you are saying I can create a custom field in the search index that can be used for the facet searching rather than reply on the existing field which is a multiple tree picker. This is probably adding the data in an unsupported fashion.
Actually something similar to what I am doing already to make a multitree picker easily searchable.
Eg.
var searchableCategoryGuids = string.Empty;
if (contentNode.Value("categories") is List<IPublishedContent> categories)
{
foreach (IPublishedContent category in categories)
searchableCategoryGuids += (" " + category.Key.ToString());
}
e.ValueSet.Set("searchableCategoryGuids", searchableCategoryGuids);
Kind Regards
David
That worked perfectly. I can extend this exactly like you said using my example above. Exactly like I do to make multitree pickers searchable. I create a custom field in the index which is a nice joined string of the guids of the selected multi tree picker items. I can use this string as a searchable field. I can then use this same field as the facet field which works perfectly since it's a list of guids split with a " ".
There was hardly any extra coding I needed to do since I already had this in place. Thanks for helping here.
I will also review those extensions you sent me through. They look great. I didn't know they existed.
Hey @DavidArmitage,
Glad to hear this helped and you got up and running!
If you like the project please consider giving it a ⭐️ on GitHub ;-)
Cheers,
Callum