Gravatar for

Question by fcote, Jan 12, 2015 9:59 AM

How to return fields from a specific collection using the Coveo Search Service

I'm using PerformQuery to return fields specific to a collection (ABCD).

        string searchServiceUrl = Sitecore.Configuration.Settings.GetSetting("ABCD.Search.ServiceEndpoint");
        string[] searchCollections = Sitecore.Configuration.Settings.GetSetting("ABCD.Search.Collections").Split('|');

        SearchService service = new SearchService();
        if (!string.IsNullOrEmpty(searchServiceUrl))
            service.Url = searchServiceUrl;

        QueryParameters queryParams = new QueryParameters();
        queryParams.CollectionNames = searchCollections;
        queryParams.BasicQuery = string.IsNullOrEmpty(query) ? "@uri" : query; //if query is blank, we need a field that every index item has

        RefineByField[] refineByFields = { new RefineByField() { Field = "@SiteSection", Maximum = 30 },
                                           new RefineByField() { Field = "@documentType", Maximum = 30} };
        queryParams.RefineByFields = refineByFields;

        queryParams.NumberOfResults = 1;
        queryParams.FirstResult = 0;

        QueryResults coveoResults = service.PerformQuery(queryParams);

However, the coveoResults.RefineByResults list contains items that are not in the specified collection. Is there a way to limit the RefineByResults to values only in the specified collection ?

1 Reply
Gravatar for

Answer by ronald, Jan 13, 2015 5:11 PM

The RefineByResults values returned by PerformQuery() are normally limited to the specified collections as you wish. Could it possible that the collections supplied by your code would be invalid? That would cause the behavior that your describe.

Ask a question