Content Search Web Part and Event Dates in SharePoint 2013

I’m working on a project with Mike McNett where we have multiple calendars across multiple sites in a site collection.  We need to create a single view where upcoming events can be viewed from one central location.

We started with Content Search Web Part (CSWP) since it can retrieve all calendar events.

So here’s the path we took:

1. Added Content Search Web Part to a page

2. Changed Query from “Recently changed items (System)” to “Items matching a content type (System)”

3. Changed Restrict by app from “Current site” to “Current site collection”

4. Changed Restrict by tag from “Do not restrict on content type” to “Event”

CSWP - BaiscQuery

5. Switched to Advanced Mode

Note: You can change the path the Query text to include all site collections by removing <sitecollection> from the URL.  If you want to include all lists in your farm, remove the path value all together.

ContentTypeId:0x0102* indicates “Event” we selected earlier.

6. Clicked Test Query

In the SEARCH RESULT PREVIEW, all events returned. In our case, 10 results (This includes past, present, and future dates)

CSWP - QueryText1

So far so good.

Since we only wanted future events to return, we started adding a filter.

7. Changed Property filter to:

StartDate>={Today}

In the SEARCH RESULT PREVIEW, Results=0. (There are five (5) events that meet this criteria.)

CSWP - QueryText2

We tried different properties, including EndDate, and everything with the word “Date”, still the SEARCH RESULT PREVIEW, returned 0 or a syntax error.  We checked to make sure that content has been indexed.

Note: Comparing anything with OWSDATE to {Today} gave us a syntax error. (I’ll explain why later.)

Below is the screenshot when comparing AnythingOWSDATE to {Today}.

CSWP - SyntaxError

After a lot of head-scratching, we started looking into Search Schema. (This can be done at a site collection or a farm level.)

In the Managed property, we typed “date” (without the double quotes).  Here’s where we saw OWSDATE is a “Text” type.

A light bulb went off, this is why comparing {Today} to AnythingOWSDATE caused the Syntax error I mentioned earlier. (At least this made sense to me.)

ManagedProperty

8. So we edited the Date00 Property to the following:

8.a Queryable: checked, Retrievable: checked, Refinable: Yes – active, Sortable: Yes – active;

And affter many tries, these are the settings we used:

8.b Mappings to crawled properties:

Include content from the first crawled property that is not empty, based on the specified order

Ows_EventDate

Ows_q_DATE_EventDate

MappingProperties

9. Started a Full Crawl

10. Went back to the CSWP, and added Date00>={Today}….drum rolls….

It worked!!!

The SEARCH RESULT PREVIEW showed five (5) events.

CSWP - QueryText3

We went back and modified the CSWP properties to include the desired settings, and here’s the final result.

CSWP - Results

We hope this helps those who have similar requirements.

21 thoughts on “Content Search Web Part and Event Dates in SharePoint 2013

  1. Jared

    When I try your solution I hit a roadblock when I try to edit the Date00 property, I cannot make any edits. I am a site collection admin so permissions should not be the reason. Any thoughts on why I wouldn’t be able to make changes to the Date00 property?

    1. Jared,

      If you select ‘Schema’ under Search in Site Settings, you’d only see ‘View Property’. Be sure you select ‘Search Schema’ under ‘Site Collection Administration’, and you should be able to map the desired properties.

  2. Pingback: Developing for SharePoint 2013 | Shawn Tucker

  3. Manu

    THANK YOU so much ! 2 days of digging over the net to find your perfect article describing the solution in details to this really annoying problem…
    Thanks again Veenus !

  4. Geoffrey

    Quick question, does it work correctly? We have an issue that {Today} in search is GMT. But the date we enter is GMT +1 (Belgium). So when we say that an item should be seen tomorrow in search, actually it is already today.

    These are the settings:
    – today is 14/11/2013
    – startDate is 15/11/2013
    – in our query we say “{Today} >= startDate”
    – only when query is correct, the item would be visible.
    The item would be visible from 15/11/2013, but it’s already visible today..
    – Why is it visible?
    We live in GMT +1, search is at GMT, so at 14/11/2013 23:00 the item would be visible (our date minus 1 hour).
    But our startDate has no time field, it’s only a date, so the time is discarded and the item is visible at 14/11/2013…

    Have you got the same issues with your timezone?

  5. This works great! Thank you.

    I just want to state that this will work for all event EXCEPT recurring event. After, trying this i noticed that all the events will works as explained except recurring one. After checking the results using the Search Query Tools, realized that Ows_EventDate and Ows_q_DATE_EventDate are the start date of the recurring series of event and not in that case the start date of the event.

  6. Shami

    This worked wonders Thanks. If you are sorting announcements by expiry date, you use the following mappings:
    Ows_Expires
    Ows_q_DATE_Expires

  7. Tim

    Hello Veenus,

    I do not have the mapping for Ows_EventDate in my Search Schema. Do I have to create this? I would have thought it was OTB.

    Thanks for your comment.
    Tim

  8. Pingback: Where Is Search Settings And Indexed Content In Sharepoint | Coojoyka

  9. James Anderson

    Wondering if changing that variable at th site collection level would affect all of the other sites in the collection – we have over 100 sites. Could you advise if that is the case. I would think that only the sites that utilize that field but not sure how to check that

Leave a reply to Shami Cancel reply