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
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
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
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
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
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.
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
Did you reindex the site after doing the update?
As the search properties are filled during indexing.
Hi Petter,
Yes, It worked finally. Thanks for the help :)
//Sanket Mahimkar
Sweet!
Glad I could help.
Don't forget to mark the answer for future viewers =)
Can we do this without altering the SitePageData? Because SitePageData is an abstarct class from base dll.
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