Gravatar for

Question by sohel, Jul 14, 2015 7:34 PM

ContentSearchManager Issue

Unable to query Coveo indexes through Sitecore.ContentSearch. Code below returns null. If no where clause is specified, returns 0. Any ideas?

Test code:

public static string GetSitecoreItem(string field, string value)
    var index = ContentSearchManager.GetIndex(IndexNameMaster);
    using (var context = index.CreateSearchContext())
        var result = context.GetQueryable<SearchResultItem>().FirstOrDefault(i => i[field].Equals(value));
        return result != null ? result.ItemId.ToString() : string.Empty;
Gravatar for

Comment by Sébastien Belzile, Jul 15, 2015 8:28 AM

Hum, I tried it here and it worked…

Are you sure your query returns something?

What is the generated query in the Coveo console? Could you try it by hand in the Index Browser?

What is your Coveo for Sitecore/Sitecore version?

1 Reply
Gravatar for

Answer by Jean-François L'Heureux, Jul 15, 2015 9:54 AM

You say that it returns no results even without the FirstOrDefault part of your LINQ expression.

This would mean that you have 0 indexed documents in your master index.

Did you check in the Coveo Index Browser to see the actual indexed documents? Do they have special permissions on them? Maybe the user which executes the query doesn't have access to the documents? It can be a lot of things…

Gravatar for

Comment by sohel, Jul 15, 2015 10:35 AM

I do see there are indexed items for the right index. Could this be permissions issue? I ran Coveo Diagnostics page and everything came out fine.

Gravatar for

Comment by Jean-François L'Heureux, Jul 15, 2015 10:44 AM

A permission issue would not be in the Coveo Diagnostic Page. It can be determined by the user who executes the search query and the permissions on the indexed documents in the Index Browser.

On the CES server, open the "CES Console" from the start menu. Then execute the LINQ query. You will see the search query and the user executing it in the CES console.

Then, execute the same query in the Index Browser. On one of the search result, click the "Details" link under it and click the "Permissions" tab to see the effective permissions on the document.

Gravatar for

Comment by sohel, Jul 15, 2015 11:48 AM

I do not see any Permissions being set on the indexed documents. And when I perform Linq query I see it is making requests as ADDomain\ADUser…. How can I link this user to the index?

Gravatar for

Comment by Jean-François L'Heureux, Jul 15, 2015 1:56 PM

Hi Sohel,

The user executing the search query should be the currently logged Sitecore user or the Sitecore website domain anonymous user normally.

Can you re-execute the test while the CES Console is opened. Then, double-click on the "Query … performed by … [Security provider name]. … seconds." line in the CES Console and copy the highlighted text. Then, close the CES Console or press the [Esc] key on your keyboard to resume automatic scrolling.

Paste the text here as a comment.

Gravatar for

Comment by sohel, Jul 15, 2015 6:30 PM

7/15/2015 6:41:25 PM | Query @uri performed by DOMAIN\coveouser. 0 results in 0.01 seconds.

I should mention that I am trying to index my local dev environment sitecore with CES (running on remote server).

Ask a question