Yeah, it is possible with indexing additional fields.
public static class IContentExtensions
{
public static string Url(this IContent content)
{
var urlResolver = ServiceLocator.Current.GetInstance<UrlResolver>();
return urlResolver.GetUrl(content.ContentLink);
}
}
[InitializableModule]
[ModuleDependency(typeof(EPiServer.Find.Cms.Module.IndexingModule))]
public class IndexingEventInitialization : IConfigurableModule
{
public void Initialize(InitializationEngine context)
{
SearchClient.Instance.Conventions.ForInstancesOf<MyPage>()
.IncludeField(x => x.Url());
}
}
And when you are getting it back
var query = _findClient.Search<MyPage>()
.Filter(filter)
.FilterForVisitor()
.OrderByDescending(hap => hap.DatePublished)
.Take(20)
.Select(mp => new NewsArticleSummaryModel
{
PageHeading = mp.PageHeading,
DatePublished = mp.DatePublished,
TeaserText = mp.TeaserText,
TeaserImage = mp.TeaserImage,
Url = mp.Url()
});
For the image, you do the same :)
Agree with what Sebbe said, the beauty of Find is you can add what you need to your index for later uses. Note that this is Find, and to some extend, Find.Commerce, not FindSearchProvider
Personally I prefer adding readonly properties to my models for the Find indexing of custom fields. I just like knowing where everything is for a class/object rather than in initalization models. I'd usually create an interface for indexable properties and add that to the IContent types so there's a clear separating of content properties and indexing properties. But that's just my personal preference but a good optional choice.
Thanks so much all - that worked perfectly!
Apologies for the incorrect tag - I have corrected now.
I've been playing around with EpiServer search, and have successfully managed to use it to filter some pages and pull out the relevant content items using
GetContentResult()
. I've also managed to useGetResult()
to project some simple properties into a custom object.My question is whether it is possible to have any sort of hybrid between the two? I want to show a list of the search items on a page - and it's fine for some title and description text. But how would I 1) get the URL to the page, without using
GetContentResult()
, and 2) is it possible to get an image in a projection too?Something like this?
I ask as getting 20 items out using
GetContentResult()
seems quite a bit slower. I know GetResult doesn't hit the DB, and uses the index instead, but surely it's at least possible to get the URL and image without pulling out the entire page?I assume I could get the IDs and fetch them individually, but that seems fiddly. Is there another way?