Numbers and Dates

Sift can also be used for searching numeric and date properties. For these types of fields it is possible to include range searches using the comparison operators. To be able to make use of these operations, you need to inform Sift of the names of the properties that are either numbers or dates. This is done by including the property names in the relevant app settings in the Web.config file.

<appSettings>
	...
    <add key="Sift.DateIndexFields" value="date,releaseDate,eventDateTime"/>
    <add key="Sift.IntegerIndexFields" value="minAttendees,maxAttendees" />
    <add key="Sift.DecimalIndexFields" value="starRating" />
	...
</appSettings>

If you are using Umbraco V9, you can specify the number and date fields within the appsettings.json file.

"Sift": {
    "DateIndexFields": "date,dateTime",
    "IntegerIndexFields": "integer",
    "DecimalIndexFields": "decimal",
    "SortableTextFields": "nodeName,description"
}

If content already exists for these properties then you will need to rebuild the Examine index in the Umbraco back office before they can be used.

Comparison Operators

For both numbers and dates you are able to specify a comparison operator, which will change the results that are returned. By default, the EQ operator is used, so only content with the date or number equal to that provided will be returned in the results. Note, the date part (see below) is assumed to be date, so any time component of the date will be ignored.

The comparison operator can be set by including the data-sift-comparison-operator attribute on the criterion element and setting it to one of the following values.

  • EQ - content with a number/date equal to that provided will be returned.
  • GE - content with a number/date greater than or equal to that provided will be returned.
  • LE - content with a number/date less than or equal to that provided will be returned.
  • GT - content with a number/date greater than that provided will be returned.
  • LT - content with a number/date less than that provided will be returned.
@inherits Umbraco.Web.Mvc.UmbracoViewPage

<h1>Number Range Filter</h1>

<div class="sift"
     data-sift-result-document-type="cinemaCento"
     data-sift-result-partial="_SiftResultsPartialExample">

    <form class="sift-criteria">

        @Html.AntiForgeryToken()

        <label for="fromRating">From Rating</label>
        <input type="text" id="fromRating" name="fromRating"
               class="sift-criterion"
               data-sift-comparison-operator="GE"
               data-sift-match-property="starRating" />
        <p></p>

        <label for="toRating">To Rating</label>
        <input type="text" id="toRating" name="toRating"
               class="sift-criterion"
               data-sift-comparison-operator="LE"
               data-sift-match-property="starRating" />
        <p></p>

        <input type="submit" value="Search" />

    </form>

    <div class="sift-result">
    </div>

</div>

<script src="~/Scripts/sift.js" type="text/javascript"></script>

Date Parts

By default, a date property is assumed to be the date (day, month, year), ignoring any time component. So, 12:15 and 15:42 on the same date would be considered equal. You can change the date part that you would like to compare by adding the date-sift-date-part attribute to the criterion element. This should be set to one of the following values.

  • date - content matching the day, month and year will be returned.
  • datetime - content matching both the date and time will be returned.
  • dayofweek - content matching the day of the week of the date will be returned. Values from 0 to 6 (Sunday to Saturday)
  • dayofmonth - content matching the day of the month of the date will be returned. Values from 1 to 31.
  • month - content matching the month of the date will be returned. Values from 1 to 12.
  • year - content matching the year of the date will be returned.
@inherits Umbraco.Web.Mvc.UmbracoViewPage

<h1>Year Filter</h1>

<div class="sift"
     data-sift-result-document-type="cinemaCento"
     data-sift-result-partial="_SiftResultsPartialExample">

    <form class="sift-criteria">

        @Html.AntiForgeryToken()

        <label for="releaseYear">Release Year</label>
        <input type="text" id="releaseYear" name="releaseYear"
               class="sift-criterion"
               data-sift-match-property="date"
               data-sift-date-part="year" />
        <p></p>

        <input type="submit" value="Search" />

    </form>

    <div class="sift-result">
    </div>

</div>

<script src="~/Scripts/sift.js" type="text/javascript"></script>

Year filter

Date Format

By default, Sift expects the format of dates and times in the format specific to the current culture. Note, this is the culture defined by the server operating system. Sift uses the C# DateTime.TryParse() function with no culture information.

You can explicitly state the format that a date or date/time parameter will be by providing a data-sift-date-format attribute on the criterion element. This should be set to a .NET standard or custom date/time format.

<< Back to User Guide