All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.redlink.solr.suggestion.result.SuggesionResultInterval Maven / Gradle / Ivy

package io.redlink.solr.suggestion.result;

import io.redlink.solr.suggestion.SuggestionRequestHandler;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

public class SuggesionResultInterval implements SuggestionResult {

    private int limit = Integer.MAX_VALUE;
    private SuggestionRequestHandler.LimitType limitType;
    private HashMap intervals = new HashMap<>();

    public SuggesionResultInterval(int limit, SuggestionRequestHandler.LimitType limitType) {
        this.limit = limit;
        this.limitType = limitType;
    }

    public Object write() {
        Map suggestions = new HashMap<>();

        HashMap suggestionIntervals = new HashMap<>();

        intervals.keySet().forEach(key -> suggestionIntervals.put(key, intervals.get(key).getFacets().write()));
        suggestions.put("suggestion_intervals", suggestionIntervals);
        return suggestions;
    }


    public void addFacet(String intervalName, String field, String value, int count, int position) {
        ((SuggesionResultSingle) intervals.get(intervalName).getFacets()).addFacet(field, value, count, position);
    }

    public void addInterval(String intervalName, LocalDateTime start, LocalDateTime end) {
        intervals.put(intervalName, new Interval(start, end, limit, limitType));
    }

    public int getCount() {
        return intervals.size();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy