Gravatar for fcote@coveo.com

Question by fcote, Jun 9, 2016 10:15 AM

Creating an Optimized Listing Page that uses Multiple Fields in Coveo for Sitecore using LINQ

Greetings,

We are currently using LINQ queries to create a Listing Page for our Seminars. From a user perspective:

  • On the Listing Page, the user can select different Topic and Type of Seminars
  • Each Topic and Type thus represent a filter that allows the user to refine his search

From a feature perspective (The LINQ query):

  • The Topic and Type field are multi-value fields
  • The LINQ query looks like this: ((@ftopic12345="GUID1") OR (@ftopic12345="GUID2") OR (@ftopic12345="GUID3*"))
  • To get the results from CES, we use a getAllResult() to fetch the entire content of the Index because any item in the Index can contain teh Topic or Type field

At the moment, this feature using getAllResult() is generating a massive amount of queries in the logs and also causes spikes in RAM consumption of the IIS process for the Sitecore CD.

Is there a more optimized way to create such a feature?

Also, is LINQ the only option available to create a Listing Page? Would it be possible and optimized to use the JS Framework to do a listing page?

Gravatar for diego.moretto@xcentium.com

Comment by Diego, Jun 17, 2016 10:00 AM

Any ideas on this one?

1 Reply
Gravatar for flguillemette@coveo.com

Answer by François Lachance-Guillemette, Jun 21, 2016 12:46 PM

Is there a more optimized way to create such a feature?

GetAllResults tries to get every result matching your query from the index, which is expected to be slow and induce heavy-processing since it can contain a lot of documents.

One way to get the Facets for your LINQ query is to call queryable.FacetOn(item => item.FieldForTopic) to select the field you want to fetch facets values for.

You can then call queryable.GetFacets(); which returns a List<FacetCategory> that you can use as data for your facets.

It would be more efficient to query the index with another LINQ expression using the specific topic that the user chose as it will not fetch every result from the index. It is also recommended to add a limit with the Take() method. Here is a simple example:

queryable.Where(item => item.FieldForTopic == CurrentTopicSelectedByUser).Take(10).ToList()

Note that your field (in this case, @ftopic12345) must be configured as a facet for this feature to work correctly (here for more information)

You could also use the JS Framework as it provides the facet component that provides this feature with little configuration out-of-the-box.


Also, is LINQ the only option available to create a Listing Page? Would it be possible and optimized to use the JS Framework to do a listing page?

You could either:

  • Use the JS Framework (see the documentation here for 0.9, bundled with Coveo for Sitecore 3.0)

It contains multiple components to build a search-driven page

  • Use the Coveo for Sitecore implementation (see the documentation here for Coveo for Sitecore 3.0+)

You could make your own copy of the default Coveo Search Page and customize it to your liking, striping down the unwanted components to simply make a listing page.

Ask a question