Gravatar for

Question by DEEPTHI KATTA, Nov 30, 2016 7:44 PM

Read a Field from SearchResultItem on Coveo Search Context

Hi There,

The below issue happens intermittently.

So, when ever the deployment is partial or indexes are not available for some reason. So, basically a rebuild of indexes fixes the issue. But, I am curious if I am doing something wrong?

I get the below error - "Object reference error not set to instance on Sitecore Content Search GetField("Field Name")

Doing something like below -

using (var context = ContentSearchManager.GetIndex("Coveo Index Name based on DB").CreateSearchContext())
    var listofMatchedItems = context.GetQueryable<SearchResultItem>().Where(i => (i.TemplateId == xyz) && (i.Paths.Contains(xyzID))).ToList();

    if (listofMatchedItems != null && listofMatchedItems.Any())
        var maxOfMinFields = listofMatchedItems.Where(e => e.GetField("Sitecore Field Name") != null && !string.IsNullOrWhiteSpace(e.GetField("Minimum Neighborhood Price").Value))
                                               .SelectMany(e => new[] { long.Parse(e.GetField("Sitecore Field Name For Price").Value) }).Max();

It errors out on line above on Linq query - very intermittent and rebuild fixes it.

Just to confirm, I should be passing Sitecore Field Name of my interest on e.GetField() method correct? Or I need to pass lower case corresponding coveo field name? Is this reason why it errors out, I still can not understand why GetField would error out on a field that I know for sure exists on Sitecore DB.

Let me know what would be best practice here.

I am thinking to add in try/catch up here - is there is way to not display Coveo components on UI if this method error's out?

Gravatar for

Comment by Jean-François L'Heureux, Dec 1, 2016 6:06 AM

From my experience, you're doing everything correctly and it shouldn't throw that error. Can you please specify which release of Coveo for Sitecore are you using and your complete CES and Coveo Search API versions too, if any.

Gravatar for

Comment by DEEPTHI KATTA, Dec 2, 2016 5:04 PM

Coveo October release of all components Sitecore version 8.1, Update 2

Let me know if you need anything else

Gravatar for

Comment by DEEPTHI KATTA, Dec 8, 2016 7:46 PM

Hi there,

we still get the errors when indexes are rebuilding, did not build properly or something of that sort.

Gravatar for

Comment by Jean-François L'Heureux, Dec 9, 2016 9:29 AM

I recommend you to open a support ticket.

0 Reply
Ask a question