Sunday, April 30, 2017

Coveo Sorting Part 3

Hey There!

This time soon enough, I really wanted to complete my thoughts on Coveo sorting.  We so far learnt two main things from the previous posts.  How to accomplish Coveo Sorting on a typical custom coveo rendering on a sortable field and how to make sorting work when you have Coveo Tabs that list the results out.

Next step, we will learn how we can achieve the same on Java script, there are few situations where this would come in handy.  In my example, what I was trying to do is apply Coveo Sorting on a computed field.  We are all aware that a computed field is in memory and hence we do not have a GUID we could use to work around the active issue which was present on adding default sort order to Custom Coveo rendering.  With out GUID, the sorting will not work on the rendering due to the issue, this would not be a problem if you are using latest version of Coveo, but, in our case we had no option, but, to battle this challenge.

A option that you could achieve sorting via javascript was the key to successfully getting the sort to work on a sortable computed field.

Below are few resources that helped me get started.

https://answers.coveo.com/questions/1658/how-can-i-set-the-default-sort-order-using-the-jav.html

Below is the code snippet that I plugged in my Custom Coveo View which needed the default sort order to be set


Do note that you have to set this in function, so, the properties get set properly and applied on XHR request.  Mission accomplished.

Now, I covered all the ways that we applied Coveo sorting on different style components.  Another cool thing I noticed if it helps some one is that even if your field is of type Date, do not use that option for Default Sort Order.  Just use Field as your type and all is working as expected.

Happy Problem Solving people.   Enjoy your rest of the weekend!  I am actually blogging from SF airport after hogging on organic veggie quesadilla.   ;)




Saturday, April 29, 2017

Coveo Sorting Part 2

Hi There!

Welcome back again to my three part series of sorting with Coveo.
This time, we look more deeper in to how to make your tabs have a sorted list, below are few easy steps you will need to do make sorting work on Coveo tabs.


  1. Ensure you have a Sort Component added to your presentation.  If you do not do this step, the Default sort order you would enter on Coveo Tab Component would not work and could also lead to exceptions on console.   Read more details about Coveo Sort Component here if curious https://developers.coveo.com/display/public/JsSearch/Sort+Component;jsessionid=6D194F8CCE1AC89DDB1B92C50E446CFF
  2. See screenshot below to see how a Coveo Custom Sort View would look like. 
  3. Ensure you plug in the same Default Sort Properties you have defined on your Coveo Custom Tab, which means you should match Sort Order, Field and Order exactly to same values on both your components for the sort to work fine.  
 Shown below is the view of Custom Sort View that goes hand in hand with Coveo Tab 



Shown below is the Sort Order Default defition on Coveo Sort View 

Shown below is the Default Sort order properties on Coveo Custom  Tab view.  Notice how they are exactly the same, except that on the below we have to use GUID to overcome an existing bug on version of Coveo we are using. 


That is it, after this steps, publish your changes and go to the page where you have coveo renderings with tabs, you will now see two things.  One, your sort options will be appended to the URL by default and you can also confirm the parameters passed on the Network tab in the XHR request. 
If all is well, you now have your sort order working on Coveo Custom tabs. 














Monday, April 17, 2017

Coveo Sorting Part 1 - On the Rendering

Coveo provides lot of tools and places where you could provide a sort mechanism.  First things first, sort is the most important piece that goes with listing.  If the listing of search results that you are showing to end user are not sorted per either business drive or more power to user where the user could actually select how he/she wants to sort their results is the key for the user to be able to find what they are looking for. 

Steps to get sorting working 

  1. Firstly define which field either sitecore or computed field you are going to use as a sort field.
  2. Note that OOTB, not all fields are sortable and you will need to configure and ensure that the field you are going to base the sort on is Coveo sortable.  For example - string fields are not inherently sortable while number fields are. 
  3. If the field you decided as sort field is not inherently sortable, configure it per directions listed here by Coveo documentation and rebuild your indexes.
    https://developers.coveo.com/display/public/SitecoreV4/Making+a+Sitecore+Field+Sortable
  4. After this step, always do a sanity check on admin tool that this field has a checkbox for sortable. 

Now that you have basic configuration ready, the next step is fairly simple.  Go to presentation on the template which has your coveo rendering on which you would like to apply sort.  Pull open the properties of Coveo rendering and you will see a Default Sort order section like below.  Input three parameters it looks for - 

  • Default Sort Type - Field | Date | Relevancy - I found Field and Date to be extremely useful 
  • Default Sort Direction - Ascending | Descending 
  • Default Sort Field - You have a pick list provided by Coveo which is a searchbox where you can type and find the sortable field you are looking for.  We are using December 2016 version of Coveo which has an active bug, so, we had to use GUID as a workaround instead of using field picker.   See an example on the screenshot below 

After you pick everything coveo is expecting, give it a spin -  Go to the page where this rendering exists and check what is happening on the query request.  You should see the below two populate with the field you picked and direction you mentioned on default sort order.  If you do not see this then the sort would not be working and you will have to debug further.  Couple times, it is due to presentation being overridden, so try resetting it before you panic. 😱




Now, all this works beautifully if you have just the basic Coveo custom rendering on your page.  Now, how will you make sort work with tabs, how about facet ordering.  What happens when you have both going.  How about if you need to apply sort ordering on a custom or computed field.  I will post details about these scenarios soon.  More to come later....Sorting O what fun. 😆

Happy Sitecoring and have fun every one.  Between, on a side note, last month I presented at LASUG about Coveo, if you wanna to check it out here is the link to youtube video.  Post your comments.