Yes, you can use a custom date field.
Sorting
Sorting can also be done directly using the parameters sort=published&sortdir=desc with the following query parameters:
descending order
https://localhost:8443/search/index.html&query=*&sort=published&sortdir=desc&public=true
ascending order
https://localhost:8443/search/index.html&query=*&sort=published&sortdir=asc&public=true
Date as facet field
Note: If you want to use the custom date field only for sort then please ignore the below section. If you want the date field to be displayed as facet filter then refer the details below:
For example, if you want to use a published date as a facet field with the following meta tag in your HTML page:
<meta name="published" content="2014-03-15T01:50:58"/>
or
<meta name="published" content="2014-03-15"/>
Note: The format of date should be as above
1. You will need to add the following mapping or data field using collection Data Fileds Tab.
The collection mapping file can be found within the /ROOT/WEB-INF/mappings/collections folder.
"published":{
"type": "date",
"store": true
},
2. Once configured clear and reindex the collection to index the web pages:
3. The user can filter the date directly
4. The search results can be filtered based on a specified range of this date field “published” as given below:
https://localhost:8443/search/index.html&query=*&sort=published&sortdir=desc&public=true&facet.field=published&f.published.range=[*TO2013-09-18T01:50:58]&f.published.filter=[*TO2013-08-18T01:50:58]
If you are using the following meta tag for date without the time information:
<meta name="published" content="2013-09-12"/>
Use the URL below to get the date range:
Mapping custom date format
If your date field has a custom date format it has to be mapped in ../ROOT/WEB-INF/mapping.json
For example if your meta date is as below
<meta name="published" content="2014-03-12 01:50:58"/>
Mapping to be provided in mapping.json
"published":
{
"type": "date",
"store": true,
"format": "yyyy-MM-dd HH:mm:ss"
},
Searching
If the custom date has to appear in search results in regular search then it is required to make necessary changes to ../ROOT/stylesheets/default.xsl
Related Topics:
Using custom date fields as facet filter
How to give date format if there are empty values for the same in indexed document?
Comments
2 comments
I found that using the format:
kept the page from being indexed.
While using the format
worked as expected.
This article seems to state that both formats are acceptable. Is this a bug, or a mistake in this article?
In reply to Robert Dennis:
I had the same experience using version 8.5.1 but found that treating the published value as a string in the mapping.json resolved the issue.
Please sign in to leave a comment.