Gravatar for

Question by nick, May 1, 2014 1:17 PM

How to use a smart date facet

If I have a field in CES with a datetime in it (of the datetime type). I would like the easiest path to generating facettes for year\month\day from this field. I was thinking of using the smart date facet, but do not know how.

Any easy way or example?


1 Reply
Gravatar for

Answer by olamothe, May 5, 2014 2:45 PM

By smart date facet, you mean sysdatebucket ? Meaning the facet value look like this ? :

Y2012; M12; D23;

Unfortunately, right now, we don't have any OOTB component to render this nicely.
You can however use a normal facet for @sysmonth and @sysyear. For your sysmonth facet, you can also specify the value caption (so that it's not 01-02,03 etc.) Just add an id to your facet ( id='MonthFacet' ) and add this to your init call :

$("#search").coveo('init', {
MonthFacet: {
      valueCaption : {
        "01" : Globalize.culture("en").calendar.months.names[0],
        "02" : Globalize.culture("en").calendar.months.names[1],
        "03" : Globalize.culture("en").calendar.months.names[2],
        "04" : Globalize.culture("en").calendar.months.names[3],
        "05" : Globalize.culture("en").calendar.months.names[4],
        "06" : Globalize.culture("en").calendar.months.names[5],
        "07" : Globalize.culture("en").calendar.months.names[6],
        "08" : Globalize.culture("en").calendar.months.names[7],
        "09" : Globalize.culture("en").calendar.months.names[8],
        "10" : Globalize.culture("en").calendar.months.names[9],
        "11" : Globalize.culture("en").calendar.months.names[10],
        "12" : Globalize.culture("en").calendar.months.names[11]
Gravatar for

Comment by nick, May 5, 2014 3:08 PM

A smart date facet is in the format you mentioned. But not necessarely sysdatebucket. It is now built in the index for every date field. So because I would like to use it on a field that is not sysdate, then sysyear and sysmonth are not what I'm looking for.

Gravatar for

Comment by olamothe, May 5, 2014 3:17 PM


Just FYI, it's in the backlog/TODO to create a facet optimised for dates. So it should eventually become as easy to do as any other facet/components.

In the meantime… maybe you could try something with query functions in order to get what you want ? Not super trivial though, I admit.

Ask a question