Try our conversational search powered by Generative AI!

UnifiedSearch include Categories (Facets/tags) in UnifiedSearchHit results



We're trying to include the list of categories in our UnifiedSearchResults with no luck.  The documentation seems to be VERY sparse with UnifiedSearch.

We've tried an extension method to see if we could just get it into the UnifiedSearchHit.FileName property using this:

		public static string SearchFilename(this PageData thisPageData)
			return thisPageData.Category.ToString();

That didn't seem to work.

We've played with projections as well.  Just trying to get it to replace the name to see if there's any traction with that.

SearchClient.Instance.Conventions.UnifiedSearchRegistry.Add<PageData>().ProjectTypeNameFrom<PageData>(content => content.Category.ToString())

No luck there either.

Does anyone have some suggestions on what we could try please?

Oct 31, 2022 15:10


If you're trying to retrieve the categories for each result and display them as part of the result listing, you can retrieve the original content item and get the categories from there. The content item can be retrieved using the OriginalObjectGetter() method which returns an object which you can cast into whatever's needed like this:

var categorisedContent = hit.OriginalObjectGetter() as ICategorizable;
var categories = categorisedContent?.Category;

Obviously bear in mind that the original object may not be an ICategorizable (or whatever you choose to cast it to) depending what you're indexing and searching so you'll need to handle the scenario where categorisedContent is null.

Nov 01, 2022 11:14


Thank you for this. I just tried it out.  That's a real help.

Do you know off-hand if this method pulls data from the search results, or if it goes back to the DB to get the content result for each call?

Nov 01, 2022 20:38

I don't know for definite, but I'm fairly sure that, in that instance, it pulls content from the IContentRepository or IContentLoader so it'll be coming from either the database or the cache depending on whether that content item has been loaded before.

Nov 01, 2022 22:25


Thank you for this.  I did some testing with SQL Profiler and this generates a LOT of hits to the DB (when not cached).  I feel like in the long run, this may be a bit expensive.  Do you, or anyone know the proper way to do this with the UnifiedSearchRegistry?  Either the indexing registry or the projections?  This data exists in the Find index, I (ideally) just need a way to map it from Find index.


Nov 02, 2022 14:28

I suspect it can be done with projections as there is a field in ISearchContent called SearchCategories which should contain the info you need. I'll take a look if I get a moment later.

Nov 03, 2022 9:12

You should be able to get access to the category value without hitting the content repository by adding it to the MetaData dictionary on the search hit. You can add that in your search initialisation like this:

    .ProjectMetaDataFrom(page => new Dictionary<string, EPiServer.Find.IndexValue> { { "Categories", page.Category.ToString() } });

You'll need to run the indexing scheduled job before that change will take effect.

Nov 03, 2022 14:55

Paul, thank you so much for this.  I tried in a few different ways to accomplish it and your solution seems to work really well for me.

Nov 03, 2022 16:45
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.