Is there a way to get Coveo equivalent field name helper such as ToCoveoFieldName in CoveoProcessParsedRestResponseArgs pipeline code? Basically I am trying to see if a property of SearchResult item is of certain value and based on it create a new property.

var db = NewStuff();

foreach (SearchResult result in response.Results)
    result["isNew"] = "201612" == result.Raw["fyearandmonth11031"].ToString();

The field fyearandmonth11031 needs to be translated from Sitecore field (YearAndMonth) to a Coveo field name.

  • 2
    I'm voting to close this question as off-topic because it's not sitecore related at all and only Coveo related. It should be asked on answers.coveo.com instead. – Jean-François L'Heureux Dec 7 '16 at 12:38
  • Yet when we talk to Coveo, they recommended to ask it here. Although I think this is still valid since the helper in question is for Coveo for Sitecore module. – xoail Dec 7 '16 at 12:42
  • Can you tell me who told you to ask it here please? – Jean-François L'Heureux Dec 7 '16 at 13:41

What you are looking for is most likely IFieldNameTranslator. You need a SitecoreHelper to get an instance for a specific index.

Since the pipeline can be run without a context, you have to validate whether the CurrentContextItem is null before trying to convert it in an indexable.

The following code should work for your use case:

ISitecoreHelper sitecoreHelper = new SitecoreHelper();
IFieldHelper translator = new FieldHelper();
if (p_Args.CurrentContextItem != null) {
    bool usePrefix = false;
    IIndexable indexable = p_Args.CurrentContextItem.ToIndexable();
    ISearchIndex index = m_SitecoreHelper.GetSearchIndex(indexable);
    IFieldNameTranslator translator = m_SitecoreHelper.GetFieldNameTranslator(index);
    string translatedField = translator.ToCoveoFieldName(indexable, "field", usePrefix);
    // Use that translated field here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.