Authored by Gino Zhang

支持suggest_conversion_custom全量索引处理

1 package com.yoho.search.dal; 1 package com.yoho.search.dal;
2 2
3 import com.yoho.search.dal.model.SuggestConversionCustom; 3 import com.yoho.search.dal.model.SuggestConversionCustom;
  4 +import org.apache.ibatis.annotations.Param;
  5 +
  6 +import java.util.List;
4 7
5 public interface SuggestConversionCustomMapper { 8 public interface SuggestConversionCustomMapper {
6 9
  10 + int selectTotalCount();
  11 +
  12 + List<SuggestConversionCustom> selectPageList(@Param(value = "offset") Integer offset, @Param(value = "pageSize") Integer pageSize);
  13 +
7 int deleteByPrimaryKey(Integer id); 14 int deleteByPrimaryKey(Integer id);
8 15
9 int insert(SuggestConversionCustom record); 16 int insert(SuggestConversionCustom record);
@@ -11,6 +11,17 @@ @@ -11,6 +11,17 @@
11 <sql id="Base_Column_List" > 11 <sql id="Base_Column_List" >
12 id, source, dest, update_time, status 12 id, source, dest, update_time, status
13 </sql> 13 </sql>
  14 +
  15 + <select id="selectTotalCount" resultType="java.lang.Integer" timeout="20000">
  16 + SELECT count(1) FROM suggest_conversion_custom
  17 + </select>
  18 +
  19 + <select id="selectPageList" resultMap="BaseResultMap" timeout="20000">
  20 + select
  21 + <include refid="Base_Column_List" />
  22 + from suggest_conversion_custom limit #{offset},#{pageSize}
  23 + </select>
  24 +
14 <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" > 25 <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
15 select 26 select
16 <include refid="Base_Column_List" /> 27 <include refid="Base_Column_List" />
  1 +package com.yoho.search.consumer.index.fullbuild;
  2 +
  3 +import com.yoho.search.base.utils.MD5Util;
  4 +import com.yoho.search.consumer.index.common.IIndexBuilder;
  5 +import com.yoho.search.consumer.service.base.SuggestConversionCustomService;
  6 +import com.yoho.search.consumer.service.bo.ConversionBO;
  7 +import com.yoho.search.dal.model.SuggestConversionCustom;
  8 +import org.springframework.beans.factory.annotation.Autowired;
  9 +import org.springframework.stereotype.Component;
  10 +
  11 +import java.util.ArrayList;
  12 +import java.util.List;
  13 +
  14 +@Component
  15 +public class SuggestConversionCustomIndexBuilder extends IIndexBuilder {
  16 +
  17 + @Autowired
  18 + private SuggestConversionCustomService suggestConversionCustomService;
  19 +
  20 + @Override
  21 + public int getTotalCount() throws Exception {
  22 + return suggestConversionCustomService.selectTotalCount();
  23 + }
  24 +
  25 + @Override
  26 + public List<?> getPageLists(int offset, int limit) throws Exception {
  27 + // 获取分页列表
  28 + List<SuggestConversionCustom> list = suggestConversionCustomService.selectPageList(offset, limit);
  29 + // 构建结果
  30 + List<ConversionBO> results = new ArrayList<>();
  31 + for (SuggestConversionCustom item : list) {
  32 + results.add(new ConversionBO(item.getSource(), item.getDest(), item.getUpdateTime(), item.getStatus()));
  33 + }
  34 +
  35 + return results;
  36 + }
  37 +
  38 + @Override
  39 + public String getId(Object object) {
  40 + return MD5Util.string2MD5(((ConversionBO) object).getSource().trim().toLowerCase());
  41 + }
  42 +
  43 +}
1 package com.yoho.search.consumer.index.fullbuild; 1 package com.yoho.search.consumer.index.fullbuild;
2 2
  3 +import com.yoho.search.base.utils.MD5Util;
3 import com.yoho.search.consumer.index.common.IIndexBuilder; 4 import com.yoho.search.consumer.index.common.IIndexBuilder;
4 import com.yoho.search.consumer.service.base.SuggestConversionService; 5 import com.yoho.search.consumer.service.base.SuggestConversionService;
5 import com.yoho.search.consumer.service.bo.ConversionBO; 6 import com.yoho.search.consumer.service.bo.ConversionBO;
@@ -13,6 +14,8 @@ import java.util.List; @@ -13,6 +14,8 @@ import java.util.List;
13 @Component 14 @Component
14 public class SuggestConversionIndexBuilder extends IIndexBuilder { 15 public class SuggestConversionIndexBuilder extends IIndexBuilder {
15 16
  17 + private static final int VALID_STATUS = 1;
  18 +
16 @Autowired 19 @Autowired
17 private SuggestConversionService suggestConversionService; 20 private SuggestConversionService suggestConversionService;
18 21
@@ -28,7 +31,7 @@ public class SuggestConversionIndexBuilder extends IIndexBuilder { @@ -28,7 +31,7 @@ public class SuggestConversionIndexBuilder extends IIndexBuilder {
28 // 构建结果 31 // 构建结果
29 List<ConversionBO> results = new ArrayList<>(); 32 List<ConversionBO> results = new ArrayList<>();
30 for (SuggestConversion item : list) { 33 for (SuggestConversion item : list) {
31 - results.add(new ConversionBO(item.getId(), item.getSource(), item.getDest())); 34 + results.add(new ConversionBO(item.getSource(), item.getDest(), item.getUpdateTime(), VALID_STATUS));
32 } 35 }
33 36
34 return results; 37 return results;
@@ -36,7 +39,7 @@ public class SuggestConversionIndexBuilder extends IIndexBuilder { @@ -36,7 +39,7 @@ public class SuggestConversionIndexBuilder extends IIndexBuilder {
36 39
37 @Override 40 @Override
38 public String getId(Object object) { 41 public String getId(Object object) {
39 - return ((ConversionBO) object).getId().toString(); 42 + return MD5Util.string2MD5(((ConversionBO) object).getSource().trim().toLowerCase());
40 } 43 }
41 44
42 } 45 }
@@ -16,6 +16,20 @@ @@ -16,6 +16,20 @@
16 "type": "string", 16 "type": "string",
17 "analyzer": "ik_complex", 17 "analyzer": "ik_complex",
18 "search_analyzer": "ik_complex" 18 "search_analyzer": "ik_complex"
  19 + },
  20 + "updateTime": {
  21 + "type": "integer",
  22 + "doc_values": true,
  23 + "fielddata": {
  24 + "format": "doc_values"
  25 + }
  26 + },
  27 + "status": {
  28 + "type": "integer",
  29 + "doc_values": true,
  30 + "fielddata": {
  31 + "format": "doc_values"
  32 + }
19 } 33 }
20 } 34 }
21 } 35 }
  1 +package com.yoho.search.consumer.service.base;
  2 +
  3 +import com.yoho.search.dal.SuggestConversionCustomMapper;
  4 +import com.yoho.search.dal.model.SuggestConversion;
  5 +import com.yoho.search.dal.model.SuggestConversionCustom;
  6 +import org.springframework.beans.factory.annotation.Autowired;
  7 +import org.springframework.stereotype.Component;
  8 +
  9 +import java.util.HashSet;
  10 +import java.util.List;
  11 +import java.util.Set;
  12 +import java.util.stream.Collectors;
  13 +
  14 +/**
  15 + * Created by ginozhang on 2016/12/6.
  16 + */
  17 +@Component
  18 +public class SuggestConversionCustomService {
  19 +
  20 + @Autowired
  21 + private SuggestConversionCustomMapper suggestConversionCustomMapper;
  22 +
  23 + public int selectTotalCount() {
  24 + return suggestConversionCustomMapper.selectTotalCount();
  25 + }
  26 +
  27 + public List<SuggestConversionCustom> selectPageList(Integer offset, Integer pageSize) {
  28 + return suggestConversionCustomMapper.selectPageList(offset, pageSize);
  29 + }
  30 +
  31 +
  32 +}
@@ -6,26 +6,22 @@ public class ConversionBO implements Serializable { @@ -6,26 +6,22 @@ public class ConversionBO implements Serializable {
6 6
7 private static final long serialVersionUID = 7154651415633074270L; 7 private static final long serialVersionUID = 7154651415633074270L;
8 8
9 - private Integer id;  
10 -  
11 private String source; 9 private String source;
12 10
13 private String dest; 11 private String dest;
14 12
15 - public ConversionBO(){} 13 + private Integer updateTime;
16 14
17 - public ConversionBO(Integer id, String source, String dest){  
18 - this.id = id;  
19 - this.source = source;  
20 - this.dest = dest;  
21 - } 15 + private Integer status;
22 16
23 - public Integer getId() {  
24 - return id; 17 + public ConversionBO() {
25 } 18 }
26 19
27 - public void setId(Integer id) {  
28 - this.id = id; 20 + public ConversionBO(String source, String dest, Integer updateTime, Integer status) {
  21 + this.source = source;
  22 + this.dest = dest;
  23 + this.updateTime = updateTime;
  24 + this.status = status;
29 } 25 }
30 26
31 public String getSource() { 27 public String getSource() {
@@ -43,4 +39,20 @@ public class ConversionBO implements Serializable { @@ -43,4 +39,20 @@ public class ConversionBO implements Serializable {
43 public void setDest(String dest) { 39 public void setDest(String dest) {
44 this.dest = dest; 40 this.dest = dest;
45 } 41 }
  42 +
  43 + public Integer getUpdateTime() {
  44 + return updateTime;
  45 + }
  46 +
  47 + public void setUpdateTime(Integer updateTime) {
  48 + this.updateTime = updateTime;
  49 + }
  50 +
  51 + public Integer getStatus() {
  52 + return status;
  53 + }
  54 +
  55 + public void setStatus(Integer status) {
  56 + this.status = status;
  57 + }
46 } 58 }
@@ -99,7 +99,7 @@ @@ -99,7 +99,7 @@
99 <property key="refresh_interval" value="1s"/> 99 <property key="refresh_interval" value="1s"/>
100 <property key="translog.flush_threshold_ops" value="5000"/> 100 <property key="translog.flush_threshold_ops" value="5000"/>
101 </properties> 101 </properties>
102 - <builderClass>com.yoho.search.consumer.index.fullbuild.SuggestConversionIndexBuilder</builderClass> 102 + <builderClass>com.yoho.search.consumer.index.fullbuild.SuggestConversionIndexBuilder,com.yoho.search.consumer.index.fullbuild.SuggestConversionCustomIndexBuilder</builderClass>
103 <mappingFile>esmapping/conversion.json</mappingFile> 103 <mappingFile>esmapping/conversion.json</mappingFile>
104 </index> 104 </index>
105 105
@@ -99,7 +99,7 @@ @@ -99,7 +99,7 @@
99 <property key="refresh_interval" value="${search.index.refresh_interval}"/> 99 <property key="refresh_interval" value="${search.index.refresh_interval}"/>
100 <property key="translog.flush_threshold_ops" value="${search.index.translog.flush_threshold_ops}"/> 100 <property key="translog.flush_threshold_ops" value="${search.index.translog.flush_threshold_ops}"/>
101 </properties> 101 </properties>
102 - <builderClass>com.yoho.search.consumer.index.fullbuild.SuggestConversionIndexBuilder</builderClass> 102 + <builderClass>com.yoho.search.consumer.index.fullbuild.SuggestConversionIndexBuilder,com.yoho.search.consumer.index.fullbuild.SuggestConversionCustomIndexBuilder</builderClass>
103 <mappingFile>esmapping/conversion.json</mappingFile> 103 <mappingFile>esmapping/conversion.json</mappingFile>
104 </index> 104 </index>
105 105