November Happy Hour will be moved to Thursday December 5th.

EPi Find Document hit Title and Excerpt

Vote:
 

Hi,

I am working on episerver CMS 9 Azure cloud application. I have implemented EPi find for search.

I have implemented the code and getting search results.

@Html.Raw(@hit.Document.Title)



@if (!Model.IsDocument(hit.Document.FileExtension))
{
@Html.Raw(@hit.Document.Excerpt)
}

Here, I am geeting some desription in Title and Excerpt respectively. I am not sure what it is(I mean Title must be Page name and Excerpt must be combination of Page description and Page Introduction).

I want Title should be Page Title property value from SEO tab of page and Excerpt should be Page Description Proeprty from SEO tab of a page.

How can I set Title and Exerpt to custom episerver properties or Can I add Custom properties in Hits.Document like PageTitle,PageDescription?

Thanks in Advance,

Best Regards,

Sanket Mahimkar

#171241
Nov 03, 2016 13:12
Vote:
 

Hi Sanket,

You can add your own projection for what values you want to be added to the title and excerpt.

client.Conventions.UnifiedSearchRegistry
                .ForInstanceOf<MySearchableClass>()
                .ProjectTitleFrom(x => x.MyTitleProperty);

Have a look at the documentation for more info

#171273
Nov 04, 2016 11:28
Vote:
 

Thanks for the reply.

As I said I want to display MetaTitle and MetaDescription properties which are there is SitePageData class.

I have inherited PageData with SitePageData and have applied to all pages.

How can I add Title and Description:

client.Conventions.UnifiedSearchRegistry
                .ForInstanceOf<SitePageData>()
                .ProjectTitleFrom(x => x.MetaTitle)
                .? (What to use for MetaDescription)
and How can I use MetaTitle and MetaDescription in

@foreach (var hit in Model.Hits)

{

<divclass="search-page__result">

<ahref="@hit.Document.Url"rel="@hit.Document.FileExtension">@Html.Raw(@hit.Document.Title)</a>

<divclass="search-page__result-content">

@if (!Model.IsDocument(hit.Document.FileExtension))

{

@Html.Raw(@hit.Document.Description)

}

</div>

</div>

}

Hope you understand.

Thanks for the reply.

Best Regards,

Sanket Mahimkar

#171278
Nov 04, 2016 11:42
Vote:
 

Forgot to tell you that I want to replace Hits.Document.Excerpt with MetaDescription from SitePageData

@Html.Raw(@hit.Document.Excerpt) to

@Html.Raw(@hit.Document.MetaDescription)

Regards,

Sanket Mahimkar

#171279
Nov 04, 2016 11:51
Vote:
 

Hi again,

Not sure I completely understand the issue. But you want Except to not be taken from the file but from the page that it's linked to? Or do you want it to take the SEO metadata entered on the file?

Again projections will let you define what values to fill the UnifiedSearchHit properties with per type. So you can set any property from any type 

SearchClient.Instance.Conventions.UnifiedSearchRegistry.ForInstanceOf<DocumentMediaData>()
    .ProjectExcerptUsing<ISearchContent>(doc => doc.<YourSEOMetadataField>);



Also unsure if you wanted to combind MetaTitle and MetaDescription into one field in the UnifiedSearchHit but should that be the case then you could

client.Conventions.UnifiedSearchRegistry
                .ForInstanceOf<SitePageData>()
                .ProjectTitleFrom(x => x.MetaTitle + x.MetaDescription);

If you wanted MetaDescription in your own property on the search hit then just use another projection.

Hope it helps

#171284
Edited, Nov 04, 2016 13:35
Vote:
 

Hi,

Yes. My Each page type is inherited with SitePageData which has MetaDescription and MetaTitle as Properties where Editors set Page Description and Page Title respectively.

The Foreach code which I have written gives Page Name and Excerpt which EPiFind returns. Instead of that, I want MetaTitle and MetaDescription to be shown.

client.Conventions.UnifiedSearchRegistry
                .ForInstanceOf<SitePageData>()
                .ProjectTitleFrom(x => x.MetaTitle);
The above code I guess will work to Show MetaTitle. But for Meta Description
SearchClient.Instance.Conventions.UnifiedSearchRegistry.ForInstanceOf<DocumentMediaData>()
    .ProjectExcerptUsing<ISearchContent>(doc => doc.<YourSEOMetadataField
I dont have Instance method for searchClient. It gives compile time error.Insyead of that I use
searchClient is of type IClient

(private readonly IClient searchClient;)

SearchClient.Conventions.UnifiedSearchRegistry.ForInstanceOf<DocumentMediaData>()
    .ProjectExcerptUsing<ISearchContent>(doc => doc.<YourSEOMetadataField
but, this code doesnt give YourSEOMetaDataField. (doc => doc.<Here it gives options like "Encode enription/Encode Title/Exerpt Length ..etc">
So, Basically, When user searches for specific text, I want to show list of related pages with MetaTitle as Heading and MetaDescription as Summary.
ex.User seaches for Kund
1.KundService (This will come from Page's Meta Title)
This is Kundservice page.Some description of Kundservice comes here.(This will come from Page's Meta Description property)
2.Företag
Foretag also has Kundservice options.Somoe more page descripiotn.
3.Kontackto uss
You can always contact us. Or you can visit our Kundservice details.
Thanks in advacne.
Best Regards,
Sanket Mahimkar
#171294
Nov 05, 2016 19:41
Vote:
 

Hi,

Ok then I think I get it.

Well you can just add 

public virtual string SearchTitle { get { return MetaTitle; } }
public virtual string SearchSummary { get { return MetaDescription; } }

to your SitePageData. 

#171320
Nov 07, 2016 16:29
Vote:
 

Hi Peter,

I tried with putting 

public virtual string SearchTitle { get { return MetaTitle; } }
public virtual string SearchSummary { get { return MetaDescription; } }
in SitePageData, but unfortunately, it didn't worked.
Regards,
Sanket Mahimkar
#171501
Nov 08, 2016 15:14
Vote:
 

Did you reindex the site after doing the update?

As the search properties are filled during indexing.

#171509
Nov 08, 2016 22:53
Vote:
 

Hi Petter,

Yes, It worked finally. Thanks for the help :)

//Sanket Mahimkar

#171531
Nov 09, 2016 15:39
Vote:
 

Sweet!

Glad I could help.

Don't forget to mark the answer for future viewers =)

#171553
Nov 10, 2016 14:50
Vote:
 

Can we do this without altering the SitePageData? Because SitePageData is an abstarct class from base dll.

#174579
Jan 30, 2017 22:54
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.