Gravatar for jwilliams@captechconsulting.com

Question by jthirus, Jul 5, 2016 3:37 PM

Using Linq's OrderByDescending on a Date

Hi,

I'm trying to sort based on a date field in our Sitecore items and am having issues. The items are showing up with a random set in a random order. The code is as follows:

        using (var context = index.CreateSearchContext())
        {
            var queryable = context.GetQueryable<BlogPostModel>();
            var query = queryable
                .Where(x => x.Paths.Contains(pathId))
                .Where(x => x.WorkflowStateID == lookupWorkstate)
                .OrderByDescending(x => x.PublishDate)
                .Skip(id * size)
                .Take(size);

            foreach (var item in query)
            {
                SitecoreContext.Map(item);
                blogs.Add(item);
            }

        }

The field is configured in our search index:

< fieldType fieldName="Publish Date" isSortable="true" settingType="Coveo.Framework.Configuration.FieldConfiguration, Coveo.Framework" />

It shows up in the field set for my index as a Date/time.

Is this something we are doing wrong or does Coveo not support OrderByDescending?

Thanks.

Sitecore version: 7.5 (rev. 141003) Coveo version: 7.0 x64 Build 8225.0

0 Reply
Ask a question