001/* 002 * (C) Copyright 2014 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl-2.1.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * bdelbosc 016 */ 017package org.nuxeo.elasticsearch.aggregate; 018 019import static org.nuxeo.elasticsearch.ElasticSearchConstants.AGG_TYPE_DATE_HISTOGRAM; 020import static org.nuxeo.elasticsearch.ElasticSearchConstants.AGG_TYPE_DATE_RANGE; 021import static org.nuxeo.elasticsearch.ElasticSearchConstants.AGG_TYPE_HISTOGRAM; 022import static org.nuxeo.elasticsearch.ElasticSearchConstants.AGG_TYPE_RANGE; 023import static org.nuxeo.elasticsearch.ElasticSearchConstants.AGG_TYPE_SIGNIFICANT_TERMS; 024import static org.nuxeo.elasticsearch.ElasticSearchConstants.AGG_TYPE_TERMS; 025 026import org.nuxeo.ecm.core.api.DocumentModel; 027import org.nuxeo.ecm.platform.query.api.AggregateDefinition; 028import org.nuxeo.ecm.platform.query.api.Bucket; 029 030/** 031 * @since 6.0 032 */ 033final public class AggregateFactory { 034 035 private AggregateFactory() { 036 } 037 038 public static AggregateEsBase<? extends Bucket> create(AggregateDefinition def, DocumentModel searchDocumentModel) { 039 switch (def.getType()) { 040 case AGG_TYPE_TERMS: 041 return new TermAggregate(def, searchDocumentModel); 042 case AGG_TYPE_RANGE: 043 return new RangeAggregate(def, searchDocumentModel); 044 case AGG_TYPE_DATE_HISTOGRAM: 045 return new DateHistogramAggregate(def, searchDocumentModel); 046 case AGG_TYPE_SIGNIFICANT_TERMS: 047 return new SignificantTermAggregate(def, searchDocumentModel); 048 case AGG_TYPE_HISTOGRAM: 049 return new HistogramAggregate(def, searchDocumentModel); 050 case AGG_TYPE_DATE_RANGE: 051 return new DateRangeAggregate(def, searchDocumentModel); 052 default: 053 throw new IllegalArgumentException("Unknown aggregate type: " + def.getType()); 054 } 055 056 } 057}