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

org.graylog2.restclient.models.api.results.SearchResult Maven / Gradle / Ivy

The newest version!
/**
 * This file is part of Graylog.
 *
 * Graylog is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Graylog is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Graylog.  If not, see .
 */
/*
 * This file is part of Graylog.
 *
 * Graylog is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Graylog is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Graylog.  If not, see .
 */
package org.graylog2.restclient.models.api.results;

import com.google.common.collect.Lists;
import org.graylog2.rest.models.system.indexer.responses.IndexRangeSummary;
import org.graylog2.restclient.lib.Field;
import org.graylog2.restclient.lib.timeranges.TimeRange;
import org.graylog2.restclient.models.FieldMapper;
import org.graylog2.restclient.models.api.responses.MessageSummaryResponse;
import org.joda.time.DateTime;

import java.util.List;

public class SearchResult {

    private final String originalQuery;
    private final String builtQuery;
    private final TimeRange timeRange;
    private final long totalResultCount;
    private final int tookMs;
    private final List results;
    private final List fields;
    private final List usedIndices;
    private List allFields;
    private final DateTime fromDateTime;
    private final DateTime toDateTime;

    public SearchResult(String originalQuery,
                        String builtQuery,
                        TimeRange timeRange,
                        long totalResultCount,
                        int tookMs,
                        List summaryResponses,
                        List fields,
                        List usedIndices,
                        DateTime fromDateTime,
                        DateTime toDateTime,
                        FieldMapper fieldMapper) {
        this.originalQuery = originalQuery;
        this.builtQuery = builtQuery;
        this.timeRange = timeRange;
        this.totalResultCount = totalResultCount;
        this.tookMs = tookMs;
        this.fields = buildFields(fields);
        this.usedIndices = usedIndices;
        this.fromDateTime = fromDateTime;
        this.toDateTime = toDateTime;

        // convert MessageSummaryResponses to MessageResult because of the post processing that happens there
        // otherwise we'd have to duplicate it everywhere.
        results = Lists.newArrayList();
        if (summaryResponses != null) {
            for (MessageSummaryResponse response : summaryResponses) {
                results.add(new MessageResult(response.message, response.index, response.highlightRanges, fieldMapper));
            }
        }
    }

    public List getMessages() {
        return results;
    }

    public String getOriginalQuery() {
        return originalQuery;
    }

    public TimeRange getTimeRange() {
        return timeRange;
    }

    public int getTookMs() {
        return tookMs;
    }

    public long getTotalResultCount() {
        return totalResultCount;
    }

    public List getPageFields() {
        return fields;
    }

    public List getUsedIndices() {
        return usedIndices;
    }

    public void setAllFields(List allFields) {
        this.allFields = allFields;
    }

    public List getAllFields() {
        return allFields;
    }

    private List buildFields(List sFields) {
        List fields = Lists.newArrayList();

        if (sFields != null) {
            for (String field : sFields) {
                fields.add(new Field(field));
            }
        }

        return fields;
    }

    public String getBuiltQuery() {
        return builtQuery;
    }

    public DateTime getFromDateTime() {
        return fromDateTime;
    }

    public DateTime getToDateTime() {
        return toDateTime;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy