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, Float firstBroadcastBoost) {
        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(),
                        minusThirtyDays
                )
        ).boost(timeBoost);
    }
}

@@ -941,32 +941,44 @@
 m(plusThirtyDays
+.getMillis()
 )%0A              
@@ -1022,16 +1022,28 @@
 irtyDays
+.getMillis()
 )%0A      
@@ -1239,16 +1239,28 @@
 me.now()
+.getMillis()
 ,%0A      
@@ -1292,16 +1292,28 @@
 irtyDays
+.getMillis()
 %0A       

Convert DateTime to millis