Gravatar for mkrimi@absolunet.com

Question by mohamed krimi, Oct 27, 2014 12:00 PM

Facets based on foreign keys

Hi guys, I have Template called ''ListItem'' that contain Title and Value fields. In the other hand, I have Template called ''Program'' that has Multilist field ''Themes'' that point to ListItem Themes source. I created a new facet based on the field "Themes". The facet display the GUID of my Theme Items.
So I try to use facets based on foreign Keys. I setup Lookup field Template as "ListItem" and Select Field as "Title". as mentionned here : https://developers.coveo.com/display/public/SC201409/Adding+Facets+Based+on+Foreign+Keys Then i added the config as mentionned here : https://developers.coveo.com/display/public/SC201409/Using+the+Sitecore+Search+Provider

I would like to know : 1 - If is it required to setup manually the Foreign Key Search Provider Configuration or it should be done directly by Coveo for Sitecore ? 2- Wich Sitecore List Type the Foreign Key feature should support ? 3- Is there anything to debug or test what does not work as expected with foreign key ?

I still have GUID Displayed. Thank you .

3 Replies
Gravatar for vseguin@coveo.com

Answer by Vincent Séguin, Oct 27, 2014 12:57 PM

Hi,

We highly recommand to use ComputedFIelds instead of foreign keys. For instance, described here :

https://developers.coveo.com/display/SC201410/Creating+a+Computed+Field+for+a+Referenced+Item

And then point your facet to this computed field. It will make sure to take account of the current language of the item.

Gravatar for mkrimi@absolunet.com

Answer by mohamed krimi, Oct 27, 2014 3:56 PM

I tried to use this approach instead using foreign key. The facet load but it is empty. When I debug I notice that my ComputedField class is called. but i'm not sure why facet is empty.

In Admin CES, I can see the field in Configuration > Fields. But I can't see the Field into the Index Document ? is something missing ?

Gravatar for vseguin@coveo.com

Comment by Vincent Séguin, Oct 27, 2014 3:58 PM

It can be a lot of things… Did you reindex? Do you have any errors in your Sitecore logs while reindexing?

Gravatar for mkrimi@absolunet.com

Answer by mohamed krimi, Oct 27, 2014 4:24 PM

To keep it simple and easy to to test, here is my C# ComputedField Class :

namespace Project.Coveo.Custom.ComputedFields { public class MilieuxdApplicationComputedField : IComputedIndexField { /// public string FieldName { get; set; } /// public string ReturnType { get; set; }

    /// <inheritdoc />
    public object ComputeFieldValue(IIndexable p_Indexable)
    {
        IIndexableDataField milieuxdApplication = p_Indexable.GetFieldByName("MilieuxdApplication");
        if (milieuxdApplication != null)
        {
            Item milieudApplicationTest = Context.ContentDatabase.GetItem(new ID("5525B18D-E811-4D83-9CD7-A13D86E6CE0C"));
            return milieudApplicationTest.Fields["Title"];
        }
        return null;
    }
}

}

This function should return the same title everytime when called. In my Coveo.SearchProvider.config i added : Project.Coveo.Custom.ComputedFields.MilieuxdApplicationComputedField, Project.Coveo.Custom

Then I rebuild the index, and no exception in Sitecore Log files.

Gravatar for vseguin@coveo.com

Comment by Vincent Séguin, Oct 27, 2014 4:27 PM

Is it possible that the p_Indexable.GetFieldByName("MilieuxdApplication"); never returns an IIndexableDataField? Have you tried stepping in the code to see if it actually returns something?

Gravatar for mkrimi@absolunet.com

Comment by mohamed krimi, Oct 27, 2014 4:30 PM

I confirm in debug mode the function is called when indexing and it returns the right title.

Gravatar for vseguin@coveo.com

Comment by Vincent Séguin, Oct 27, 2014 7:30 PM

In that case, i suggest you open a Support ticket, it will probably be more efficient to troubleshoot it directly with you.

Ask a question