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.

Advertisements