集成ik分析器

This commit is contained in:
zhh
2018-06-22 11:25:03 +08:00
parent 9523533c99
commit a76e46e57b
4 changed files with 27 additions and 5 deletions

View File

@@ -1,7 +1,11 @@
package com.macro.mall.search.domain;
import com.macro.mall.model.PmsProductAttributeValue;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldIndex;
import org.springframework.data.elasticsearch.annotations.FieldType;
import java.io.Serializable;
import java.math.BigDecimal;
@@ -11,18 +15,25 @@ import java.util.List;
* 搜索中的商品信息
* Created by macro on 2018/6/19.
*/
@Document(indexName = "pms", type = "product")
@Document(indexName = "pms", type = "product",shards = 1,replicas = 0)
public class EsProduct implements Serializable {
private static final long serialVersionUID = -1L;
@Id
private Long id;
@Field(index = FieldIndex.not_analyzed,type = FieldType.String)
private String productSn;
private Long brandId;
@Field(index = FieldIndex.not_analyzed,type = FieldType.String)
private String brandName;
private Long productCategoryId;
@Field(index = FieldIndex.not_analyzed,type = FieldType.String)
private String productCategoryName;
private String pic;
@Field(analyzer = "ik_max_word",type = FieldType.String)
private String name;
@Field(analyzer = "ik_max_word",type = FieldType.String)
private String subTitle;
@Field(analyzer = "ik_max_word",type = FieldType.String)
private String keywords;
private BigDecimal price;
private Integer sale;

View File

@@ -105,11 +105,11 @@ public class EsProductServiceImpl implements EsProductService {
}
//搜索
FunctionScoreQueryBuilder functionScoreQueryBuilder = QueryBuilders.functionScoreQuery()
.add(QueryBuilders.matchPhraseQuery("name", keyword),
.add(QueryBuilders.matchQuery("name", keyword),
ScoreFunctionBuilders.weightFactorFunction(1000))
.add(QueryBuilders.matchPhraseQuery("subTitle", keyword),
.add(QueryBuilders.matchQuery("subTitle", keyword),
ScoreFunctionBuilders.weightFactorFunction(500))
.add(QueryBuilders.matchPhraseQuery("keywords", keyword),
.add(QueryBuilders.matchQuery("keywords", keyword),
ScoreFunctionBuilders.weightFactorFunction(200))
.scoreMode("sum").setMinScore(10f);
if (StringUtils.isEmpty(keyword)) {

View File

@@ -23,7 +23,7 @@
p.recommand_status recommandStatus,
p.stock stock,
p.promotion_type promotionType,
P.keywords keywords
P.keywords keywords,
p.sort sort,
a.id attr_id,
a.value attr_value,