7

I have a website with Sitecore.NET 7.2 (rev. 160123). Using facets I see I can search for different things, and I have a few filters. However, I didn't manage to be able to filter for a date field on my search.

For example, this two date fields:

enter image description here

They are not found on my search: enter image description here

I tried using the raw value (20180208T000000) but no luck either.

So, how can I filter the Content Editor search by a date field?

Basically, what I want is to search (filter) by a specific field, which turns out to be a date. Why does this not work with dates by default on Sitecore search?

  • 1
    Does searching by any field work in your instance? – DougCouto Feb 17 '17 at 14:55
  • @DougCouto Yes, other fields that are not dates work. I have to search by the raw value tough – SysDragon Feb 17 '17 at 16:16
5

In the past I found that the only way I can do date search was to use the default start field from search field types.

enter image description here

As you can see that it has the Start field and some date value and it does return the results. Also you can use the END date field there.

Combination of those 2 date might help you achieve what you are looking for.

You have another option there to Search by field values. Hopefully that will help you.

Updated Answer

After reading comments I thought to provide a full updated answer than just hint. I spent some time and now I wrote this blog post here on how to do this: How to use Sitecore Search for Date fields?

So all you need to do is following:

  • Go to the /sitecore/system/Settings/Buckets/Search Types/Start Date
  • Copy paste it to /sitecore/system/Settings/Buckets/Search Types/User Defined
  • Rename it to match it to your date field. In my example I am going to make it to Resource Spotlight Start Date
  • Update below values in the field to make sure it searched for your field and not the start field.

enter image description here

In the above image

1 is to change the icon in the search interface.

2 is must for changing it to your desired field name. It does not need to be your exact field name but something unique to indicate user.

3 is for field. Here you should put your actual field name. If you have doubts on what is your exact field name then open the LUKE and then find your field’s name. In my instance my field name under template was Resource Spotlight Start Date but under LUKE it was resource_spotlight_start_date.

4 is for control type parameters and that can be same as your name too.

5 is for Displaying text for your user.

Once you do this you will see nice shiny field created by you in the search interface.

enter image description here

Now when you click it you will observe that it gives you calendar search.

enter image description here

But if you select it and hit run it won't give you any results. Why? Well you need to do this one last step: go to your app_config/include and find the file Sitecore.ContentSearch.Lucene.DefaultIndexConfiguration.config. Open the file and add this line

<field fieldName=”resource_spotlight_start_date” storageType=”YES” indexType=”TOKENIZED” vectorType=”NO” boost=”1f” type=”System.DateTime” format=”yyyyMMddTHHmmZ” settingType=”Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider”>

Under the <fieldNames> section. This ensures that your master index and lucene consider your newly created field to be date searchable. Once you add this close your config, rebuild indexes and search again from step 11. Boom you will see below results.

enter image description here

To answer the comment I needed to update the actual answer.

So when I was looking into search logs while I used the filtering by field value for date field and compared it with the start date field I found below:

For search by field:

 +_datasource:sitecore +(+_latestversion:1 +(+_path:433f55f1b8cd4254ad0e43d221110b77 +resource_spotlight_start_date:"20170201t050000000z 20170202t045959000z"))

for search by date

+_datasource:sitecore +(+_latestversion:1 +(+_path:433f55f1b8cd4254ad0e43d221110b77 +__smallcreateddate:[20170201t0500z TO 99991231t0459z]))

I think Sitecore was comparing it as string value then the actual date value and that is where adding the field to the Lucene config as date value started making it treating as date value.

One thing I have not tried is just updated the Lucene file but don't create the custom search field and see if you can find the results.

| improve this answer | |
  • No sorry, I thought it was clear on the question. I want to search (filter) by a specific field, which turns out to be a date, and is not one of the two you mention – SysDragon Feb 20 '17 at 10:52
  • @SysDragon i updated my answer now, that is surely going to help you. So hopefully no more vote down :) – Mrunal Daftari Feb 20 '17 at 20:03
  • Thank you, that is useful. Do you know why filtering by field value doesn't work with dates by default on Sitecore search? – SysDragon Feb 21 '17 at 10:59
  • @SysDragon explanation is too long so updating the answer itself – Mrunal Daftari Feb 21 '17 at 15:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.