Authored by Gino Zhang

Conversion索引增加Brand关键词的转换关系

... ... @@ -14,12 +14,13 @@
<result column="hot_keyword" jdbcType="VARCHAR" property="hotKeyword" />
<result column="status" property="status" jdbcType="INTEGER" />
<result column="country_id" property="countryId" jdbcType="INTEGER" />
<result column="brand_style" jdbcType="VARCHAR" property="brandStyle" />
</resultMap>
<sql id="Base_Column_List">
id, brand_name, brand_domain, brand_alif, brand_ico,
is_hot,
brand_name_cn, brand_name_en,
brand_keyword, hot_keyword,status,country_id
brand_keyword, hot_keyword,status,country_id,brand_style
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap"
parameterType="java.lang.Integer" timeout="20000">
... ... @@ -39,7 +40,7 @@
brand_alif,
brand_ico, is_hot,
brand_name_cn, brand_name_en, brand_keyword,
hot_keyword,status,country_id)
hot_keyword,status,country_id,brand_style)
values (#{id,jdbcType=INTEGER},
#{brandName,jdbcType=VARCHAR},
#{brandDomain,jdbcType=VARCHAR},
... ... @@ -48,25 +49,32 @@
#{brandNameCn,jdbcType=VARCHAR},
#{brandNameEn,jdbcType=VARCHAR},
#{brandKeyword,jdbcType=VARCHAR},
#{hotKeyword,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER},#{countryId,jdbcType=INTEGER})
#{hotKeyword,jdbcType=VARCHAR},
#{status,jdbcType=INTEGER},
#{countryId,jdbcType=INTEGER},
#{brandStyle,jdbcType=VARCHAR})
</insert>
<insert id="insertbatch" parameterType="java.util.List" timeout="20000">
insert ignore into brand (id, brand_name, brand_domain,
brand_alif, brand_ico,
is_hot,
brand_name_cn, brand_name_en, brand_keyword,
hot_keyword,status,country_id) values
hot_keyword,status,country_id,brand_style) values
<foreach collection="list" item="item" index="index"
separator=",">
(#{item.id,jdbcType=INTEGER},
#{item.brandName,jdbcType=VARCHAR},
#{item.brandDomain,jdbcType=VARCHAR},
#{item.brandAlif,jdbcType=VARCHAR},
#{item.brandIco,jdbcType=VARCHAR}, #{item.isHot,jdbcType=CHAR},
#{item.brandIco,jdbcType=VARCHAR},
#{item.isHot,jdbcType=CHAR},
#{item.brandNameCn,jdbcType=VARCHAR},
#{item.brandNameEn,jdbcType=VARCHAR},
#{item.brandKeyword,jdbcType=VARCHAR},
#{item.hotKeyword,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER},#{item.countryId,jdbcType=INTEGER}
#{item.hotKeyword,jdbcType=VARCHAR},
#{item.status,jdbcType=INTEGER},
#{item.countryId,jdbcType=INTEGER},
#{item.brandStyle,jdbcType=VARCHAR}
)
</foreach>
</insert>
... ... @@ -110,6 +118,9 @@
<if test="countryId != null">
country_id,
</if>
<if test="brandStyle != null">
brand_style,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
... ... @@ -148,6 +159,9 @@
<if test="countryId != null">
#{countryId,jdbcType=INTEGER},
</if>
<if test="brandStyle != null">
#{brandStyle,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yoho.search.dal.model.Brand"
... ... @@ -187,6 +201,9 @@
<if test="countryId != null">
country_id = #{countryId,jdbcType=INTEGER},
</if>
<if test="brandStyle != null">
brand_style = #{brandStyle,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
... ... @@ -209,7 +226,8 @@
hot_keyword =
#{hotKeyword,jdbcType=VARCHAR},
status = #{status,jdbcType=INTEGER},
country_id = #{countryId,jdbcType=INTEGER}
country_id = #{countryId,jdbcType=INTEGER},
brand_style = #{brandStyle,jdbcType=VARCHAR}
where id = #{id,jdbcType=INTEGER}
</update>
<select id="count" resultType="java.lang.Integer" timeout="20000" >
... ...
package com.yoho.search.consumer.index.fullbuild;
import com.yoho.search.base.utils.DateUtil;
import com.yoho.search.base.utils.MD5Util;
import com.yoho.search.consumer.index.common.IIndexBuilder;
import com.yoho.search.consumer.service.base.BrandService;
import com.yoho.search.consumer.service.bo.ConversionBO;
import com.yoho.search.dal.model.Brand;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
/**
* 从品牌风格和关键词里获取关键词提取。
*/
@Component
public class SuggestConversionFromBrandIndexBuilder extends IIndexBuilder {
private static final int VALID_STATUS = 1;
@Autowired
private BrandService brandService;
@Override
public int getTotalCount() throws Exception {
return brandService.count();
}
@Override
public List<?> getPageLists(int offset, int limit) throws Exception {
// 获取分页列表
List<Brand> list = brandService.getBrandPageLists(offset, limit);
// 构建结果
List<ConversionBO> results = new ArrayList<>();
for (Brand item : list) {
ConversionBO conversionBO = toConversionBO(item);
if (conversionBO != null) {
results.add(conversionBO);
}
}
return results;
}
private ConversionBO toConversionBO(Brand brand) {
if (StringUtils.isEmpty(brand.getBrandKeyword()) && StringUtils.isEmpty(brand.getBrandStyle())) {
return null;
}
// 根据品牌风格和品牌关键词构建dest
StringBuffer dest = new StringBuffer();
if (StringUtils.isNotEmpty(brand.getBrandStyle())) {
dest.append(brand.getBrandStyle());
}
if (StringUtils.isNotEmpty(brand.getBrandKeyword())) {
if (dest.length() == 0) {
dest.append(brand.getBrandKeyword());
} else {
dest.append(",").append(brand.getBrandKeyword());
}
}
return new ConversionBO(brand.getBrandName(), dest.toString(), DateUtil.getCurrentTimeSecond(), VALID_STATUS);
}
@Override
public String getId(Object object) {
return MD5Util.string2MD5(((ConversionBO) object).getSource().trim().toLowerCase());
}
}
... ...
... ... @@ -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,com.yoho.search.consumer.index.fullbuild.SuggestConversionCustomIndexBuilder</builderClass>
<builderClass>com.yoho.search.consumer.index.fullbuild.SuggestConversionIndexBuilder,com.yoho.search.consumer.index.fullbuild.SuggestConversionFromBrandIndexBuilder,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,com.yoho.search.consumer.index.fullbuild.SuggestConversionCustomIndexBuilder</builderClass>
<builderClass>com.yoho.search.consumer.index.fullbuild.SuggestConversionIndexBuilder,com.yoho.search.consumer.index.fullbuild.SuggestConversionFromBrandIndexBuilder,com.yoho.search.consumer.index.fullbuild.SuggestConversionCustomIndexBuilder</builderClass>
<mappingFile>esmapping/conversion.json</mappingFile>
</index>
... ...