Try our conversational search powered by Generative AI!

Episerver Find UnifiedSearch

Vote:
 

Hi i am using UnifiedSearch, i used a Interface to define the Search and i want to returns the records with a image.

if i remove  CustomizeProjection it works, but i want to return the image also

The problem that i have is in line that get the results, it throwing a Exception 

Message"An error has occurred."
ExceptionMessage"Object reference not set to an instance of an object."
ExceptionType"System.NullReferenceException"
StackTrace" at EPiServer.Find.UnifiedSearch.UnifiedSearchRegistry.GetProjectionForType(Type type) at EPiServer.Find.UnifiedSearch.UnifiedSearchRegistry.GetProjectionForType(Type type) at EPiServer.Find.UnifiedSearch.UnifiedSearchRegistry.GetRules(Type type) at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext() at 
But i don't have idea what i am doing wrong
var results =
            SearchClient.Instance.UnifiedSearchFor(requestItem.SearchTerm)
            .GetResult();



public
 interface ISearchData     {          string SearchTitle { get;  }          string SearchText { get; }          string SearchSummary { get;  } string SearchHitUrl { get; }
Url SearchImage { get; set; }              }


public class FindInitialization : IInitializableModule
   {
       public void Initialize(EPiServer.Framework.Initialization.InitializationEngine context)
       {
 
 
            SearchClient.Instance.Conventions.UnifiedSearchRegistry.Add<>ISearchData>();
            SearchClient.Instance.Conventions.UnifiedSearchRegistry.ForInstanceOf<>ISearchData>().
               CustomizeProjection(x => x.ProjectImageUriFrom<>ISearchData>(c => GetPageImage(c.SearchImage)));
 
           
       }
 
       private Uri GetPageImage(EPiServer.Url image)
       {
           if (image != null)
               return image.Uri;
           return null;
       }
#112557
Oct 30, 2014 6:32
Vote:
 

I think it's easier to implement ISearchContent to your types and do your GetPageImage() in there.

#116160
Jan 25, 2015 19:21
* 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.