2

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.

3
  • 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. Commented Dec 7, 2016 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
    Commented Dec 7, 2016 at 12:42
  • Can you tell me who told you to ask it here please? Commented Dec 7, 2016 at 13:41

1 Answer 1

4

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 and acknowledge you have read our privacy policy.

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