001/* 002 * (C) Copyright 2014 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * bdelbosc 018 */ 019package org.nuxeo.elasticsearch.aggregate; 020 021import static org.nuxeo.elasticsearch.ElasticSearchConstants.AGG_TYPE_DATE_HISTOGRAM; 022import static org.nuxeo.elasticsearch.ElasticSearchConstants.AGG_TYPE_DATE_RANGE; 023import static org.nuxeo.elasticsearch.ElasticSearchConstants.AGG_TYPE_HISTOGRAM; 024import static org.nuxeo.elasticsearch.ElasticSearchConstants.AGG_TYPE_RANGE; 025import static org.nuxeo.elasticsearch.ElasticSearchConstants.AGG_TYPE_SIGNIFICANT_TERMS; 026import static org.nuxeo.elasticsearch.ElasticSearchConstants.AGG_TYPE_TERMS; 027 028import org.nuxeo.ecm.core.api.DocumentModel; 029import org.nuxeo.ecm.platform.query.api.AggregateDefinition; 030import org.nuxeo.ecm.platform.query.api.Bucket; 031 032/** 033 * @since 6.0 034 */ 035final public class AggregateFactory { 036 037 private AggregateFactory() { 038 } 039 040 public static AggregateEsBase<? extends Bucket> create(AggregateDefinition def, DocumentModel searchDocumentModel) { 041 switch (def.getType()) { 042 case AGG_TYPE_TERMS: 043 return new TermAggregate(def, searchDocumentModel); 044 case AGG_TYPE_RANGE: 045 return new RangeAggregate(def, searchDocumentModel); 046 case AGG_TYPE_DATE_HISTOGRAM: 047 return new DateHistogramAggregate(def, searchDocumentModel); 048 case AGG_TYPE_SIGNIFICANT_TERMS: 049 return new SignificantTermAggregate(def, searchDocumentModel); 050 case AGG_TYPE_HISTOGRAM: 051 return new HistogramAggregate(def, searchDocumentModel); 052 case AGG_TYPE_DATE_RANGE: 053 return new DateRangeAggregate(def, searchDocumentModel); 054 default: 055 throw new IllegalArgumentException("Unknown aggregate type: " + def.getType()); 056 } 057 058 } 059}