mirror of
				https://github.com/spring-projects/spring-data-elasticsearch.git
				synced 2025-10-31 06:38:44 +00:00 
			
		
		
		
	DATAES-211 - clean up
remove facet feature as it is removed in elasticsearch 2.x
This commit is contained in:
		
							parent
							
								
									4e0cbb8966
								
							
						
					
					
						commit
						42fc41b2eb
					
				| @ -76,7 +76,9 @@ public class NodeClientFactoryBean implements FactoryBean<NodeClient>, Initializ | ||||
| 		nodeClient = (NodeClient) nodeBuilder().settings(Settings.builder().put(loadConfig()) | ||||
| 				.put("http.enabled", String.valueOf(this.enableHttp)) | ||||
| 				.put("path.home", this.pathHome) | ||||
| 				.put("path.data", this.pathData)) | ||||
| 				.put("path.data", this.pathData) | ||||
| 						.put("script.inline", "on") | ||||
| 		) | ||||
| 				.clusterName(this.clusterName).local(this.local).node() | ||||
| 				.client(); | ||||
| 	} | ||||
|  | ||||
| @ -35,6 +35,8 @@ import com.fasterxml.jackson.core.JsonFactory; | ||||
| import com.fasterxml.jackson.core.JsonGenerator; | ||||
| import org.elasticsearch.search.SearchHit; | ||||
| import org.elasticsearch.search.SearchHitField; | ||||
| import org.springframework.data.domain.Page; | ||||
| import org.springframework.data.domain.PageImpl; | ||||
| import org.springframework.data.domain.Pageable; | ||||
| import org.springframework.data.elasticsearch.ElasticsearchException; | ||||
| import org.springframework.data.elasticsearch.annotations.Document; | ||||
| @ -72,7 +74,7 @@ public class DefaultResultMapper extends AbstractResultMapper { | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public <T> FacetedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) { | ||||
| 	public <T> Page<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) { | ||||
| 		long totalHits = response.getHits().totalHits(); | ||||
| 		List<T> results = new ArrayList<T>(); | ||||
| 		for (SearchHit hit : response.getHits()) { | ||||
| @ -88,17 +90,7 @@ public class DefaultResultMapper extends AbstractResultMapper { | ||||
| 				results.add(result); | ||||
| 			} | ||||
| 		} | ||||
| 		//TODO: ako facets !!! | ||||
| /*		List<FacetResult> facets = new ArrayList<FacetResult>(); | ||||
| 		if (response.getFacets() != null) { | ||||
| 			for (Facet facet : response.getFacets()) { | ||||
| 				FacetResult facetResult = DefaultFacetMapper.parse(facet); | ||||
| 				if (facetResult != null) { | ||||
| 					facets.add(facetResult); | ||||
| 				} | ||||
| 			} | ||||
| 		}*/ | ||||
| 		return new FacetedPageImpl<T>(results, pageable, totalHits, null ); | ||||
| 		return new PageImpl<T>(results, pageable, totalHits); | ||||
| 	} | ||||
| 
 | ||||
|     private <T> void populateScriptFields(T result, SearchHit hit) { | ||||
|  | ||||
| @ -173,7 +173,7 @@ public interface ElasticsearchOperations { | ||||
| 	 * @param clazz | ||||
| 	 * @return | ||||
| 	 */ | ||||
| 	<T> FacetedPage<T> queryForPage(SearchQuery query, Class<T> clazz); | ||||
| 	<T> Page<T> queryForPage(SearchQuery query, Class<T> clazz); | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Execute the query against elasticsearch and return result as {@link Page} using custom mapper | ||||
| @ -182,7 +182,7 @@ public interface ElasticsearchOperations { | ||||
| 	 * @param clazz | ||||
| 	 * @return | ||||
| 	 */ | ||||
| 	<T> FacetedPage<T> queryForPage(SearchQuery query, Class<T> clazz, SearchResultMapper mapper); | ||||
| 	<T> Page<T> queryForPage(SearchQuery query, Class<T> clazz, SearchResultMapper mapper); | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Execute the query against elasticsearch and return result as {@link Page} | ||||
| @ -200,7 +200,7 @@ public interface ElasticsearchOperations { | ||||
| 	 * @param clazz | ||||
| 	 * @return | ||||
| 	 */ | ||||
| 	<T> FacetedPage<T> queryForPage(StringQuery query, Class<T> clazz); | ||||
| 	<T> Page<T> queryForPage(StringQuery query, Class<T> clazz); | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Execute the query against elasticsearch and return result as {@link Page} using custom mapper | ||||
| @ -209,7 +209,7 @@ public interface ElasticsearchOperations { | ||||
| 	 * @param clazz | ||||
| 	 * @return | ||||
| 	 */ | ||||
| 	<T> FacetedPage<T> queryForPage(StringQuery query, Class<T> clazz, SearchResultMapper mapper); | ||||
| 	<T> Page<T> queryForPage(StringQuery query, Class<T> clazz, SearchResultMapper mapper); | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Executes the given {@link CriteriaQuery} against elasticsearch and return result as {@link CloseableIterator}. | ||||
| @ -431,15 +431,6 @@ public interface ElasticsearchOperations { | ||||
| 	 */ | ||||
| 	boolean deleteIndex(String indexName); | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Deletes a type in an index | ||||
| 	 * | ||||
| 	 * @param index | ||||
| 	 * @param type | ||||
| 	 */ | ||||
| 	//TODo: ako remove this | ||||
| 	/*void deleteType(String index, String type);*/ | ||||
| 
 | ||||
| 	/** | ||||
| 	 * check if index is exists | ||||
| 	 * | ||||
|  | ||||
| @ -76,10 +76,7 @@ import org.springframework.beans.BeansException; | ||||
| import org.springframework.context.ApplicationContext; | ||||
| import org.springframework.context.ApplicationContextAware; | ||||
| import org.springframework.core.io.ClassPathResource; | ||||
| import org.springframework.data.domain.Page; | ||||
| import org.springframework.data.domain.PageRequest; | ||||
| import org.springframework.data.domain.Pageable; | ||||
| import org.springframework.data.domain.Sort; | ||||
| import org.springframework.data.domain.*; | ||||
| import org.springframework.data.elasticsearch.ElasticsearchException; | ||||
| import org.springframework.data.elasticsearch.annotations.Document; | ||||
| import org.springframework.data.elasticsearch.annotations.Mapping; | ||||
| @ -259,12 +256,12 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public <T> FacetedPage<T> queryForPage(SearchQuery query, Class<T> clazz) { | ||||
| 	public <T> Page<T> queryForPage(SearchQuery query, Class<T> clazz) { | ||||
| 		return queryForPage(query, clazz, resultsMapper); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public <T> FacetedPage<T> queryForPage(SearchQuery query, Class<T> clazz, SearchResultMapper mapper) { | ||||
| 	public <T> Page<T> queryForPage(SearchQuery query, Class<T> clazz, SearchResultMapper mapper) { | ||||
| 		SearchResponse response = doSearch(prepareSearch(query, clazz), query); | ||||
| 		return mapper.mapResults(response, clazz, query.getPageable()); | ||||
| 	} | ||||
| @ -328,12 +325,12 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public <T> FacetedPage<T> queryForPage(StringQuery query, Class<T> clazz) { | ||||
| 	public <T> Page<T> queryForPage(StringQuery query, Class<T> clazz) { | ||||
| 		return queryForPage(query, clazz, resultsMapper); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public <T> FacetedPage<T> queryForPage(StringQuery query, Class<T> clazz, SearchResultMapper mapper) { | ||||
| 	public <T> Page<T> queryForPage(StringQuery query, Class<T> clazz, SearchResultMapper mapper) { | ||||
| 		SearchResponse response = getSearchResponse(prepareSearch(query, clazz).setQuery(query.getSource()).execute()); | ||||
| 		return mapper.mapResults(response, clazz, query.getPageable()); | ||||
| 	} | ||||
| @ -668,7 +665,7 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati | ||||
| 		while (hasRecords) { | ||||
| 			Page<String> page = scroll(scrollId, 5000, new SearchResultMapper() { | ||||
| 				@Override | ||||
| 				public <T> FacetedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) { | ||||
| 				public <T> Page<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) { | ||||
| 					List<String> result = new ArrayList<String>(); | ||||
| 					for (SearchHit searchHit : response.getHits()) { | ||||
| 						String id = searchHit.getId(); | ||||
| @ -676,7 +673,7 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati | ||||
| 					} | ||||
| 
 | ||||
| 					if (result.size() > 0) { | ||||
| 						return new FacetedPageImpl<T>((List<T>) result); | ||||
| 						return new PageImpl<T>((List<T>) result); | ||||
| 					} | ||||
| 					return null; | ||||
| 				} | ||||
| @ -864,18 +861,6 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| /* | ||||
| 		if (CollectionUtils.isNotEmpty(searchQuery.getFacets())) { | ||||
| 			for (FacetRequest facetRequest : searchQuery.getFacets()) { | ||||
| 				FacetBuilder facet = facetRequest.getFacet(); | ||||
| 				if (facetRequest.applyQueryFilter() && searchQuery.getFilter() != null) { | ||||
| 					facet.facetFilter(searchQuery.getFilter()); | ||||
| 				} | ||||
| 				searchRequest.addFacet(facet); | ||||
| 			} | ||||
| 		} | ||||
| */ | ||||
| 
 | ||||
| 		if (searchQuery.getHighlightFields() != null) { | ||||
| 			for (HighlightBuilder.Field highlightField : searchQuery.getHighlightFields()) { | ||||
| 				searchRequest.addHighlightedField(highlightField); | ||||
|  | ||||
| @ -1,36 +0,0 @@ | ||||
| /* | ||||
|  * Copyright 2014 the original author or authors. | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  * You may obtain a copy of the License at | ||||
|  * | ||||
|  *      http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * | ||||
|  * Unless required by applicable law or agreed to in writing, software | ||||
|  * distributed under the License is distributed on an "AS IS" BASIS, | ||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  */ | ||||
| package org.springframework.data.elasticsearch.core; | ||||
| 
 | ||||
| import java.util.List; | ||||
| 
 | ||||
| import org.springframework.data.domain.Page; | ||||
| import org.springframework.data.elasticsearch.core.facet.FacetResult; | ||||
| 
 | ||||
| /** | ||||
|  * @author Rizwan Idrees | ||||
|  * @author Mohsin Husen | ||||
|  * @author Artur Konczak | ||||
|  * @author Jonathan Yan | ||||
|  */ | ||||
| public interface FacetedPage<T> extends Page<T> { | ||||
| 
 | ||||
| 	boolean hasFacets(); | ||||
| 
 | ||||
| 	List<FacetResult> getFacets(); | ||||
| 
 | ||||
| 	FacetResult getFacet(String name); | ||||
| } | ||||
| @ -1,72 +0,0 @@ | ||||
| /* | ||||
|  * Copyright 2014 the original author or authors. | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  * You may obtain a copy of the License at | ||||
|  * | ||||
|  *      http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * | ||||
|  * Unless required by applicable law or agreed to in writing, software | ||||
|  * distributed under the License is distributed on an "AS IS" BASIS, | ||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  */ | ||||
| package org.springframework.data.elasticsearch.core; | ||||
| 
 | ||||
| import java.util.HashMap; | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
| 
 | ||||
| import org.apache.commons.collections.CollectionUtils; | ||||
| import org.springframework.data.domain.PageImpl; | ||||
| import org.springframework.data.domain.Pageable; | ||||
| import org.springframework.data.elasticsearch.core.facet.FacetResult; | ||||
| 
 | ||||
| /** | ||||
|  * Container for query result and facet results | ||||
|  * | ||||
|  * @author Rizwan Idrees | ||||
|  * @author Mohsin Husen | ||||
|  * @author Artur Konczak | ||||
|  * @author Jonathan Yan | ||||
|  */ | ||||
| public class FacetedPageImpl<T> extends PageImpl<T> implements FacetedPage<T> { | ||||
| 
 | ||||
| 	private List<FacetResult> facets; | ||||
| 	private Map<String, FacetResult> mapOfFacets = new HashMap<String, FacetResult>(); | ||||
| 
 | ||||
| 	public FacetedPageImpl(List<T> content) { | ||||
| 		super(content); | ||||
| 	} | ||||
| 
 | ||||
| 	public FacetedPageImpl(List<T> content, Pageable pageable, long total) { | ||||
| 		super(content, pageable, total); | ||||
| 	} | ||||
| 
 | ||||
| 	public FacetedPageImpl(List<T> content, Pageable pageable, long total, List<FacetResult> facets) { | ||||
| 		super(content, pageable, total); | ||||
| 		this.facets = facets; | ||||
| 		if(facets!=null) { | ||||
| 			for (FacetResult facet : facets) { | ||||
| 				mapOfFacets.put(facet.getName(), facet); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public boolean hasFacets() { | ||||
| 		return CollectionUtils.isNotEmpty(facets); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public List<FacetResult> getFacets() { | ||||
| 		return facets; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public FacetResult getFacet(String name) { | ||||
| 		return mapOfFacets.get(name); | ||||
| 	} | ||||
| } | ||||
| @ -16,6 +16,7 @@ | ||||
| package org.springframework.data.elasticsearch.core; | ||||
| 
 | ||||
| import org.elasticsearch.action.search.SearchResponse; | ||||
| import org.springframework.data.domain.Page; | ||||
| import org.springframework.data.domain.Pageable; | ||||
| 
 | ||||
| /** | ||||
| @ -23,5 +24,5 @@ import org.springframework.data.domain.Pageable; | ||||
|  */ | ||||
| public interface SearchResultMapper { | ||||
| 
 | ||||
| 	<T> FacetedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable); | ||||
| 	<T> Page<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable); | ||||
| } | ||||
|  | ||||
| @ -1,49 +0,0 @@ | ||||
| /* | ||||
|  * Copyright 2014 the original author or authors. | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  * You may obtain a copy of the License at | ||||
|  * | ||||
|  *      http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * | ||||
|  * Unless required by applicable law or agreed to in writing, software | ||||
|  * distributed under the License is distributed on an "AS IS" BASIS, | ||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  *//* | ||||
| 
 | ||||
| package org.springframework.data.elasticsearch.core.facet; | ||||
| 
 | ||||
| import org.springframework.util.Assert; | ||||
| 
 | ||||
| */ | ||||
| /** | ||||
|  * @author Artur Konczak | ||||
|  *//* | ||||
| 
 | ||||
| public abstract class AbstractFacetRequest implements FacetRequest { | ||||
| 
 | ||||
| 	private String name; | ||||
| 	private boolean applyQueryFilter; | ||||
| 
 | ||||
| 	public AbstractFacetRequest(String name) { | ||||
| 		Assert.hasText(name, "Facet can't be null or empty !!!"); | ||||
| 		this.name = name; | ||||
| 	} | ||||
| 
 | ||||
| 	protected String getName() { | ||||
| 		return name; | ||||
| 	} | ||||
| 
 | ||||
| 	public void setApplyQueryFilter(boolean applyQueryFilter) { | ||||
| 		this.applyQueryFilter = applyQueryFilter; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public boolean applyQueryFilter() { | ||||
| 		return applyQueryFilter; | ||||
| 	} | ||||
| } | ||||
| */ | ||||
| @ -1,46 +0,0 @@ | ||||
| /* | ||||
|  * Copyright 2014 the original author or authors. | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  * You may obtain a copy of the License at | ||||
|  * | ||||
|  *      http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * | ||||
|  * Unless required by applicable law or agreed to in writing, software | ||||
|  * distributed under the License is distributed on an "AS IS" BASIS, | ||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  */ | ||||
| package org.springframework.data.elasticsearch.core.facet; | ||||
| 
 | ||||
| import org.springframework.util.Assert; | ||||
| 
 | ||||
| /** | ||||
|  * @author Rizwan Idrees | ||||
|  * @author Mohsin Husen | ||||
|  * @author Artur Konczak | ||||
|  * @author Jonathan Yan | ||||
|  */ | ||||
| public class AbstractFacetResult implements FacetResult { | ||||
| 
 | ||||
| 	private final String name; | ||||
| 	private final FacetType type; | ||||
| 
 | ||||
| 	protected AbstractFacetResult(String name, FacetType type) { | ||||
| 		Assert.hasText(name, "Facet name can't be null and should have a value"); | ||||
| 		this.name = name; | ||||
| 		this.type = type; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public String getName() { | ||||
| 		return name; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public FacetType getType() { | ||||
| 		return type; | ||||
| 	} | ||||
| } | ||||
| @ -1,81 +0,0 @@ | ||||
| ///* | ||||
| // * Copyright 2014 the original author or authors. | ||||
| // * | ||||
| // * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| // * you may not use this file except in compliance with the License. | ||||
| // * You may obtain a copy of the License at | ||||
| // * | ||||
| // *      http://www.apache.org/licenses/LICENSE-2.0 | ||||
| // * | ||||
| // * Unless required by applicable law or agreed to in writing, software | ||||
| // * distributed under the License is distributed on an "AS IS" BASIS, | ||||
| // * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| // * See the License for the specific language governing permissions and | ||||
| // * limitations under the License. | ||||
| // */ | ||||
| //package org.springframework.data.elasticsearch.core.facet; | ||||
| // | ||||
| //import java.util.ArrayList; | ||||
| //import java.util.List; | ||||
| // | ||||
| //import org.elasticsearch.search.facet.Facet; | ||||
| //import org.elasticsearch.search.facet.histogram.HistogramFacet; | ||||
| //import org.elasticsearch.search.facet.range.RangeFacet; | ||||
| //import org.elasticsearch.search.facet.statistical.StatisticalFacet; | ||||
| //import org.elasticsearch.search.facet.terms.TermsFacet; | ||||
| //import org.springframework.data.elasticsearch.core.facet.result.*; | ||||
| // | ||||
| ///** | ||||
| // * @author Artur Konczak | ||||
| // * @author Petar Tahchiev | ||||
| // */ | ||||
| //public class DefaultFacetMapper { | ||||
| // | ||||
| //	public static FacetResult parse(Facet facet) { | ||||
| //		if (facet instanceof TermsFacet) { | ||||
| //			return parseTerm((TermsFacet) facet); | ||||
| //		} | ||||
| // | ||||
| //		if (facet instanceof RangeFacet) { | ||||
| //			return parseRange((RangeFacet) facet); | ||||
| //		} | ||||
| // | ||||
| //		if (facet instanceof StatisticalFacet) { | ||||
| //			return parseStatistical((StatisticalFacet) facet); | ||||
| //		} | ||||
| // | ||||
| //		if (facet instanceof HistogramFacet) { | ||||
| //			return parseHistogram((HistogramFacet) facet); | ||||
| //		} | ||||
| // | ||||
| //		return null; | ||||
| //	} | ||||
| // | ||||
| //	private static FacetResult parseTerm(TermsFacet facet) { | ||||
| //		List<Term> entries = new ArrayList<Term>(); | ||||
| //		for (TermsFacet.Entry entry : facet.getEntries()) { | ||||
| //			entries.add(new Term(entry.getTerm().toString(), entry.getCount())); | ||||
| //		} | ||||
| //		return new TermResult(facet.getName(), entries, facet.getTotalCount(), facet.getOtherCount(), facet.getMissingCount()); | ||||
| //	} | ||||
| // | ||||
| //	private static FacetResult parseRange(RangeFacet facet) { | ||||
| //		List<Range> entries = new ArrayList<Range>(); | ||||
| //		for (RangeFacet.Entry entry : facet.getEntries()) { | ||||
| //			entries.add(new Range(entry.getFrom() == Double.NEGATIVE_INFINITY ? null : entry.getFrom(), entry.getTo() == Double.POSITIVE_INFINITY ? null : entry.getTo(), entry.getCount(), entry.getTotal(), entry.getTotalCount(), entry.getMin(), entry.getMax())); | ||||
| //		} | ||||
| //		return new RangeResult(facet.getName(), entries); | ||||
| //	} | ||||
| // | ||||
| //	private static FacetResult parseStatistical(StatisticalFacet facet) { | ||||
| //		return new StatisticalResult(facet.getName(), facet.getCount(), facet.getMax(), facet.getMin(), facet.getMean(), facet.getStdDeviation(), facet.getSumOfSquares(), facet.getTotal(), facet.getVariance()); | ||||
| //	} | ||||
| // | ||||
| //	private static FacetResult parseHistogram(HistogramFacet facet) { | ||||
| //		List<IntervalUnit> entries = new ArrayList<IntervalUnit>(); | ||||
| //		for (HistogramFacet.Entry entry : facet.getEntries()) { | ||||
| //			entries.add(new IntervalUnit(entry.getKey(), entry.getCount(), entry.getTotalCount(), entry.getTotal(), entry.getMean(), entry.getMin(), entry.getMax())); | ||||
| //		} | ||||
| //		return new HistogramResult(facet.getName(), entries); | ||||
| //	} | ||||
| //} | ||||
| @ -1,35 +0,0 @@ | ||||
| /* | ||||
|  * Copyright 2014 the original author or authors. | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  * You may obtain a copy of the License at | ||||
|  * | ||||
|  *      http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * | ||||
|  * Unless required by applicable law or agreed to in writing, software | ||||
|  * distributed under the License is distributed on an "AS IS" BASIS, | ||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  *//* | ||||
| 
 | ||||
| package org.springframework.data.elasticsearch.core.facet; | ||||
| 
 | ||||
| import org.elasticsearch.search.facet.FacetBuilder; | ||||
| 
 | ||||
| */ | ||||
| /** | ||||
|  * @author Artur Koczak | ||||
|  *//* | ||||
| 
 | ||||
| public interface FacetRequest { | ||||
| 
 | ||||
| 	public static final String FIELD_UNTOUCHED = "untouched"; | ||||
| 	public static final String FIELD_SORT = "sort"; | ||||
| 
 | ||||
| 	FacetBuilder getFacet(); | ||||
| 
 | ||||
| 	boolean applyQueryFilter(); | ||||
| } | ||||
| */ | ||||
| @ -1,31 +0,0 @@ | ||||
| /* | ||||
|  * Copyright 2014 the original author or authors. | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  * You may obtain a copy of the License at | ||||
|  * | ||||
|  *      http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * | ||||
|  * Unless required by applicable law or agreed to in writing, software | ||||
|  * distributed under the License is distributed on an "AS IS" BASIS, | ||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  */ | ||||
| package org.springframework.data.elasticsearch.core.facet; | ||||
| 
 | ||||
| /** | ||||
|  * Generic interface for all facets | ||||
|  * | ||||
|  * @author Rizwan Idrees | ||||
|  * @author Mohsin Husen | ||||
|  * @author Artur Konczak | ||||
|  * @author Jonathan Yan | ||||
|  */ | ||||
| public interface FacetResult { | ||||
| 
 | ||||
| 	String getName(); | ||||
| 
 | ||||
| 	FacetType getType(); | ||||
| } | ||||
| @ -1,26 +0,0 @@ | ||||
| /* | ||||
|  * Copyright 2014 the original author or authors. | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  * You may obtain a copy of the License at | ||||
|  * | ||||
|  *      http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * | ||||
|  * Unless required by applicable law or agreed to in writing, software | ||||
|  * distributed under the License is distributed on an "AS IS" BASIS, | ||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  */ | ||||
| package org.springframework.data.elasticsearch.core.facet; | ||||
| 
 | ||||
| /** | ||||
|  * @author Artur Konczak | ||||
|  * @author Petar Tahchiev | ||||
|  */ | ||||
| public enum FacetType { | ||||
| 
 | ||||
| 	term, range, histogram, statistical | ||||
| 
 | ||||
| } | ||||
| @ -1,73 +0,0 @@ | ||||
| /* | ||||
|  * Copyright 2014 the original author or authors. | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  * You may obtain a copy of the License at | ||||
|  * | ||||
|  *      http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * | ||||
|  * Unless required by applicable law or agreed to in writing, software | ||||
|  * distributed under the License is distributed on an "AS IS" BASIS, | ||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  *//* | ||||
| 
 | ||||
| package org.springframework.data.elasticsearch.core.facet.request; | ||||
| 
 | ||||
| import java.util.concurrent.TimeUnit; | ||||
| 
 | ||||
| import org.apache.commons.lang.StringUtils; | ||||
| import org.elasticsearch.search.facet.FacetBuilder; | ||||
| import org.elasticsearch.search.facet.FacetBuilders; | ||||
| import org.elasticsearch.search.facet.histogram.HistogramFacetBuilder; | ||||
| import org.springframework.data.elasticsearch.core.facet.AbstractFacetRequest; | ||||
| import org.springframework.util.Assert; | ||||
| 
 | ||||
| */ | ||||
| /** | ||||
|  * @author Artur Konczak | ||||
|  * @author Mohsin Husen | ||||
|  *//* | ||||
| 
 | ||||
| public class HistogramFacetRequest extends AbstractFacetRequest { | ||||
| 
 | ||||
| 	private String field; | ||||
| 	private long interval; | ||||
| 	private TimeUnit timeUnit; | ||||
| 
 | ||||
| 	public HistogramFacetRequest(String name) { | ||||
| 		super(name); | ||||
| 	} | ||||
| 
 | ||||
| 	public void setField(String field) { | ||||
| 		this.field = field; | ||||
| 	} | ||||
| 
 | ||||
| 	public void setInterval(long interval) { | ||||
| 		this.interval = interval; | ||||
| 	} | ||||
| 
 | ||||
| 	public void setTimeUnit(TimeUnit timeUnit) { | ||||
| 		this.timeUnit = timeUnit; | ||||
| 	} | ||||
| 
 | ||||
| 	public FacetBuilder getFacet() { | ||||
| 		Assert.notNull(getName(), "Facet name can't be a null !!!"); | ||||
| 		Assert.isTrue(StringUtils.isNotBlank(field), "Please select field on which to build the facet !!!"); | ||||
| 		Assert.isTrue(interval > 0, "Please provide interval as positive value greater them zero !!!"); | ||||
| 
 | ||||
| 		HistogramFacetBuilder builder = FacetBuilders.histogramFacet(getName()); | ||||
| 		builder.field(field); | ||||
| 
 | ||||
| 		if (timeUnit != null) { | ||||
| 			builder.interval(interval, timeUnit); | ||||
| 		} else { | ||||
| 			builder.interval(interval); | ||||
| 		} | ||||
| 
 | ||||
| 		return builder; | ||||
| 	} | ||||
| } | ||||
| */ | ||||
| @ -1,60 +0,0 @@ | ||||
| /* | ||||
|  * Copyright 2014 the original author or authors. | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  * You may obtain a copy of the License at | ||||
|  * | ||||
|  *      http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * | ||||
|  * Unless required by applicable law or agreed to in writing, software | ||||
|  * distributed under the License is distributed on an "AS IS" BASIS, | ||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  *//* | ||||
| 
 | ||||
| package org.springframework.data.elasticsearch.core.facet.request; | ||||
| 
 | ||||
| import java.util.concurrent.TimeUnit; | ||||
| 
 | ||||
| import org.springframework.data.elasticsearch.core.facet.FacetRequest; | ||||
| 
 | ||||
| */ | ||||
| /** | ||||
|  * @author Artur Konczak | ||||
|  *//* | ||||
| 
 | ||||
| public class HistogramFacetRequestBuilder { | ||||
| 
 | ||||
| 	HistogramFacetRequest result; | ||||
| 
 | ||||
| 	public HistogramFacetRequestBuilder(String name) { | ||||
| 		result = new HistogramFacetRequest(name); | ||||
| 	} | ||||
| 
 | ||||
| 	public HistogramFacetRequestBuilder field(String field) { | ||||
| 		result.setField(field); | ||||
| 		return this; | ||||
| 	} | ||||
| 
 | ||||
| 	public HistogramFacetRequestBuilder interval(long interval) { | ||||
| 		result.setInterval(interval); | ||||
| 		return this; | ||||
| 	} | ||||
| 
 | ||||
| 	public HistogramFacetRequestBuilder timeUnit(TimeUnit timeUnit) { | ||||
| 		result.setTimeUnit(timeUnit); | ||||
| 		return this; | ||||
| 	} | ||||
| 
 | ||||
| 	public FacetRequest build() { | ||||
| 		return result; | ||||
| 	} | ||||
| 
 | ||||
| 	public HistogramFacetRequestBuilder applyQueryFilter() { | ||||
| 		result.setApplyQueryFilter(true); | ||||
| 		return this; | ||||
| 	} | ||||
| } | ||||
| */ | ||||
| @ -1,52 +0,0 @@ | ||||
| /* | ||||
|  * Copyright 2014 the original author or authors. | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  * You may obtain a copy of the License at | ||||
|  * | ||||
|  *      http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * | ||||
|  * Unless required by applicable law or agreed to in writing, software | ||||
|  * distributed under the License is distributed on an "AS IS" BASIS, | ||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  *//* | ||||
| 
 | ||||
| package org.springframework.data.elasticsearch.core.facet.request; | ||||
| 
 | ||||
| import org.elasticsearch.search.facet.FacetBuilder; | ||||
| import org.springframework.data.elasticsearch.core.facet.FacetRequest; | ||||
| 
 | ||||
| */ | ||||
| /** | ||||
|  * @author Artur Konczak | ||||
|  * @author Mohsin Husen | ||||
|  *//* | ||||
| 
 | ||||
| public class NativeFacetRequest implements FacetRequest { | ||||
| 
 | ||||
| 	private FacetBuilder facet; | ||||
| 	private boolean applyQueryFilter; | ||||
| 
 | ||||
| 	public NativeFacetRequest(FacetBuilder facet) { | ||||
| 		this(facet, false); | ||||
| 	} | ||||
| 
 | ||||
| 	public NativeFacetRequest(FacetBuilder facet, boolean applyQueryFilter) { | ||||
| 		this.facet = facet; | ||||
| 		this.applyQueryFilter = applyQueryFilter; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public FacetBuilder getFacet() { | ||||
| 		return facet; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public boolean applyQueryFilter() { | ||||
| 		return applyQueryFilter; | ||||
| 	} | ||||
| } | ||||
| */ | ||||
| @ -1,136 +0,0 @@ | ||||
| /* | ||||
|  * Copyright 2014 the original author or authors. | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  * You may obtain a copy of the License at | ||||
|  * | ||||
|  *      http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * | ||||
|  * Unless required by applicable law or agreed to in writing, software | ||||
|  * distributed under the License is distributed on an "AS IS" BASIS, | ||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  *//* | ||||
| 
 | ||||
| package org.springframework.data.elasticsearch.core.facet.request; | ||||
| 
 | ||||
| import java.util.ArrayList; | ||||
| import java.util.List; | ||||
| 
 | ||||
| import org.apache.commons.lang.StringUtils; | ||||
| import org.elasticsearch.search.facet.FacetBuilder; | ||||
| import org.elasticsearch.search.facet.FacetBuilders; | ||||
| import org.elasticsearch.search.facet.range.RangeFacetBuilder; | ||||
| import org.springframework.data.elasticsearch.core.facet.AbstractFacetRequest; | ||||
| import org.springframework.util.Assert; | ||||
| 
 | ||||
| */ | ||||
| /** | ||||
|  * Range facet for numeric fields | ||||
|  * | ||||
|  * @author Artur Konczak | ||||
|  * @author Akos Bordas | ||||
|  *//* | ||||
| 
 | ||||
| public class RangeFacetRequest extends AbstractFacetRequest { | ||||
| 
 | ||||
| 	private String field; | ||||
| 	private String keyField; | ||||
| 	private String valueField; | ||||
| 
 | ||||
| 	private List<Entry> entries = new ArrayList<Entry>(); | ||||
| 
 | ||||
| 	public RangeFacetRequest(String name) { | ||||
| 		super(name); | ||||
| 	} | ||||
| 
 | ||||
| 	public void setField(String field) { | ||||
| 		this.field = field; | ||||
| 	} | ||||
| 
 | ||||
| 	public void setFields(String keyField, String valueField) { | ||||
| 		this.keyField = keyField; | ||||
| 		this.valueField = valueField; | ||||
| 	} | ||||
| 
 | ||||
| 	public void range(Double from, Double to) { | ||||
| 		entries.add(new DoubleEntry(from, to)); | ||||
| 	} | ||||
| 
 | ||||
| 	public void range(String from, String to) { | ||||
| 		entries.add(new StringEntry(from, to)); | ||||
| 	} | ||||
| 
 | ||||
| 	public void addRange(Double from, Double to) { | ||||
| 		entries.add(new DoubleEntry(from, to)); | ||||
| 	} | ||||
| 
 | ||||
| 	public void addRange(String from, String to) { | ||||
| 		entries.add(new StringEntry(from, to)); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public FacetBuilder getFacet() { | ||||
| 		Assert.notNull(getName(), "Facet name can't be a null !!!"); | ||||
| 		Assert.isTrue(StringUtils.isNotBlank(field) || StringUtils.isNotBlank(keyField) && StringUtils.isNotBlank(valueField), "Please select field or key field and value field !!!"); | ||||
| 
 | ||||
| 		RangeFacetBuilder builder = FacetBuilders.rangeFacet(getName()); | ||||
| 		if (StringUtils.isNotBlank(keyField)) { | ||||
| 			builder.keyField(keyField).valueField(valueField); | ||||
| 		} else { | ||||
| 			builder.field(field); | ||||
| 		} | ||||
| 
 | ||||
| 		for (Entry entry : entries) { | ||||
| 			if (entry instanceof DoubleEntry) { | ||||
| 				DoubleEntry doubleEntry = (DoubleEntry) entry; | ||||
| 				builder.addRange(validateValue(doubleEntry.getFrom(), Double.NEGATIVE_INFINITY), validateValue(doubleEntry.getTo(), Double.POSITIVE_INFINITY)); | ||||
| 			} else { | ||||
| 				StringEntry stringEntry = (StringEntry) entry; | ||||
| 				builder.addRange(stringEntry.getFrom(), stringEntry.getTo()); | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		return builder; | ||||
| 	} | ||||
| 
 | ||||
| 	private double validateValue(Double value, double defaultValue) { | ||||
| 		return value == null ? defaultValue : value; | ||||
| 	} | ||||
| 
 | ||||
| 	static class DoubleEntry extends Entry<Double> { | ||||
| 
 | ||||
| 		DoubleEntry(Double from, Double to) { | ||||
| 			super(from, to); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	static class StringEntry extends Entry<String> { | ||||
| 
 | ||||
| 		StringEntry(String from, String to) { | ||||
| 			super(from, to); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	static class Entry<T> { | ||||
| 
 | ||||
| 		T from; | ||||
| 		T to; | ||||
| 
 | ||||
| 		Entry(T from, T to) { | ||||
| 			this.from = from; | ||||
| 			this.to = to; | ||||
| 		} | ||||
| 
 | ||||
| 		public T getFrom() { | ||||
| 			return from; | ||||
| 		} | ||||
| 
 | ||||
| 		public T getTo() { | ||||
| 			return to; | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| */ | ||||
| @ -1,86 +0,0 @@ | ||||
| /* | ||||
|  * Copyright 2014 the original author or authors. | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  * You may obtain a copy of the License at | ||||
|  * | ||||
|  *      http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * | ||||
|  * Unless required by applicable law or agreed to in writing, software | ||||
|  * distributed under the License is distributed on an "AS IS" BASIS, | ||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  *//* | ||||
| 
 | ||||
| package org.springframework.data.elasticsearch.core.facet.request; | ||||
| 
 | ||||
| import org.springframework.data.elasticsearch.core.facet.FacetRequest; | ||||
| 
 | ||||
| */ | ||||
| /** | ||||
|  * Basic range facet | ||||
|  * | ||||
|  * @author Artur Konczak | ||||
|  *//* | ||||
| 
 | ||||
| public class RangeFacetRequestBuilder { | ||||
| 
 | ||||
| 	RangeFacetRequest result; | ||||
| 
 | ||||
| 	public RangeFacetRequestBuilder(String name) { | ||||
| 		result = new RangeFacetRequest(name); | ||||
| 	} | ||||
| 
 | ||||
| 	public RangeFacetRequestBuilder field(String field) { | ||||
| 		result.setField(field); | ||||
| 		return this; | ||||
| 	} | ||||
| 
 | ||||
| 	public RangeFacetRequestBuilder fields(String keyField, String valueField) { | ||||
| 		result.setFields(keyField, valueField); | ||||
| 		return this; | ||||
| 	} | ||||
| 
 | ||||
| 
 | ||||
| 	public RangeFacetRequestBuilder range(double from, double to) { | ||||
| 		result.range(from, to); | ||||
| 		return this; | ||||
| 	} | ||||
| 
 | ||||
| 	public RangeFacetRequestBuilder range(String from, String to) { | ||||
| 		result.range(from, to); | ||||
| 		return this; | ||||
| 	} | ||||
| 
 | ||||
| 	public RangeFacetRequestBuilder from(double from) { | ||||
| 		result.range(from, null); | ||||
| 		return this; | ||||
| 	} | ||||
| 
 | ||||
| 	public RangeFacetRequestBuilder to(double to) { | ||||
| 		result.range(null, to); | ||||
| 		return this; | ||||
| 	} | ||||
| 
 | ||||
| 	public RangeFacetRequestBuilder from(String from) { | ||||
| 		result.range(from, null); | ||||
| 		return this; | ||||
| 	} | ||||
| 
 | ||||
| 	public RangeFacetRequestBuilder to(String to) { | ||||
| 		result.range(null, to); | ||||
| 		return this; | ||||
| 	} | ||||
| 
 | ||||
| 	public RangeFacetRequestBuilder applyQueryFilter() { | ||||
| 		result.setApplyQueryFilter(true); | ||||
| 		return this; | ||||
| 	} | ||||
| 
 | ||||
| 	public FacetRequest build() { | ||||
| 		return result; | ||||
| 	} | ||||
| } | ||||
| */ | ||||
| @ -1,64 +0,0 @@ | ||||
| /* | ||||
|  * Copyright 2014 the original author or authors. | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  * You may obtain a copy of the License at | ||||
|  * | ||||
|  *      http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * | ||||
|  * Unless required by applicable law or agreed to in writing, software | ||||
|  * distributed under the License is distributed on an "AS IS" BASIS, | ||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  *//* | ||||
| 
 | ||||
| package org.springframework.data.elasticsearch.core.facet.request; | ||||
| 
 | ||||
| import org.apache.commons.lang.ArrayUtils; | ||||
| import org.apache.commons.lang.StringUtils; | ||||
| import org.elasticsearch.search.facet.FacetBuilder; | ||||
| import org.elasticsearch.search.facet.FacetBuilders; | ||||
| import org.elasticsearch.search.facet.statistical.StatisticalFacetBuilder; | ||||
| import org.springframework.data.elasticsearch.core.facet.AbstractFacetRequest; | ||||
| import org.springframework.util.Assert; | ||||
| 
 | ||||
| */ | ||||
| /** | ||||
|  * @author Petar Tahchiev | ||||
|  *//* | ||||
| 
 | ||||
| public class StatisticalFacetRequest extends AbstractFacetRequest { | ||||
| 
 | ||||
| 	private String field; | ||||
| 
 | ||||
| 	private String[] fields; | ||||
| 
 | ||||
| 	public StatisticalFacetRequest(String name) { | ||||
| 		super(name); | ||||
| 	} | ||||
| 
 | ||||
| 	public void setField(String field) { | ||||
| 		this.field = field; | ||||
| 	} | ||||
| 
 | ||||
| 	public void setFields(String... fields) { | ||||
| 		this.fields = fields; | ||||
| 	} | ||||
| 
 | ||||
| 	public FacetBuilder getFacet() { | ||||
| 		Assert.notNull(getName(), "Facet name can't be a null !!!"); | ||||
| 		Assert.isTrue(StringUtils.isNotBlank(field) && fields == null, "Please select field or fields on which to build the facets !!!"); | ||||
| 
 | ||||
| 		StatisticalFacetBuilder builder = FacetBuilders.statisticalFacet(getName()); | ||||
| 		if (ArrayUtils.isNotEmpty(fields)) { | ||||
| 			builder.fields(fields); | ||||
| 		} else { | ||||
| 			builder.field(field); | ||||
| 		} | ||||
| 
 | ||||
| 		return builder; | ||||
| 	} | ||||
| } | ||||
| */ | ||||
| @ -1,53 +0,0 @@ | ||||
| /* | ||||
|  * Copyright 2014 the original author or authors. | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  * You may obtain a copy of the License at | ||||
|  * | ||||
|  *      http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * | ||||
|  * Unless required by applicable law or agreed to in writing, software | ||||
|  * distributed under the License is distributed on an "AS IS" BASIS, | ||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  *//* | ||||
| 
 | ||||
| package org.springframework.data.elasticsearch.core.facet.request; | ||||
| 
 | ||||
| import org.springframework.data.elasticsearch.core.facet.FacetRequest; | ||||
| 
 | ||||
| */ | ||||
| /** | ||||
|  * @author Petar Tahchiev | ||||
|  *//* | ||||
| 
 | ||||
| public class StatisticalFacetRequestBuilder { | ||||
| 
 | ||||
| 	StatisticalFacetRequest result; | ||||
| 
 | ||||
| 	public StatisticalFacetRequestBuilder(String name) { | ||||
| 		result = new StatisticalFacetRequest(name); | ||||
| 	} | ||||
| 
 | ||||
| 	public StatisticalFacetRequestBuilder field(String field) { | ||||
| 		result.setField(field); | ||||
| 		return this; | ||||
| 	} | ||||
| 
 | ||||
| 	public StatisticalFacetRequestBuilder fields(String... fields) { | ||||
| 		result.setFields(fields); | ||||
| 		return this; | ||||
| 	} | ||||
| 
 | ||||
| 	public StatisticalFacetRequestBuilder applyQueryFilter() { | ||||
| 		result.setApplyQueryFilter(true); | ||||
| 		return this; | ||||
| 	} | ||||
| 
 | ||||
| 	public FacetRequest build() { | ||||
| 		return result; | ||||
| 	} | ||||
| } | ||||
| */ | ||||
| @ -1,26 +0,0 @@ | ||||
| /* | ||||
|  * Copyright 2014 the original author or authors. | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  * You may obtain a copy of the License at | ||||
|  * | ||||
|  *      http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * | ||||
|  * Unless required by applicable law or agreed to in writing, software | ||||
|  * distributed under the License is distributed on an "AS IS" BASIS, | ||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  */ | ||||
| package org.springframework.data.elasticsearch.core.facet.request; | ||||
| 
 | ||||
| /** | ||||
|  * @author Artur Konczak | ||||
|  * @author Mohsin Husen | ||||
|  */ | ||||
| public enum TermFacetOrder { | ||||
| 
 | ||||
| 	ascTerm, descTerm, ascCount, descCount; | ||||
| 
 | ||||
| } | ||||
| @ -1,112 +0,0 @@ | ||||
| /* | ||||
|  * Copyright 2014 the original author or authors. | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  * You may obtain a copy of the License at | ||||
|  * | ||||
|  *      http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * | ||||
|  * Unless required by applicable law or agreed to in writing, software | ||||
|  * distributed under the License is distributed on an "AS IS" BASIS, | ||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  *//* | ||||
| 
 | ||||
| package org.springframework.data.elasticsearch.core.facet.request; | ||||
| 
 | ||||
| import org.apache.commons.lang.ArrayUtils; | ||||
| import org.apache.commons.lang.StringUtils; | ||||
| import org.elasticsearch.search.facet.FacetBuilder; | ||||
| import org.elasticsearch.search.facet.FacetBuilders; | ||||
| import org.elasticsearch.search.facet.terms.TermsFacet; | ||||
| import org.elasticsearch.search.facet.terms.TermsFacetBuilder; | ||||
| import org.springframework.data.elasticsearch.core.facet.AbstractFacetRequest; | ||||
| import org.springframework.util.Assert; | ||||
| 
 | ||||
| */ | ||||
| /** | ||||
|  * Term facet | ||||
|  * | ||||
|  * @author Artur Konczak | ||||
|  *//* | ||||
| 
 | ||||
| public class TermFacetRequest extends AbstractFacetRequest { | ||||
| 
 | ||||
| 	private String[] fields; | ||||
| 	private Object[] excludeTerms; | ||||
| 	private int size = 10; | ||||
| 	private TermFacetOrder order = TermFacetOrder.descCount; | ||||
| 	private boolean allTerms = false; | ||||
| 	private String regex = null; | ||||
| 	private int regexFlag = 0; | ||||
| 
 | ||||
| 	public TermFacetRequest(String name) { | ||||
| 		super(name); | ||||
| 	} | ||||
| 
 | ||||
| 	public void setFields(String... fields) { | ||||
| 		this.fields = fields; | ||||
| 	} | ||||
| 
 | ||||
| 	public void setSize(int size) { | ||||
| 		Assert.isTrue(size >= 0, "Size should be bigger then zero !!!"); | ||||
| 		this.size = size; | ||||
| 	} | ||||
| 
 | ||||
| 	public void setOrder(TermFacetOrder order) { | ||||
| 		this.order = order; | ||||
| 	} | ||||
| 
 | ||||
| 	public void setExcludeTerms(Object... excludeTerms) { | ||||
| 		this.excludeTerms = excludeTerms; | ||||
| 	} | ||||
| 
 | ||||
| 	public void setAllTerms(boolean allTerms) { | ||||
| 		this.allTerms = allTerms; | ||||
| 	} | ||||
| 
 | ||||
| 	public void setRegex(String regex) { | ||||
| 		this.regex = regex; | ||||
| 	} | ||||
| 
 | ||||
| 	public void setRegex(String regex, int regexFlag) { | ||||
| 		this.regex = regex; | ||||
| 		this.regexFlag = regexFlag; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public FacetBuilder getFacet() { | ||||
| 		Assert.notEmpty(fields, "Please select at last one field !!!"); | ||||
| 		TermsFacetBuilder builder = FacetBuilders.termsFacet(getName()).fields(fields).size(size); | ||||
| 		switch (order) { | ||||
| 
 | ||||
| 			case descTerm: | ||||
| 				builder.order(TermsFacet.ComparatorType.REVERSE_TERM); | ||||
| 				break; | ||||
| 			case ascTerm: | ||||
| 				builder.order(TermsFacet.ComparatorType.TERM); | ||||
| 				break; | ||||
| 			case ascCount: | ||||
| 				builder.order(TermsFacet.ComparatorType.REVERSE_COUNT); | ||||
| 				break; | ||||
| 			default: | ||||
| 				builder.order(TermsFacet.ComparatorType.COUNT); | ||||
| 		} | ||||
| 		if (ArrayUtils.isNotEmpty(excludeTerms)) { | ||||
| 			builder.exclude(excludeTerms); | ||||
| 		} | ||||
| 
 | ||||
| 		if (allTerms) { | ||||
| 			builder.allTerms(allTerms); | ||||
| 		} | ||||
| 
 | ||||
| 		if (StringUtils.isNotBlank(regex)) { | ||||
| 			builder.regex(regex, regexFlag); | ||||
| 		} | ||||
| 
 | ||||
| 		return builder; | ||||
| 	} | ||||
| } | ||||
| */ | ||||
| @ -1,95 +0,0 @@ | ||||
| /* | ||||
|  * Copyright 2014 the original author or authors. | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  * You may obtain a copy of the License at | ||||
|  * | ||||
|  *      http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * | ||||
|  * Unless required by applicable law or agreed to in writing, software | ||||
|  * distributed under the License is distributed on an "AS IS" BASIS, | ||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  *//* | ||||
| 
 | ||||
| package org.springframework.data.elasticsearch.core.facet.request; | ||||
| 
 | ||||
| import org.springframework.data.elasticsearch.core.facet.FacetRequest; | ||||
| 
 | ||||
| */ | ||||
| /** | ||||
|  * Basic term facet | ||||
|  * | ||||
|  * @author Artur Konczak | ||||
|  *//* | ||||
| 
 | ||||
| public class TermFacetRequestBuilder { | ||||
| 
 | ||||
| 	private TermFacetRequest result; | ||||
| 
 | ||||
| 	public TermFacetRequestBuilder(String name) { | ||||
| 		result = new TermFacetRequest(name); | ||||
| 	} | ||||
| 
 | ||||
| 	public TermFacetRequestBuilder fields(String... fields) { | ||||
| 		result.setFields(fields); | ||||
| 		return this; | ||||
| 	} | ||||
| 
 | ||||
| 	public TermFacetRequestBuilder size(int size) { | ||||
| 		result.setSize(size); | ||||
| 		return this; | ||||
| 	} | ||||
| 
 | ||||
| 	public TermFacetRequestBuilder excludeTerms(Object... terms) { | ||||
| 		result.setExcludeTerms(terms); | ||||
| 		return this; | ||||
| 	} | ||||
| 
 | ||||
| 	public TermFacetRequestBuilder allTerms() { | ||||
| 		result.setAllTerms(true); | ||||
| 		return this; | ||||
| 	} | ||||
| 
 | ||||
| 	public TermFacetRequestBuilder regex(String regex) { | ||||
| 		result.setRegex(regex); | ||||
| 		return this; | ||||
| 	} | ||||
| 
 | ||||
| 	public TermFacetRequestBuilder regex(String regex, int regexFlag) { | ||||
| 		result.setRegex(regex, regexFlag); | ||||
| 		return this; | ||||
| 	} | ||||
| 
 | ||||
| 	public TermFacetRequestBuilder ascTerm() { | ||||
| 		result.setOrder(TermFacetOrder.ascTerm); | ||||
| 		return this; | ||||
| 	} | ||||
| 
 | ||||
| 	public TermFacetRequestBuilder descTerm() { | ||||
| 		result.setOrder(TermFacetOrder.descTerm); | ||||
| 		return this; | ||||
| 	} | ||||
| 
 | ||||
| 	public TermFacetRequestBuilder ascCount() { | ||||
| 		result.setOrder(TermFacetOrder.ascCount); | ||||
| 		return this; | ||||
| 	} | ||||
| 
 | ||||
| 	public TermFacetRequestBuilder descCount() { | ||||
| 		result.setOrder(TermFacetOrder.descCount); | ||||
| 		return this; | ||||
| 	} | ||||
| 
 | ||||
| 	public TermFacetRequestBuilder applyQueryFilter() { | ||||
| 		result.setApplyQueryFilter(true); | ||||
| 		return this; | ||||
| 	} | ||||
| 
 | ||||
| 	public FacetRequest build() { | ||||
| 		return result; | ||||
| 	} | ||||
| } | ||||
| */ | ||||
| @ -1,38 +0,0 @@ | ||||
| /* | ||||
|  * Copyright 2014 the original author or authors. | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  * You may obtain a copy of the License at | ||||
|  * | ||||
|  *      http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * | ||||
|  * Unless required by applicable law or agreed to in writing, software | ||||
|  * distributed under the License is distributed on an "AS IS" BASIS, | ||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  */ | ||||
| package org.springframework.data.elasticsearch.core.facet.result; | ||||
| 
 | ||||
| import java.util.List; | ||||
| 
 | ||||
| import org.springframework.data.elasticsearch.core.facet.AbstractFacetResult; | ||||
| import org.springframework.data.elasticsearch.core.facet.FacetType; | ||||
| 
 | ||||
| /** | ||||
|  * @author Artur Konczak | ||||
|  */ | ||||
| public class HistogramResult extends AbstractFacetResult { | ||||
| 
 | ||||
| 	private List<IntervalUnit> terms; | ||||
| 
 | ||||
| 	public HistogramResult(String name, List<IntervalUnit> terms) { | ||||
| 		super(name, FacetType.term); | ||||
| 		this.terms = terms; | ||||
| 	} | ||||
| 
 | ||||
| 	public List<IntervalUnit> getIntervalUnit() { | ||||
| 		return terms; | ||||
| 	} | ||||
| } | ||||
| @ -1,91 +0,0 @@ | ||||
| /* | ||||
|  * Copyright 2014 the original author or authors. | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  * You may obtain a copy of the License at | ||||
|  * | ||||
|  *      http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * | ||||
|  * Unless required by applicable law or agreed to in writing, software | ||||
|  * distributed under the License is distributed on an "AS IS" BASIS, | ||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  */ | ||||
| package org.springframework.data.elasticsearch.core.facet.result; | ||||
| 
 | ||||
| import java.text.SimpleDateFormat; | ||||
| import java.util.Date; | ||||
| 
 | ||||
| /** | ||||
|  * Single term | ||||
|  * | ||||
|  * @author Rizwan Idrees | ||||
|  * @author Mohsin Husen | ||||
|  * @author Artur Konczak | ||||
|  * @author Jonathan Yan | ||||
|  */ | ||||
| public class IntervalUnit { | ||||
| 
 | ||||
| 	private static final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm"); | ||||
| 
 | ||||
| 	long key; | ||||
| 	long count; | ||||
| 	long totalCount; | ||||
| 	double total; | ||||
| 	double mean; | ||||
| 	double min; | ||||
| 	double max; | ||||
| 
 | ||||
| 	public IntervalUnit(long key, long count, long totalCount, double total, double mean, double min, double max) { | ||||
| 		this.key = key; | ||||
| 		this.count = count; | ||||
| 		this.totalCount = totalCount; | ||||
| 		this.total = total; | ||||
| 		this.mean = mean; | ||||
| 		this.min = min; | ||||
| 		this.max = max; | ||||
| 	} | ||||
| 
 | ||||
| 	public long getKey() { | ||||
| 		return key; | ||||
| 	} | ||||
| 
 | ||||
| 	public long getCount() { | ||||
| 		return count; | ||||
| 	} | ||||
| 
 | ||||
| 	public long getTotalCount() { | ||||
| 		return totalCount; | ||||
| 	} | ||||
| 
 | ||||
| 	public double getTotal() { | ||||
| 		return total; | ||||
| 	} | ||||
| 
 | ||||
| 	public double getMean() { | ||||
| 		return mean; | ||||
| 	} | ||||
| 
 | ||||
| 	public double getMin() { | ||||
| 		return min; | ||||
| 	} | ||||
| 
 | ||||
| 	public double getMax() { | ||||
| 		return max; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public String toString() { | ||||
| 		return "IntervalUnit{" + | ||||
| 				"key=" + format.format(new Date(key)) + | ||||
| 				", count=" + count + | ||||
| 				", totalCount=" + totalCount + | ||||
| 				", total=" + total + | ||||
| 				", mean=" + mean + | ||||
| 				", min=" + min + | ||||
| 				", max=" + max + | ||||
| 				'}'; | ||||
| 	} | ||||
| } | ||||
| @ -1,78 +0,0 @@ | ||||
| /* | ||||
|  * Copyright 2014 the original author or authors. | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  * You may obtain a copy of the License at | ||||
|  * | ||||
|  *      http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * | ||||
|  * Unless required by applicable law or agreed to in writing, software | ||||
|  * distributed under the License is distributed on an "AS IS" BASIS, | ||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  */ | ||||
| package org.springframework.data.elasticsearch.core.facet.result; | ||||
| 
 | ||||
| /** | ||||
|  * Single range | ||||
|  * | ||||
|  * @author Rizwan Idrees | ||||
|  * @author Mohsin Husen | ||||
|  * @author Artur Konczak | ||||
|  * @author Jonathan Yan | ||||
|  */ | ||||
| public class Range { | ||||
| 
 | ||||
| 	private Double from; | ||||
| 	private Double to; | ||||
| 	private long count; | ||||
| 	private double total; | ||||
| 	private double totalCount; | ||||
| 	private double min = Double.POSITIVE_INFINITY; | ||||
| 	private double max = Double.NEGATIVE_INFINITY; | ||||
| 
 | ||||
| 	public Range(Double from, Double to, long count, double total, double totalCount, double min, double max) { | ||||
| 		this.from = from; | ||||
| 		this.to = to; | ||||
| 		this.count = count; | ||||
| 		this.total = total; | ||||
| 		this.totalCount = totalCount; | ||||
| 		this.min = min; | ||||
| 		this.max = max; | ||||
| 	} | ||||
| 
 | ||||
| 	public Double getFrom() { | ||||
| 		return from; | ||||
| 	} | ||||
| 
 | ||||
| 	public Double getTo() { | ||||
| 		return to; | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Return number of documents in range | ||||
| 	 * | ||||
| 	 * @return | ||||
| 	 */ | ||||
| 	public long getCount() { | ||||
| 		return count; | ||||
| 	} | ||||
| 
 | ||||
| 	public double getTotal() { | ||||
| 		return total; | ||||
| 	} | ||||
| 
 | ||||
| 	public double getTotalCount() { | ||||
| 		return totalCount; | ||||
| 	} | ||||
| 
 | ||||
| 	public double getMin() { | ||||
| 		return min; | ||||
| 	} | ||||
| 
 | ||||
| 	public double getMax() { | ||||
| 		return max; | ||||
| 	} | ||||
| } | ||||
| @ -1,43 +0,0 @@ | ||||
| /* | ||||
|  * Copyright 2014 the original author or authors. | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  * You may obtain a copy of the License at | ||||
|  * | ||||
|  *      http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * | ||||
|  * Unless required by applicable law or agreed to in writing, software | ||||
|  * distributed under the License is distributed on an "AS IS" BASIS, | ||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  */ | ||||
| package org.springframework.data.elasticsearch.core.facet.result; | ||||
| 
 | ||||
| import java.util.List; | ||||
| 
 | ||||
| import org.springframework.data.elasticsearch.core.facet.AbstractFacetResult; | ||||
| import org.springframework.data.elasticsearch.core.facet.FacetType; | ||||
| 
 | ||||
| /** | ||||
|  * Basic term facet result | ||||
|  * | ||||
|  * @author Rizwan Idrees | ||||
|  * @author Mohsin Husen | ||||
|  * @author Artur Konczak | ||||
|  * @author Jonathan Yan | ||||
|  */ | ||||
| public class RangeResult extends AbstractFacetResult { | ||||
| 
 | ||||
| 	private List<Range> ranges; | ||||
| 
 | ||||
| 	public RangeResult(String name, List<Range> ranges) { | ||||
| 		super(name, FacetType.range); | ||||
| 		this.ranges = ranges; | ||||
| 	} | ||||
| 
 | ||||
| 	public List<Range> getRanges() { | ||||
| 		return ranges; | ||||
| 	} | ||||
| } | ||||
| @ -1,85 +0,0 @@ | ||||
| /* | ||||
|  * Copyright 2014 the original author or authors. | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  * You may obtain a copy of the License at | ||||
|  * | ||||
|  *      http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * | ||||
|  * Unless required by applicable law or agreed to in writing, software | ||||
|  * distributed under the License is distributed on an "AS IS" BASIS, | ||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  */ | ||||
| package org.springframework.data.elasticsearch.core.facet.result; | ||||
| 
 | ||||
| import org.springframework.data.elasticsearch.core.facet.AbstractFacetResult; | ||||
| import org.springframework.data.elasticsearch.core.facet.FacetType; | ||||
| 
 | ||||
| /** | ||||
|  * @author Petar Tahchiev | ||||
|  */ | ||||
| public class StatisticalResult extends AbstractFacetResult { | ||||
| 
 | ||||
| 	private long count; | ||||
| 
 | ||||
| 	private double max; | ||||
| 
 | ||||
| 	private double min; | ||||
| 
 | ||||
| 	private double mean; | ||||
| 
 | ||||
| 	private double stdDeviation; | ||||
| 
 | ||||
| 	private double sumOfSquares; | ||||
| 
 | ||||
| 	private double total; | ||||
| 
 | ||||
| 	private double variance; | ||||
| 
 | ||||
| 	public StatisticalResult(String name, long count, double max, double min, double mean, double stdDeviation, double sumOfSquares, double total, double variance) { | ||||
| 		super(name, FacetType.statistical); | ||||
| 		this.count = count; | ||||
| 		this.max = max; | ||||
| 		this.min = min; | ||||
| 		this.mean = mean; | ||||
| 		this.stdDeviation = stdDeviation; | ||||
| 		this.sumOfSquares = sumOfSquares; | ||||
| 		this.total = total; | ||||
| 		this.variance = variance; | ||||
| 	} | ||||
| 
 | ||||
| 	public long getCount() { | ||||
| 		return count; | ||||
| 	} | ||||
| 
 | ||||
| 	public double getMax() { | ||||
| 		return max; | ||||
| 	} | ||||
| 
 | ||||
| 	public double getMin() { | ||||
| 		return min; | ||||
| 	} | ||||
| 
 | ||||
| 	public double getMean() { | ||||
| 		return mean; | ||||
| 	} | ||||
| 
 | ||||
| 	public double getStdDeviation() { | ||||
| 		return stdDeviation; | ||||
| 	} | ||||
| 
 | ||||
| 	public double getSumOfSquares() { | ||||
| 		return sumOfSquares; | ||||
| 	} | ||||
| 
 | ||||
| 	public double getTotal() { | ||||
| 		return total; | ||||
| 	} | ||||
| 
 | ||||
| 	public double getVariance() { | ||||
| 		return variance; | ||||
| 	} | ||||
| } | ||||
| @ -1,43 +0,0 @@ | ||||
| /* | ||||
|  * Copyright 2014 the original author or authors. | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  * You may obtain a copy of the License at | ||||
|  * | ||||
|  *      http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * | ||||
|  * Unless required by applicable law or agreed to in writing, software | ||||
|  * distributed under the License is distributed on an "AS IS" BASIS, | ||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  */ | ||||
| package org.springframework.data.elasticsearch.core.facet.result; | ||||
| 
 | ||||
| /** | ||||
|  * Single term | ||||
|  * | ||||
|  * @author Rizwan Idrees | ||||
|  * @author Mohsin Husen | ||||
|  * @author Artur Konczak | ||||
|  * @author Jonathan Yan | ||||
|  */ | ||||
| public class Term { | ||||
| 
 | ||||
| 	private String term; | ||||
| 	private int count; | ||||
| 
 | ||||
| 	public Term(String term, int count) { | ||||
| 		this.term = term; | ||||
| 		this.count = count; | ||||
| 	} | ||||
| 
 | ||||
| 	public String getTerm() { | ||||
| 		return term; | ||||
| 	} | ||||
| 
 | ||||
| 	public int getCount() { | ||||
| 		return count; | ||||
| 	} | ||||
| } | ||||
| @ -1,62 +0,0 @@ | ||||
| /* | ||||
|  * Copyright 2014 the original author or authors. | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  * You may obtain a copy of the License at | ||||
|  * | ||||
|  *      http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * | ||||
|  * Unless required by applicable law or agreed to in writing, software | ||||
|  * distributed under the License is distributed on an "AS IS" BASIS, | ||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  */ | ||||
| package org.springframework.data.elasticsearch.core.facet.result; | ||||
| 
 | ||||
| import java.util.List; | ||||
| 
 | ||||
| import org.springframework.data.elasticsearch.core.facet.AbstractFacetResult; | ||||
| import org.springframework.data.elasticsearch.core.facet.FacetType; | ||||
| 
 | ||||
| /** | ||||
|  * Basic term facet result | ||||
|  * | ||||
|  * @author Rizwan Idrees | ||||
|  * @author Mohsin Husen | ||||
|  * @author Artur Konczak | ||||
|  * @author Jonathan Yan | ||||
|  * @author Matija Obreza | ||||
|  */ | ||||
| public class TermResult extends AbstractFacetResult { | ||||
| 
 | ||||
| 	private List<Term> terms; | ||||
| 	private long total; | ||||
| 	private long other; | ||||
| 	private long missing; | ||||
| 
 | ||||
| 	public TermResult(String name, List<Term> terms, long total, long other, long missing) { | ||||
| 		super(name, FacetType.term); | ||||
| 		this.terms = terms; | ||||
| 		this.total = total; | ||||
| 		this.other = other; | ||||
| 		this.missing = missing; | ||||
| 	} | ||||
| 
 | ||||
| 	public List<Term> getTerms() { | ||||
| 		return terms; | ||||
| 	} | ||||
| 	 | ||||
| 	public long getTotal() { | ||||
| 		return total; | ||||
| 	} | ||||
| 	 | ||||
| 	public long getOther() { | ||||
| 		return other; | ||||
| 	} | ||||
| 	 | ||||
| 	public long getMissing() { | ||||
| 		return missing; | ||||
| 	} | ||||
| } | ||||
| @ -20,7 +20,6 @@ import java.io.Serializable; | ||||
| import org.elasticsearch.index.query.QueryBuilder; | ||||
| import org.springframework.data.domain.Page; | ||||
| import org.springframework.data.domain.Pageable; | ||||
| import org.springframework.data.elasticsearch.core.FacetedPage; | ||||
| import org.springframework.data.elasticsearch.core.query.SearchQuery; | ||||
| import org.springframework.data.repository.NoRepositoryBean; | ||||
| 
 | ||||
| @ -37,9 +36,9 @@ public interface ElasticsearchRepository<T, ID extends Serializable> extends Ela | ||||
| 
 | ||||
| 	Iterable<T> search(QueryBuilder query); | ||||
| 
 | ||||
| 	FacetedPage<T> search(QueryBuilder query, Pageable pageable); | ||||
| 	Page<T> search(QueryBuilder query, Pageable pageable); | ||||
| 
 | ||||
| 	FacetedPage<T> search(SearchQuery searchQuery); | ||||
| 	Page<T> search(SearchQuery searchQuery); | ||||
| 
 | ||||
| 	Page<T> searchSimilar(T entity, String[] fields, Pageable pageable); | ||||
| } | ||||
|  | ||||
| @ -21,7 +21,6 @@ import java.io.Serializable; | ||||
| import java.lang.reflect.ParameterizedType; | ||||
| import java.lang.reflect.Type; | ||||
| import java.util.ArrayList; | ||||
| import java.util.Collection; | ||||
| import java.util.Collections; | ||||
| import java.util.List; | ||||
| 
 | ||||
| @ -32,7 +31,6 @@ import org.slf4j.LoggerFactory; | ||||
| import org.springframework.dao.InvalidDataAccessApiUsageException; | ||||
| import org.springframework.data.domain.*; | ||||
| import org.springframework.data.elasticsearch.core.ElasticsearchOperations; | ||||
| import org.springframework.data.elasticsearch.core.FacetedPage; | ||||
| import org.springframework.data.elasticsearch.core.query.*; | ||||
| import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; | ||||
| import org.springframework.util.Assert; | ||||
| @ -192,13 +190,13 @@ public abstract class AbstractElasticsearchRepository<T, ID extends Serializable | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public FacetedPage<T> search(QueryBuilder query, Pageable pageable) { | ||||
| 	public Page<T> search(QueryBuilder query, Pageable pageable) { | ||||
| 		SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(query).withPageable(pageable).build(); | ||||
| 		return elasticsearchOperations.queryForPage(searchQuery, getEntityClass()); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public FacetedPage<T> search(SearchQuery query) { | ||||
| 	public Page<T> search(SearchQuery query) { | ||||
| 		return elasticsearchOperations.queryForPage(query, getEntityClass()); | ||||
| 	} | ||||
| 
 | ||||
|  | ||||
| @ -20,6 +20,7 @@ import java.util.LinkedList; | ||||
| import org.elasticsearch.action.get.GetResponse; | ||||
| import org.elasticsearch.action.get.MultiGetResponse; | ||||
| import org.elasticsearch.action.search.SearchResponse; | ||||
| import org.springframework.data.domain.Page; | ||||
| import org.springframework.data.domain.Pageable; | ||||
| 
 | ||||
| /** | ||||
| @ -46,7 +47,7 @@ public class CustomResultMapper implements ResultsMapper { | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public <T> FacetedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) { | ||||
| 	public <T> Page<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) { | ||||
| 		return null;  //To change body of implemented methods use File | Settings | File Templates. | ||||
| 	} | ||||
| 
 | ||||
|  | ||||
| @ -34,6 +34,7 @@ import org.junit.Before; | ||||
| import org.junit.Test; | ||||
| import org.mockito.Mock; | ||||
| import org.mockito.MockitoAnnotations; | ||||
| import org.springframework.data.domain.Page; | ||||
| import org.springframework.data.elasticsearch.entities.Car; | ||||
| 
 | ||||
| /** | ||||
| @ -63,7 +64,7 @@ public class DefaultResultMapperTests { | ||||
| 		when(response.getHits()).thenReturn(searchHits); | ||||
| 
 | ||||
| 		//When | ||||
| 		FacetedPage<Car> page = resultMapper.mapResults(response, Car.class, null); | ||||
| 		Page<Car> page = resultMapper.mapResults(response, Car.class, null); | ||||
| 
 | ||||
| 		//Then | ||||
| 		assertThat(page.hasContent(), is(true)); | ||||
| @ -81,7 +82,7 @@ public class DefaultResultMapperTests { | ||||
| 		when(response.getHits()).thenReturn(searchHits); | ||||
| 
 | ||||
| 		//When | ||||
| 		FacetedPage<Car> page = resultMapper.mapResults(response, Car.class, null); | ||||
| 		Page<Car> page = resultMapper.mapResults(response, Car.class, null); | ||||
| 
 | ||||
| 		//Then | ||||
| 		assertThat(page.hasContent(), is(true)); | ||||
|  | ||||
| @ -41,10 +41,7 @@ import org.junit.Ignore; | ||||
| import org.junit.Test; | ||||
| import org.junit.runner.RunWith; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.data.domain.Page; | ||||
| import org.springframework.data.domain.PageRequest; | ||||
| import org.springframework.data.domain.Pageable; | ||||
| import org.springframework.data.domain.Sort; | ||||
| import org.springframework.data.domain.*; | ||||
| import org.springframework.data.elasticsearch.ElasticsearchException; | ||||
| import org.springframework.data.elasticsearch.annotations.Document; | ||||
| import org.springframework.data.elasticsearch.core.query.*; | ||||
| @ -490,7 +487,8 @@ public class ElasticsearchTemplateTests { | ||||
| 		// when | ||||
| 		SearchQuery searchQuery = new NativeSearchQueryBuilder() | ||||
| 				.withQuery(matchAllQuery()) | ||||
| 				.withScriptField(new ScriptField("scriptedRate", new Script("doc['rate'].value * factor", ScriptService.ScriptType.INLINE, "groovy", params))) | ||||
| 				.withScriptField(new ScriptField("scriptedRate", | ||||
| 						new Script("doc['rate'].value * factor", ScriptService.ScriptType.INLINE, null , params))) | ||||
| 						.build(); | ||||
| 		Page<SampleEntity> sampleEntities = elasticsearchTemplate.queryForPage(searchQuery, SampleEntity.class); | ||||
| 		// then | ||||
| @ -521,7 +519,6 @@ public class ElasticsearchTemplateTests { | ||||
| 	@Test | ||||
| 	@Ignore("By default, the search request will fail if there is no mapping associated with a field. The ignore_unmapped option allows to ignore fields that have no mapping and not sort by them") | ||||
| 	public void shouldReturnSortedPageableResultsGivenStringQuery() { | ||||
| 		// todo | ||||
| 		// given | ||||
| 		String documentId = randomNumeric(5); | ||||
| 		SampleEntity sampleEntity = new SampleEntity(); | ||||
| @ -633,12 +630,12 @@ public class ElasticsearchTemplateTests { | ||||
| 		// when | ||||
| 		Page<String> page = elasticsearchTemplate.queryForPage(searchQuery, String.class, new SearchResultMapper() { | ||||
| 			@Override | ||||
| 			public <T> FacetedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) { | ||||
| 			public <T> Page<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) { | ||||
| 				List<String> values = new ArrayList<String>(); | ||||
| 				for (SearchHit searchHit : response.getHits()) { | ||||
| 					values.add((String) searchHit.field("message").value()); | ||||
| 				} | ||||
| 				return new FacetedPageImpl<T>((List<T>) values); | ||||
| 				return new PageImpl<T>((List<T>) values); | ||||
| 			} | ||||
| 		}); | ||||
| 		// then | ||||
| @ -763,7 +760,7 @@ public class ElasticsearchTemplateTests { | ||||
| 		while (hasRecords) { | ||||
| 			Page<SampleEntity> page = elasticsearchTemplate.scroll(scrollId, 5000L, new SearchResultMapper() { | ||||
| 				@Override | ||||
| 				public <T> FacetedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) { | ||||
| 				public <T> Page<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) { | ||||
| 					List<SampleEntity> result = new ArrayList<SampleEntity>(); | ||||
| 					for (SearchHit searchHit : response.getHits()) { | ||||
| 						String message = searchHit.getFields().get("message").getValue(); | ||||
| @ -774,7 +771,7 @@ public class ElasticsearchTemplateTests { | ||||
| 					} | ||||
| 
 | ||||
| 					if (result.size() > 0) { | ||||
| 						return new FacetedPageImpl<T>((List<T>) result); | ||||
| 						return new PageImpl<T>((List<T>) result); | ||||
| 					} | ||||
| 					return null; | ||||
| 				} | ||||
| @ -814,7 +811,7 @@ public class ElasticsearchTemplateTests { | ||||
| 		while (hasRecords) { | ||||
| 			Page<SampleEntity> page = elasticsearchTemplate.scroll(scrollId, 10000L, new SearchResultMapper() { | ||||
| 				@Override | ||||
| 				public <T> FacetedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) { | ||||
| 				public <T> Page<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) { | ||||
| 					List<SampleEntity> result = new ArrayList<SampleEntity>(); | ||||
| 					for (SearchHit searchHit : response.getHits()) { | ||||
| 						String message = searchHit.getFields().get("message").getValue(); | ||||
| @ -825,7 +822,7 @@ public class ElasticsearchTemplateTests { | ||||
| 					} | ||||
| 
 | ||||
| 					if (result.size() > 0) { | ||||
| 						return new FacetedPageImpl<T>((List<T>) result); | ||||
| 						return new PageImpl<T>((List<T>) result); | ||||
| 					} | ||||
| 					return null; | ||||
| 				} | ||||
| @ -862,7 +859,7 @@ public class ElasticsearchTemplateTests { | ||||
| 		while (hasRecords) { | ||||
| 			Page<SampleEntity> page = elasticsearchTemplate.scroll(scrollId, 5000L, new SearchResultMapper() { | ||||
| 				@Override | ||||
| 				public <T> FacetedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) { | ||||
| 				public <T> Page<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) { | ||||
| 					List<SampleEntity> chunk = new ArrayList<SampleEntity>(); | ||||
| 					for (SearchHit searchHit : response.getHits()) { | ||||
| 						if (response.getHits().getHits().length <= 0) { | ||||
| @ -874,7 +871,7 @@ public class ElasticsearchTemplateTests { | ||||
| 						chunk.add(user); | ||||
| 					} | ||||
| 					if (chunk.size() > 0) { | ||||
| 						return new FacetedPageImpl<T>((List<T>) chunk); | ||||
| 						return new PageImpl<T>((List<T>) chunk); | ||||
| 					} | ||||
| 					return null; | ||||
| 				} | ||||
| @ -906,7 +903,7 @@ public class ElasticsearchTemplateTests { | ||||
| 		while (hasRecords) { | ||||
| 			Page<SampleEntity> page = elasticsearchTemplate.scroll(scrollId, 5000L, new SearchResultMapper() { | ||||
| 				@Override | ||||
| 				public <T> FacetedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) { | ||||
| 				public <T> Page<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) { | ||||
| 					List<SampleEntity> chunk = new ArrayList<SampleEntity>(); | ||||
| 					for (SearchHit searchHit : response.getHits()) { | ||||
| 						if (response.getHits().getHits().length <= 0) { | ||||
| @ -918,7 +915,7 @@ public class ElasticsearchTemplateTests { | ||||
| 						chunk.add(user); | ||||
| 					} | ||||
| 					if (chunk.size() > 0) { | ||||
| 						return new FacetedPageImpl<T>((List<T>) chunk); | ||||
| 						return new PageImpl<T>((List<T>) chunk); | ||||
| 					} | ||||
| 					return null; | ||||
| 				} | ||||
| @ -1209,7 +1206,7 @@ public class ElasticsearchTemplateTests { | ||||
| 
 | ||||
| 		Page<SampleEntity> sampleEntities = elasticsearchTemplate.queryForPage(searchQuery, SampleEntity.class, new SearchResultMapper() { | ||||
| 			@Override | ||||
| 			public <T> FacetedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) { | ||||
| 			public <T> Page<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) { | ||||
| 				List<SampleEntity> chunk = new ArrayList<SampleEntity>(); | ||||
| 				for (SearchHit searchHit : response.getHits()) { | ||||
| 					if (response.getHits().getHits().length <= 0) { | ||||
| @ -1222,7 +1219,7 @@ public class ElasticsearchTemplateTests { | ||||
| 					chunk.add(user); | ||||
| 				} | ||||
| 				if (chunk.size() > 0) { | ||||
| 					return new FacetedPageImpl<T>((List<T>) chunk); | ||||
| 					return new PageImpl<T>((List<T>) chunk); | ||||
| 				} | ||||
| 				return null; | ||||
| 			} | ||||
| @ -1275,7 +1272,7 @@ public class ElasticsearchTemplateTests { | ||||
| 		// then | ||||
| 		Page<SampleEntity> page = elasticsearchTemplate.queryForPage(searchQuery, SampleEntity.class, new SearchResultMapper() { | ||||
| 			@Override | ||||
| 			public <T> FacetedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) { | ||||
| 			public <T> Page<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) { | ||||
| 				List<SampleEntity> values = new ArrayList<SampleEntity>(); | ||||
| 				for (SearchHit searchHit : response.getHits()) { | ||||
| 					SampleEntity sampleEntity = new SampleEntity(); | ||||
| @ -1283,7 +1280,7 @@ public class ElasticsearchTemplateTests { | ||||
| 					sampleEntity.setMessage((String) searchHit.getSource().get("message")); | ||||
| 					values.add(sampleEntity); | ||||
| 				} | ||||
| 				return new FacetedPageImpl<T>((List<T>) values); | ||||
| 				return new PageImpl<T>((List<T>) values); | ||||
| 			} | ||||
| 		}); | ||||
| 		assertThat(page, is(notNullValue())); | ||||
| @ -1445,7 +1442,7 @@ public class ElasticsearchTemplateTests { | ||||
| 				.withTypes(TYPE_NAME).withQuery(matchAllQuery()).build(); | ||||
| 		Page<Map> sampleEntities = elasticsearchTemplate.queryForPage(searchQuery, Map.class, new SearchResultMapper() { | ||||
| 			@Override | ||||
| 			public <T> FacetedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) { | ||||
| 			public <T> Page<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) { | ||||
| 				List<Map> chunk = new ArrayList<Map>(); | ||||
| 				for (SearchHit searchHit : response.getHits()) { | ||||
| 					if (response.getHits().getHits().length <= 0) { | ||||
| @ -1460,7 +1457,7 @@ public class ElasticsearchTemplateTests { | ||||
| 					chunk.add(person); | ||||
| 				} | ||||
| 				if (chunk.size() > 0) { | ||||
| 					return new FacetedPageImpl<T>((List<T>) chunk); | ||||
| 					return new PageImpl<T>((List<T>) chunk); | ||||
| 				} | ||||
| 				return null; | ||||
| 			} | ||||
| @ -1959,7 +1956,7 @@ public class ElasticsearchTemplateTests { | ||||
| 		SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).withTypes("hetro").withIndices(INDEX_1_NAME, INDEX_2_NAME).build(); | ||||
| 		Page<ResultAggregator> page = elasticsearchTemplate.queryForPage(searchQuery, ResultAggregator.class, new SearchResultMapper() { | ||||
| 			@Override | ||||
| 			public <T> FacetedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) { | ||||
| 			public <T> Page<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) { | ||||
| 				List<ResultAggregator> values = new ArrayList<ResultAggregator>(); | ||||
| 				for (SearchHit searchHit : response.getHits()) { | ||||
| 					String id = String.valueOf(searchHit.getSource().get("id")); | ||||
| @ -1967,7 +1964,7 @@ public class ElasticsearchTemplateTests { | ||||
| 					String lastName = StringUtils.isNotEmpty((String) searchHit.getSource().get("lastName")) ? (String) searchHit.getSource().get("lastName") : ""; | ||||
| 					values.add(new ResultAggregator(id, firstName, lastName)); | ||||
| 				} | ||||
| 				return new FacetedPageImpl<T>((List<T>) values); | ||||
| 				return new PageImpl<T>((List<T>) values); | ||||
| 			} | ||||
| 		}); | ||||
| 
 | ||||
|  | ||||
| @ -350,7 +350,6 @@ public class CriteriaQueryTests { | ||||
| 	@Test | ||||
| 	public void shouldExecuteExpression() { | ||||
| 		// given | ||||
| 		// todo | ||||
| 		List<IndexQuery> indexQueries = new ArrayList<IndexQuery>(); | ||||
| 		// first document | ||||
| 		String documentId = randomNumeric(5); | ||||
|  | ||||
| @ -19,6 +19,8 @@ import lombok.*; | ||||
| import org.springframework.data.annotation.Id; | ||||
| import org.springframework.data.annotation.Version; | ||||
| import org.springframework.data.elasticsearch.annotations.Document; | ||||
| import org.springframework.data.elasticsearch.annotations.Field; | ||||
| import org.springframework.data.elasticsearch.annotations.FieldType; | ||||
| import org.springframework.data.elasticsearch.annotations.ScriptedField; | ||||
| import org.springframework.data.elasticsearch.core.geo.GeoPoint; | ||||
| 
 | ||||
| @ -38,6 +40,7 @@ public class SampleEntity { | ||||
| 	@Id | ||||
| 	private String id; | ||||
| 	private String type; | ||||
| 	@Field(type = FieldType.String) | ||||
| 	private String message; | ||||
| 	private int rate; | ||||
| 	@ScriptedField | ||||
|  | ||||
| @ -32,7 +32,7 @@ grant { | ||||
| 
 | ||||
|   // Standard set of classes | ||||
|   permission org.elasticsearch.script.ClassPermission "<<STANDARD>>"; | ||||
|   // groovy runtime (TODO: clean these up if possible) | ||||
|   // groovy runtime | ||||
|   permission org.elasticsearch.script.ClassPermission "groovy.grape.GrabAnnotationTransformation"; | ||||
|   permission org.elasticsearch.script.ClassPermission "groovy.json.JsonOutput"; | ||||
|   permission org.elasticsearch.script.ClassPermission "groovy.lang.Binding"; | ||||
|  | ||||
| @ -11,8 +11,8 @@ Import-Template: | ||||
|  org.apache.commons.collections.*;version="${commonscollections:[=.=.=,+1.0.0)}";resolution:=optional, | ||||
|  org.apache.commons.lang.*;version="${commonslang:[=.=.=,+1.0.0)}", | ||||
|  com.fasterxml.jackson.*;version="${jackson:[=.=.=,+1.0.0)}";resolution:=optional, | ||||
|  org.elasticsearch.*;version="${elasticsearch:[=.=.=,+1.4.4)}", | ||||
|  org.apache.lucene.*;version="4.10.4", | ||||
|  org.elasticsearch.*;version="${elasticsearch:[=.=.=,2.2.0)}", | ||||
|  org.apache.lucene.*;version="5.4.1", | ||||
|  org.joda.time.*;version="${jodatime:[=.=.=,+1.0.0)}", | ||||
|  org.slf4j.*;version="${slf4j:[=.=.=,+1.0.0)}", | ||||
|  org.springframework.*;version="${spring:[=.=.=.=,+1.0.0)}", | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user