Authored by Gino Zhang

支持suggest_conversion_custom全量索引处理

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