After some experimentation I notice that all other predefined projections (ex. title) works fine, it is only ImageUri that I cant get to work.
Hi
Try to use the OriginalString property:
SearchClient.Instance.Conventions.UnifiedSearchRegistry.ForInstanceOf<ArticlePage>()
.CustomizeProjection(p => p.ProjectImageUriFrom<ArticlePage>(a => a.ImageUri.OriginalString));
That wouldnt even compile, the type must be a Uri, which lead me to believe there is some sort of json serialization error going on, but I have no idea what I can do to resolve it.
Ok, sorry, I'm using the EPiServer.Url as property type.
The implementation below works for me.
SearchClient.Instance.Conventions.UnifiedSearchRegistry
.ForInstanceOf<SitePageData>()
.CustomizeProjection(
x => x.ProjectImageUriFrom<SitePageData>(
page => GetPageImage(page.PageImage.OriginalString)));
private static Uri GetPageImage(string url)
{
if(string.IsNullOrWhiteSpace(url))
{
return null;
}
return new Uri(url, UriKind.Relative);
}
Taht stopped me from getting exceptions atleast. But if I check the index, the 'SearchImageUri' property (or any like that) is not present anywhere for pages that do have a valid image set.
Hi guys,
I had the exact same Exception as Erik but I solved it in another way. My problem was that I couldn't project a thumbnail from an ImageVault image. I figured out that since the projection is executed on the searchresult the returned PageData is just a deserialized JSON-object, not a true PageData-object. And on that premiss I wrote this little crowbar implementation.
SearchClient.Instance.Conventions.UnifiedSearchRegistry
.ForInstanceOf<PageData>()
.CustomizeProjection(
x => x.ProjectImageUriFrom<PageData>(
page => GetThumbnail(page.ContentGuid)));
private static Uri GetThumbnail(Guid id)
{
if (id != null)
{
PageData p = Utilities.GetPageFromGuid(id);
if (p != null && (p[Web.Global.ImageProperties.List] != null ||
p[Web.Global.ImageProperties.Media] != null))
{
Thumbnail media = SiteDataFactory.Instance.GetThumbnail(p, 200, 140);
if (media != null)
return new Uri(media.Url, UriKind.RelativeOrAbsolute);
}
}
return null;
}
Provided code examples don't work for me and ImageUri is always null if I use custom methods in ProjectImageUriFrom expression. The fix is to directly call "new Uri()" in the expression. This code worked for me:
client.ForInstancesOf<PageData>() .IncludeField(x => x.SearchImageUri()); client.UnifiedSearchRegistry.ForInstanceOf<PageData>() .ProjectImageUriFrom(x => x.SearchImageUri() != null ? new Uri(x.SearchImageUri()) : null);
SearchImageUri is my extension method to get string url for page image and store it in Find index. It is fine to call it several times in ProjectImageUriFrom expression, because it's not really executed there, but used as a getter expression for "SearchImageUri" property of a search result.
Hi,
I tried using this extension method to add a image thumbnail to my search results as most of my pages have some sort of image, I used what 'http://find.episerver.com/Documentation/unified-search' suggested, and tried first this (in a init module depending on "IndexingModule"):
I also tried this:
I then reindexed and made a search like so:
They both throw the error: "EPiServer.Find.ProjectionException: To deserialize objects the $type property must be set."
Could someone point me in the right direction as of how exactly I am supposed to use these projection extensions?