Need to create a search page

Vote:
 

public class DefaultPageViewModel<T> : IPageViewModel<T> where T : PageData
    {
        public DefaultPageViewModel(T currentPage)

        {
            CurrentPage = currentPage;
            Section = ContentExtensions.GetSection(currentPage.ContentLink);
        }
        public T CurrentPage { get; set; }
        public IContent Section { get; set; }
    }


What to keep in the place of 'T' ?

showing error on
DefaultPageViewModel<T> ->(CS0311) The type 'T' cannot be used as type parameter 'T' there is no implicit reference converse to 'T' to 'EPiServerDemo.Models.Pages.SitePageData'

IPageViewModel<T> -> (CS0535) DefaultPageViewModel<T> does not implement interface member of 'IPageViewModel<T>.Layout' .

Please help me fix this error.


#261492
Sep 02, 2021 10:31
Vote:
 

This looks like it's a base viewmodel for any of the view models in your site.It also looks like maybe IPageViewModel<T> has a restriction to SitePageData which is likely your base page model with base properties. So you'll want change this class (DefaultPageViewModel<T>) from PageData to SitePageData 

Then if you're createing a search page I'd expect the following

  1. SearchPage Model inheriting SitePageData 
  2. SearchPageController passing in SitePageData in the Controller method
  3. SearchPageViewModel inhertiing  DefaultPageViewModel<T> passing SearchPage as the T param
  4. SearchPage View passing in the SearchPageViewModel 

This should all work. Just make sure you're interface and classes generic parameter type restrictions match.

#261497
Sep 02, 2021 11:46
Vote:
 

Also as a point on design, your ViewModel should not be setting properties such as 

CurrentPage = currentPage;
Section = ContentExtensions.GetSection(currentPage.ContentLink);

The viewmodel should be kept clean, those properties should be setup by the controller or ideally a factory/service for your ViewModel generation.

#261498
Sep 02, 2021 11:49
Tapas - Sep 02, 2021 12:43
Is it necessary to create a search page in regards to implementing Episerver Find features.?
Scott Reed - Sep 02, 2021 12:47
Search & Navigation (Formally Find) is just a search platform based on elastic that indexes pages, blocks, media and any IContent. The .NET API is just a code API and can be called anywhere you like. This could be a search page if you're creating a search page or it could be in a header for a quick search, a block or anywhere really where you're searching/surfacing large groups of content.
Tapas - Sep 02, 2021 12:58
While implementing Find, what are things we have to create to include the following features:
Highlighting Search Keyword
Highlighting Best Bets
Handling Stemming
Scott Reed - Sep 02, 2021 13:00
https://world.optimizely.com/documentation/developer-guides/search-navigation/
Tapas - Sep 02, 2021 13:15
Thanks, Scott. 😊
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.