Using Geta Epi Categories for Unified Search (Find 12.7.1.0)

Vote:
 

We are using the Geta Epi Categories in out solution https://github.com/Geta/EpiCategories. We are using version 1.2.1.

Is there a way to use the Geta Epi Categories in the unified search method. The CMS users will be assigning categories to content with the Geta Categories property type (IList). The Unified Search Search Categories property is of the IEnumerable type so was wondering if this is possible and a nudge in the right direction to do this

Thanks in advance!

#193869
Jun 06, 2018 16:55
Vote:
 

Hi Steven

You can add the categories property to your indexed object(s) as follows:

[ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
public class AddGetaCategoriesInitialization : IInitializableModule
{
    private static readonly ILogger Logger = LogManager.GetLogger();

    private bool _initialized;

    public void Initialize(InitializationEngine context)
    {
        if (_initialized || context.HostType != HostType.WebApplication)
        {
            return;
        }

        SearchClient.Instance.Conventions.ForInstancesOf<PageTypeWithGetaCategories>().IncludeField(x => x.GetaCategories());
        
        _initialized = true;
    }

    public void Uninitialize(InitializationEngine context) { }
}

Then use the extension method as following:

public static List<string> GetaCategories(this object content)
{
    if (content is PageTypeWithGetaCategories page)
    {
        return ConvertToList(page.GetaCategoriesPropertyName);
    }
    return new List<string>();
}

Then facet as usual using .TermsFacetFor(x => x.GetaCategories()) and query using  query = query.FilterHits(x => x.GetaCategories().Match(categorySearchTerm);

David

#193878
Edited, Jun 06, 2018 23:33
Vote:
 
<p>Thanks, David I shall have a look at this today and see how it goes!</p>
#194082
Jun 13, 2018 9:35
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.