Gravatar for

Question by ppande, Jan 26, 2015 5:08 PM

Search by Display Name

How do I use the Search API to search based on DisplayName? Here's how I'm searching based on item name:

       ISearchIndex index = ContentSearchManager.GetIndex("Coveo_web_index");

        using (var context = index.CreateSearchContext())
            var results = context.GetQueryable<SearchResultItem>().Where(item => item.Name == "some name");


Also, I was wondering how is the display name field getting indexed, when by default it's added in the

2 Replies
Gravatar for

Answer by Jean-François L'Heureux, Jan 26, 2015 5:22 PM

The display name field is not in the excluded fields list by default. It is in the fieldMap fieldNames raw:AddFieldByFieldName section:

<fieldNames hint="raw:AddFieldByFieldName">
    <fieldType fieldName="_displayname" isFacet="true" settingType="Coveo.Framework.Configuration.FieldConfiguration, Coveo.Framework" />

To use it in your filters, you can use the field indexer like this:

context.GetQueryable<SearchResultItem>().Where(item => item["_displayname"] == "some display name");

But an even better way to get it is to derive a class from SearchResultItem like this:

public class MySearchResultItem : SearchResultItem
    public string DisplayName { get; set; }

And do your query with your result type:

context.GetQueryable<MySearchResultItem>().Where(item => item.DisplayName == "some display name");
Gravatar for

Comment by ppande, Jan 29, 2015 4:13 PM

is that one underscore or two. I tried this and it's not giving me any results back. How can I test LINQ queries for Coveo? Also, is there a way to look at which fields are available for me to search on?

Is there any other way to go about a query other than LINQ?


Gravatar for

Comment by ppande, Jan 29, 2015 11:11 PM

One more thing.. when I try to re-index the site, I get an error now. I didn't use to get this before.

Job started: IndexUpdateIndexName=Coveowebindex|#Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ServiceModel.FaultException`1[System.ServiceModel.ExceptionDetail]: The requested operation cannot be performed in read-only mode.

Gravatar for

Comment by Jean-François L'Heureux, Jan 30, 2015 9:24 AM

This is because your CES index has switched to read-only mode and cannot index more documents. This may be caused by a manual action or not enough disk space on the index drive. Open the CES Adminstration Tool website to switch to read-write mode.

Gravatar for

Answer by Vincent Séguin, Jan 26, 2015 5:11 PM


If your SearchResultItem has a DisplayName property, you could use that, or derive from it to add this property. Coveo indexes this property by default, even if it's in the excluded fields.

Ask a question