package org.atlasapi.content;

import org.elasticsearch.index.query.FilterBuilders;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders;
import org.joda.time.DateTime;

public class BroadcastQueryBuilder {


    public static QueryBuilder build(QueryBuilder childQuery, Float timeBoost) {
        DateTime minusThirtyDays = DateTime.now().minusDays(30);
        DateTime plusThirtyDays = DateTime.now().plusDays(30);

        return QueryBuilders.functionScoreQuery(
                QueryBuilders.filteredQuery(
                        childQuery,
                        FilterBuilders.nestedFilter(
                                EsContent.BROADCASTS,
                                FilterBuilders.rangeFilter(EsBroadcast.TRANSMISSION_TIME)
                                        .from(plusThirtyDays)
                                        .to(minusThirtyDays)
                        )
                )
        ).add(ScoreFunctionBuilders.gaussDecayFunction(
                        EsBroadcast.TRANSMISSION_TIME_IN_MILLIS,
                        DateTime.now().getMillis(),
                        minusThirtyDays.getMillis()
                )
        ).boost(timeBoost);
    }
}

@@ -24,16 +24,68 @@
 ntent;%0A%0A
+import com.metabroadcast.common.time.DateTimeZones;%0A
 import o
@@ -121,32 +121,32 @@
 FilterBuilders;%0A
-
 import org.elast
@@ -338,16 +338,40 @@
 eTime;%0A%0A
+import java.util.Date;%0A%0A
 public c
@@ -494,20 +494,16 @@
     Date
-Time
  minusTh
@@ -541,16 +541,55 @@
 Days(30)
+.toDateTime(DateTimeZones.UTC).toDate()
 ;%0A      
@@ -594,20 +594,16 @@
     Date
-Time
  plusThi
@@ -639,16 +639,55 @@
 Days(30)
+.toDateTime(DateTimeZones.UTC).toDate()
 ;%0A%0A     
@@ -1324,34 +1324,54 @@
     
-DateTime.now().getMillis()
+new Date().toInstant().getEpochSecond() * 1000
 ,%0A  
@@ -1412,19 +1412,43 @@
 ays.
-getMillis()
+toInstant().getEpochSecond() * 1000
 %0A   

Correct timestamps