1
0
mirror of https://github.com/chatopera/cosin.git synced 2025-08-05 20:41:34 +08:00

Fix HighlightBuilder's package path

This commit is contained in:
dengchao@xgtl 2020-04-16 10:16:06 +08:00
parent 72545a9db7
commit 7bfe151a0e
6 changed files with 420 additions and 420 deletions

View File

@ -21,7 +21,7 @@ import com.chatopera.cc.model.Topic;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.elasticsearch.index.query.Operator; import org.elasticsearch.index.query.Operator;
import org.elasticsearch.index.query.QueryStringQueryBuilder; import org.elasticsearch.index.query.QueryStringQueryBuilder;
import org.elasticsearch.search.highlight.HighlightBuilder; import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
import org.elasticsearch.search.sort.FieldSortBuilder; import org.elasticsearch.search.sort.FieldSortBuilder;
import org.elasticsearch.search.sort.SortOrder; import org.elasticsearch.search.sort.SortOrder;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;

View File

@ -19,7 +19,7 @@ package com.chatopera.cc.persistence.es;
import com.chatopera.cc.model.KbsTopic; import com.chatopera.cc.model.KbsTopic;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.elasticsearch.index.query.*; import org.elasticsearch.index.query.*;
import org.elasticsearch.search.highlight.HighlightBuilder; import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
import org.elasticsearch.search.sort.FieldSortBuilder; import org.elasticsearch.search.sort.FieldSortBuilder;
import org.elasticsearch.search.sort.SortOrder; import org.elasticsearch.search.sort.SortOrder;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;

View File

@ -20,7 +20,7 @@ import com.chatopera.cc.basic.MainContext;
import com.chatopera.cc.model.QuickReply; import com.chatopera.cc.model.QuickReply;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.elasticsearch.index.query.*; import org.elasticsearch.index.query.*;
import org.elasticsearch.search.highlight.HighlightBuilder; import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
import org.elasticsearch.search.sort.FieldSortBuilder; import org.elasticsearch.search.sort.FieldSortBuilder;
import org.elasticsearch.search.sort.SortOrder; import org.elasticsearch.search.sort.SortOrder;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;

View File

@ -20,7 +20,7 @@ import com.chatopera.cc.model.Topic;
import com.chatopera.cc.persistence.repository.XiaoEUKResultMapper; import com.chatopera.cc.persistence.repository.XiaoEUKResultMapper;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.elasticsearch.index.query.*; import org.elasticsearch.index.query.*;
import org.elasticsearch.search.highlight.HighlightBuilder; import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
import org.elasticsearch.search.sort.FieldSortBuilder; import org.elasticsearch.search.sort.FieldSortBuilder;
import org.elasticsearch.search.sort.SortOrder; import org.elasticsearch.search.sort.SortOrder;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;

View File

@ -27,7 +27,7 @@ import org.elasticsearch.action.get.MultiGetResponse;
import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHitField; import org.elasticsearch.search.SearchHitField;
import org.elasticsearch.search.highlight.HighlightField; import org.elasticsearch.search.fetch.subphase.highlight.HighlightField;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.ElasticsearchException; import org.springframework.data.elasticsearch.ElasticsearchException;
import org.springframework.data.elasticsearch.annotations.Document; import org.springframework.data.elasticsearch.annotations.Document;
@ -45,7 +45,7 @@ import org.springframework.data.mapping.context.MappingContext;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.nio.charset.Charset; import java.nio.charset.StandardCharsets;
import java.util.*; import java.util.*;
public class UKResultMapper extends AbstractResultMapper { public class UKResultMapper extends AbstractResultMapper {
@ -96,7 +96,7 @@ public class UKResultMapper extends AbstractResultMapper {
public <T> T mapEntity(String source , SearchHit hit , Class<T> clazz) { public <T> T mapEntity(String source , SearchHit hit , Class<T> clazz) {
T t = mapEntity(source , clazz) ; T t = mapEntity(source , clazz) ;
Map<String, HighlightField> highlightFields = hit.getHighlightFields(); Map<String, HighlightField> highlightFields = hit.getHighlightFields();
HighlightField highlightNameField = highlightFields.get("title"); HighlightField highlightNameField = highlightFields.get("title");
HighlightField contentHightlightField = highlightFields.get("content"); HighlightField contentHightlightField = highlightFields.get("content");
try { try {
@ -108,8 +108,8 @@ public class UKResultMapper extends AbstractResultMapper {
} }
PropertyUtils.setProperty(t, "id" , hit.getId()); PropertyUtils.setProperty(t, "id" , hit.getId());
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
e.printStackTrace(); e.printStackTrace();
} }
return t; return t;
} }
@ -154,18 +154,18 @@ public class UKResultMapper extends AbstractResultMapper {
for (SearchHitField value : values) { for (SearchHitField value : values) {
if (value.getValues().size() > 1) { if (value.getValues().size() > 1) {
generator.writeArrayFieldStart(value.getName()); generator.writeArrayFieldStart(value.getName());
for (Object val : value.getValues()) { for (Object val : value.getValues()) {
generator.writeObject(val); generator.writeObject(val);
} }
generator.writeEndArray(); generator.writeEndArray();
} else { } else {
generator.writeObjectField(value.getName(), value.getValue()); generator.writeObjectField(value.getName(), value.getValue());
} }
} }
generator.writeEndObject(); generator.writeEndObject();
generator.flush(); generator.flush();
return new String(stream.toByteArray(), Charset.forName("UTF-8")); return new String(stream.toByteArray(), StandardCharsets.UTF_8);
} catch (IOException e) { } catch (IOException e) {
return null; return null;
} }
} }
@ -199,7 +199,7 @@ public class UKResultMapper extends AbstractResultMapper {
ElasticsearchPersistentEntity<?> persistentEntity = mappingContext.getPersistentEntity(clazz); ElasticsearchPersistentEntity<?> persistentEntity = mappingContext.getPersistentEntity(clazz);
PersistentProperty<?> idProperty = persistentEntity.getIdProperty(); PersistentProperty<?> idProperty = persistentEntity.getIdProperty();
// Only deal with String because ES generated Ids are strings ! // Only deal with String because ES generated Ids are strings !
if (idProperty != null && idProperty.getType().isAssignableFrom(String.class)) { if (idProperty != null && idProperty.getType().isAssignableFrom(String.class)) {
persistentEntity.getPropertyAccessor(result).setProperty(idProperty, id); persistentEntity.getPropertyAccessor(result).setProperty(idProperty, id);
} }

View File

@ -27,7 +27,7 @@ import org.elasticsearch.action.get.MultiGetResponse;
import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHitField; import org.elasticsearch.search.SearchHitField;
import org.elasticsearch.search.highlight.HighlightField; import org.elasticsearch.search.fetch.subphase.highlight.HighlightField;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.ElasticsearchException; import org.springframework.data.elasticsearch.ElasticsearchException;
import org.springframework.data.elasticsearch.annotations.Document; import org.springframework.data.elasticsearch.annotations.Document;
@ -45,7 +45,7 @@ import org.springframework.data.mapping.context.MappingContext;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.nio.charset.Charset; import java.nio.charset.StandardCharsets;
import java.util.*; import java.util.*;
public class XiaoEUKResultMapper extends AbstractResultMapper { public class XiaoEUKResultMapper extends AbstractResultMapper {
@ -96,7 +96,7 @@ public class XiaoEUKResultMapper extends AbstractResultMapper {
public <T> T mapEntity(String source , SearchHit hit , Class<T> clazz) { public <T> T mapEntity(String source , SearchHit hit , Class<T> clazz) {
T t = mapEntity(source , clazz) ; T t = mapEntity(source , clazz) ;
Map<String, HighlightField> highlightFields = hit.getHighlightFields(); Map<String, HighlightField> highlightFields = hit.getHighlightFields();
HighlightField highlightNameField = highlightFields.get("title"); HighlightField highlightNameField = highlightFields.get("title");
HighlightField contentHightlightField = highlightFields.get("content"); HighlightField contentHightlightField = highlightFields.get("content");
try { try {
@ -108,8 +108,8 @@ public class XiaoEUKResultMapper extends AbstractResultMapper {
} }
PropertyUtils.setProperty(t, "id" , hit.getId()); PropertyUtils.setProperty(t, "id" , hit.getId());
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
e.printStackTrace(); e.printStackTrace();
} }
return t; return t;
} }
@ -154,18 +154,18 @@ public class XiaoEUKResultMapper extends AbstractResultMapper {
for (SearchHitField value : values) { for (SearchHitField value : values) {
if (value.getValues().size() > 1) { if (value.getValues().size() > 1) {
generator.writeArrayFieldStart(value.getName()); generator.writeArrayFieldStart(value.getName());
for (Object val : value.getValues()) { for (Object val : value.getValues()) {
generator.writeObject(val); generator.writeObject(val);
} }
generator.writeEndArray(); generator.writeEndArray();
} else { } else {
generator.writeObjectField(value.getName(), value.getValue()); generator.writeObjectField(value.getName(), value.getValue());
} }
} }
generator.writeEndObject(); generator.writeEndObject();
generator.flush(); generator.flush();
return new String(stream.toByteArray(), Charset.forName("UTF-8")); return new String(stream.toByteArray(), StandardCharsets.UTF_8);
} catch (IOException e) { } catch (IOException e) {
return null; return null;
} }
} }
@ -199,7 +199,7 @@ public class XiaoEUKResultMapper extends AbstractResultMapper {
ElasticsearchPersistentEntity<?> persistentEntity = mappingContext.getPersistentEntity(clazz); ElasticsearchPersistentEntity<?> persistentEntity = mappingContext.getPersistentEntity(clazz);
PersistentProperty<?> idProperty = persistentEntity.getIdProperty(); PersistentProperty<?> idProperty = persistentEntity.getIdProperty();
// Only deal with String because ES generated Ids are strings ! // Only deal with String because ES generated Ids are strings !
if (idProperty != null && idProperty.getType().isAssignableFrom(String.class)) { if (idProperty != null && idProperty.getType().isAssignableFrom(String.class)) {
persistentEntity.getPropertyAccessor(result).setProperty(idProperty, id); persistentEntity.getPropertyAccessor(result).setProperty(idProperty, id);
} }