Experiment with Ease

background experiment

When you are stuck in a problem, do not get scared to experiment!  You might be successful at solving the problem or not, but, every time you let go of your fears and experiment, you end up learning some thing new every single time.

On one of our heavy custom implementation with Coveo due to super complex architecture which uses Web forms, I exactly had to to that.  Funny story,  I am so used to MVC that literally when I dream of a solution I do so, you guessed it right in MVC. 🙂

So, we had a situation where we need to use Coveo Search Box component on shared content which could span across multiple sites and hence the URL should not be based on item and should rather be based on context.  While looking for a solution I bumped in to the below Q&A, but, the solution was for MVC.

https://answers.coveo.com/questions/9939/how-to-configure-coveo-search-box-view-rendering-o.html

I wanted to see how I can implement this on web forms and searched to find a parallel solve for the same with no luck.   So, the only option left was to experiment to see if it will actually work.

To prove my theory, I opened up couple Coveo dll’s to see how I can use Inheritance to swap the Model.  Turns out, it is possible to swap the Model out with few extra steps than MVC.  Do note, that in MVC the model swapping could be done on the View Rendering item to use your custom coveo search box model instead of OOTB coveo model.

So, below are the extra steps for web forms to achieve what is noted for MVC on the Q&A.  We tried these below and it works perfectly alright. 🙂 Rest of the steps should be similar to what is noted on the Q&A noted above, so, I will not repeat the awesome steps that Jean-François L’Heureux provided.

  1. In your duplicated Custom Coveo Search Box sublayout, let us call it CustomCoveoSearchBox.ascx change the inherits to your own custom class
    Inherits=”Coveo.UI.CoveoSearchbox”
    Would become
    Inherits=”ProjectName.Search.Extensions.CustomCoveoSearchbox”
    Use your best judgement or project guidelines to decide a namespace for your custom coveo search box class. 🙂
  2. Next step is to pass in your CustomSearchboxModel (a new custom class that would inherit SearchboxModel) in the OnLoad override of your CustomCoveoSearchBox  class.   Your CustomSearchboxModel would provide your new implementation for GetSearchPageUrl() that would have logic to determine the URL based on site context and other decision factors.

A quick screenshot from Dotpeek of Coveo.UI that helped me with the decisions.

CoveoSearchModel

Hope this helps some one battling the situation on web forms based Sitecore instance.