Gravatar for

Question by cmgutmanis, Mar 5, 2015 6:14 PM

coveo for sitecore: no results for faceted search


I am trying to retrieve facet results from a search using the coveo webservice and soap api. I am able to get expected results using the exact syntax in the tutorial, but as soon as I change the FieldName parameter, I receive no results. To further confuse things, if I use the built-in Sitecore.ContentSearch.Linq methods, facets seem to work as expected (this is not an option for the code; it was more a verification that these values were in fact being tracked.)

This will return facets and counts: var results = context.GetQueryable().Where(x =>.Content.Contains(searchQuery.ToLower())).FacetOn(y => y["_smorch"]).GetFacets();

This returns NULL in the result.GroupByResults.DisplayValues field. When I did it with "@sysfiletype" as the FieldName, it behaved as expected (returning facets and counts).

        var facet = new GroupByField();
        facet.FieldName = "_smorch";
        facet.MaxNumberOfGroupByResults = 8;
        facet.SortCriteria = GroupBySortCriteria.SortByOccurrence;
        query.GroupByFields = new GroupByFieldV();

        var results = service.ExecuteQuery(searchSession, query);

Here is my smorch configuration:

fieldType fieldName="_smorch" isFacet="true" settingType="Coveo.Framework.Configuration.FieldConfiguration, Coveo.Framework" 

field fieldName="_smorch" type="MyProject.Web.SearchIndices.SmorchField, MyProject.Shared.Sc.Web" returnType="System.String"

Any help will be greatly appreciated.

1 Reply
Gravatar for

Answer by Luc Bergeron, Mar 6, 2015 8:11 AM

I think you have a field name translation issue here. If I understand correctly, you used Coveo for Sitecore to index the documents. In that case, the Sitecore field names are translated. The field name "_smorch" in Sitecore will look like "fz95xsmorch12345" in CES.

You should check the field set in the CES Admin Tool and see what the field name is. The field metadata will be "_smorch". Also, the field name changes depending on the database (core, master, web). So you may want to scope your search query to return only results from one database at a time.

Let me know how it goes

Gravatar for

Comment by cmgutmanis, Mar 6, 2015 10:12 AM

So this looks like it partially resolved the issue, thanks. Is there a way to either anticipate or (preferably) control how CES translates the field names? I am fine with hardcoding the value here for local development, but if this name is going to change when I move the project through environments, I need to somehow be able anticipate this.

Otherwise, is there a hook that allows you to access the CES translated field name from the Sitecore field name? If CES is going to translate, this would be a perfect solution. Thanks again.

Gravatar for

Comment by Luc Bergeron, Mar 6, 2015 10:29 AM

The best way to translate the field names is to find the index and then use its FieldNameTranslator property. The code will look like this:

var index = ContentSearchManager.GetIndex("sitecore_master_index");
string translatedFieldName = index.FieldNameTranslator.GetIndexFieldName("_smorch");

On my Sitecore instance, it returns "@fz95xsmorch6210"

Ask a question