Modifying Coveo’s default MVC search for Sitecore

I recently had the opportunity to dive into Coveo search for Sitecore.  This article assumes that you have installed Coveo successfully, have it working against Sitecore, and are wondering what is next.

Coveo provides an out of box MVC solution to start from.  You can add this to your content tree, publish, and assuming you got everything working, you should see a search.

insertcoveo

Take a look at the presentation layer for this new item.  You will find two views:

coveopresentation

The CSHTML files for these are stored at /Views/Coveo/SearchBoxView.cshtml and /Views/Coveo/SearchBoxViewResources.cshtml.  The Coveo Search View Resources is primarily links to some rather large JavaScript files.  This is the core of the functionality.

Now the other view, Coveo Search View, is where you would make modifications to the html.  I found that there are two primary elements / considerations to make when looking at this view.

The first would be the configuration.  You will see a bunch of references to the model like this:

coveorenderingparametermodel

This is all configuration you can change on the rendering parameter, and considering this works with a rather large js file, I would be real careful about making modifications here.  Here is an example of some (its a big list) of the configurations in the rendering parameter:

coveorenderparameters

The second element in this file starts with the div class of CoveoResultList.  This houses the majority of html.  This is where you can modify how search displays and what fields to display.  For example the div class “coveo-result-row” holds a lot of these changes you can make:

coveo-result-row

The ToCoveoFieldName method takes a Sitecore field and translates it to field name stored in the Coveo search index.  In other words, assuming the Sitecore field lives in your index, you should be able to add it here.

Overall I think this is a very simple approach to getting started with a Coveo search page in Sitecore.  With that said, this is not the only solution.  You can always make your own custom search to work with Coveo.  However I would strongly suggest you give this a good try before going to a custom solution.  There is a lot of configuration you can make between the rendering parameter and the html on this page to fit your needs.  A certainly a lot of stuff working behind the scenes in the JavaScript files that I wouldn’t take lightly when considering custom.  For more specific information and to dive deeper, please review Coveo’s Developer Docs.

And as always don’t work from the source.  Make copies of the rendering views before you start heavily modifying.  There is nothing fun about pulling your hair out digging for originals while your very cold rooster mocks you.

rooster.PNG

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s