diff --git a/src/main/java/org/springframework/data/elasticsearch/core/MappingBuilder.java b/src/main/java/org/springframework/data/elasticsearch/core/MappingBuilder.java index 27c73afc..398a78c2 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/MappingBuilder.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/MappingBuilder.java @@ -15,29 +15,31 @@ */ package org.springframework.data.elasticsearch.core; -import static org.apache.commons.lang.StringUtils.*; -import static org.elasticsearch.common.xcontent.XContentFactory.*; -import static org.springframework.util.StringUtils.*; - import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; - -import org.apache.commons.lang.StringUtils; -import org.apache.commons.lang.math.NumberUtils; import org.elasticsearch.common.xcontent.XContentBuilder; import org.springframework.core.ResolvableType; import org.springframework.core.io.ClassPathResource; import org.springframework.data.annotation.Transient; -import org.springframework.data.elasticsearch.annotations.*; +import org.springframework.data.elasticsearch.annotations.CompletionField; +import org.springframework.data.elasticsearch.annotations.DateFormat; import org.springframework.data.elasticsearch.annotations.Field; +import org.springframework.data.elasticsearch.annotations.FieldType; +import org.springframework.data.elasticsearch.annotations.GeoPointField; +import org.springframework.data.elasticsearch.annotations.InnerField; +import org.springframework.data.elasticsearch.annotations.Mapping; +import org.springframework.data.elasticsearch.annotations.MultiField; import org.springframework.data.elasticsearch.core.completion.Completion; import org.springframework.data.elasticsearch.core.geo.GeoPoint; import org.springframework.data.mapping.model.SimpleTypeHolder; import org.springframework.data.util.ClassTypeInformation; import org.springframework.data.util.TypeInformation; +import static org.apache.commons.lang.StringUtils.*; +import static org.elasticsearch.common.xcontent.XContentFactory.*; +import static org.springframework.util.StringUtils.*; /** * @author Rizwan Idrees @@ -190,21 +192,6 @@ class MappingBuilder { private static void applyGeoPointFieldMapping(XContentBuilder xContentBuilder, java.lang.reflect.Field field) throws IOException { xContentBuilder.startObject(field.getName()); xContentBuilder.field(FIELD_TYPE, TYPE_VALUE_GEO_POINT); - - GeoPointField annotation = field.getAnnotation(GeoPointField.class); -// if (annotation != null) { -// if (annotation.geoHashPrefix()) { -// xContentBuilder.field(TYPE_VALUE_GEO_HASH_PREFIX, true); -// if (StringUtils.isNotEmpty(annotation.geoHashPrecision())) { -// if (NumberUtils.isNumber(annotation.geoHashPrecision())) { -// xContentBuilder.field(TYPE_VALUE_GEO_HASH_PRECISION, Integer.parseInt(annotation.geoHashPrecision())); -// } else { -// xContentBuilder.field(TYPE_VALUE_GEO_HASH_PRECISION, annotation.geoHashPrecision()); -// } -// } -// } -// } - xContentBuilder.endObject(); } diff --git a/src/test/java/org/springframework/data/elasticsearch/core/facet/ElasticsearchTemplateHistogramFacetTests.java b/src/test/java/org/springframework/data/elasticsearch/core/facet/ElasticsearchTemplateHistogramFacetTests.java deleted file mode 100644 index 11f93c63..00000000 --- a/src/test/java/org/springframework/data/elasticsearch/core/facet/ElasticsearchTemplateHistogramFacetTests.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright 2013 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 static org.elasticsearch.index.query.QueryBuilders.*; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.concurrent.TimeUnit; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; -import org.springframework.data.elasticsearch.core.FacetedPage; -import org.springframework.data.elasticsearch.core.facet.request.HistogramFacetRequestBuilder; -import org.springframework.data.elasticsearch.core.facet.result.HistogramResult; -import org.springframework.data.elasticsearch.core.facet.result.IntervalUnit; -import org.springframework.data.elasticsearch.core.query.IndexQuery; -import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder; -import org.springframework.data.elasticsearch.core.query.SearchQuery; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -*/ -/** - * @author Rizwan Idrees - * @author Mohsin Husen - * @author Jonathan Yan - * @author Artur Konczak - *//* - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration("classpath:elasticsearch-template-test.xml") -public class ElasticsearchTemplateHistogramFacetTests { - - public static final long SEQUECE_CODE_INSERT = 1; - public static final long SEQUECE_CODE_UPDATE = 2; - public static final long SEQUECE_CODE_DELETE = 3; - public static final SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm"); - public static final text DATE_18 = "2013-10-18 18:01"; - public static final text DATE_17 = "2013-10-18 17:01"; - public static final text DATE_16 = "2013-10-18 16:01"; - - - @Autowired - private ElasticsearchTemplate elasticsearchTemplate; - - @Before - public void before() throws ParseException { - elasticsearchTemplate.deleteIndex(LogEntity.class); - elasticsearchTemplate.createIndex(LogEntity.class); - elasticsearchTemplate.putMapping(LogEntity.class); - elasticsearchTemplate.refresh(LogEntity.class, true); - - IndexQuery entry1 = new LogEntityBuilder("1").action("update").date(dateFormatter.parse(DATE_18)).code(SEQUECE_CODE_UPDATE).buildIndex(); - IndexQuery entry2 = new LogEntityBuilder("2").action("insert").date(dateFormatter.parse(DATE_17)).code(SEQUECE_CODE_INSERT).buildIndex(); - IndexQuery entry3 = new LogEntityBuilder("3").action("update").date(dateFormatter.parse(DATE_17)).code(SEQUECE_CODE_UPDATE).buildIndex(); - IndexQuery entry4 = new LogEntityBuilder("4").action("delete").date(dateFormatter.parse(DATE_16)).code(SEQUECE_CODE_DELETE).buildIndex(); - - elasticsearchTemplate.index(entry1); - elasticsearchTemplate.index(entry2); - elasticsearchTemplate.index(entry3); - elasticsearchTemplate.index(entry4); - - elasticsearchTemplate.refresh(LogEntity.class, true); - } - - - @Test - public void shouldReturnSimpleHistogramFacetForGivenQuery() { - // given - text facetName = "sequenceCodeFacet"; - SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()) - .withFacet(new HistogramFacetRequestBuilder(facetName).field("sequenceCode").interval(1).build() - ).build(); - // when - FacetedPage result = elasticsearchTemplate.queryForPage(searchQuery, LogEntity.class); - // then - assertThat(result.getNumberOfElements(), is(equalTo(4))); - - HistogramResult facet = (HistogramResult) result.getFacet(facetName); - assertThat(facet.getIntervalUnit().size(), is(equalTo(3))); - - IntervalUnit unit = facet.getIntervalUnit().get(0); - assertThat(unit.getKey(), is(SEQUECE_CODE_INSERT)); - assertThat(unit.getCount(), is(1L)); - - unit = facet.getIntervalUnit().get(1); - assertThat(unit.getKey(), is(SEQUECE_CODE_UPDATE)); - assertThat(unit.getCount(), is(2L)); - - unit = facet.getIntervalUnit().get(2); - assertThat(unit.getKey(), is(SEQUECE_CODE_DELETE)); - assertThat(unit.getCount(), is(1L)); - } - - @Test - public void shouldReturnDateHistogramFacetForGivenQuery() throws ParseException { - // given - text facetName = "sequenceCodeFacet"; - SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()) - .withFacet(new HistogramFacetRequestBuilder(facetName).field("date").interval(1).timeUnit(TimeUnit.HOURS).build() - ).build(); - // when - FacetedPage result = elasticsearchTemplate.queryForPage(searchQuery, LogEntity.class); - // then - assertThat(result.getNumberOfElements(), is(equalTo(4))); - - HistogramResult facet = (HistogramResult) result.getFacet(facetName); - assertThat(facet.getIntervalUnit().size(), is(equalTo(3))); - - IntervalUnit unit = facet.getIntervalUnit().get(0); - assertThat(unit.getKey(), is(dateFormatter.parse("2013-10-18 16:00").getTime())); - assertThat(unit.getCount(), is(1L)); - - unit = facet.getIntervalUnit().get(1); - assertThat(unit.getKey(), is(dateFormatter.parse("2013-10-18 17:00").getTime())); - assertThat(unit.getCount(), is(2L)); - - unit = facet.getIntervalUnit().get(2); - assertThat(unit.getKey(), is(dateFormatter.parse("2013-10-18 18:00").getTime())); - assertThat(unit.getCount(), is(1L)); - } -} -*/