Can I use my own field for a custom date, and use it for sorting and display in results?

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

http://localhost:8080/searchblox/servlet/SearchServlet?facet=on&query=*&sort=published&sortdir=desc&xsl=xml

ascending order

http://localhost:8080/searchblox/servlet/SearchServlet?facet=on&query=*&sort=published&sortdir=asc&xsl=xml

Date as facet field

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 to the mapping.json file found within the /searchblox/WEB-INF folder, and then create a new collection to index the web pages:

"published":{
"type":"date",
"store":"yes",
"include_in_all":"false"
},

2. Restart SearchBlox, delete, recreate and index the collection

3. The user can filter the date directly

http://localhost:8080/searchblox/servlet/SearchServlet?facet=on&query=test&facet.field=published&f.published.filter=2014-03-15&xsl=xml

4. The search results can be filtered based on a specified range of this date field “published” using the URL below:

http://localhost:8080/searchblox/servlet/SearchServlet?facet=on&query=test&facet.field=published&f.published.range=[*TO2013-09-18T01:50:58]&f.published.filter=[*TO2013-08-18T01:50:58]&xsl=xml

You can also use 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:

http://localhost:8080/searchblox/servlet/SearchServlet?facet=on&query=test&facet.field=published&f.published.range=[*TO2013-08-18]&f.published.filter=[*TO2013-10-18]&xsl=xml

Mapping custom date format

If your date field has  a custom date format it has to be mapped in ../searchblox/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":"yes",

"include_in_all":"false",

"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 ../searchblox/stylesheets/default.xsl 

If the custom date has to appear in search results in faceted search (version 8.6.9) then it is required to modify the file in webapps\searchblox\plugindate\views\component-templates\results.html at line no 69, please replace lastmodified with your date field name as below:

<span class="">{{getLastModified(content.publication)}}</span><br>

 

Have more questions? Submit a request

Comments

  • Avatar
    Robert Dennis

    I found that using the format:

    <meta name="published" content="20140315T01:50:58"/>

    kept the page from being indexed.

    While using the format

    <meta name="published" content="2014-03-15T01:50:58"/>

    worked as expected.

    This article seems to state that both formats are acceptable. Is this a bug, or a mistake in this article? 

    Edited by Robert Dennis
  • Avatar
    David Hoernig

    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.

     "published": {
    "type": "string",
    "store": "yes",
    "analyzer": "alpha_analyzer",
    "include_in_all": "false"
    },