1.迁移product search 代码
2.先注释掉提示错误的代码,后续相关人员开发功能时自行解开 3.修改es连接方式为 rest,增加spring data jest
This commit is contained in:
110
search/search-biz/pom.xml
Normal file
110
search/search-biz/pom.xml
Normal file
@@ -0,0 +1,110 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>search</artifactId>
|
||||
<groupId>cn.iocoder.mall</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>search-biz</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<!-- Mall 相关 -->
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.mall</groupId>
|
||||
<artifactId>mall-spring-boot</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<artifactId>search-biz-api</artifactId>
|
||||
<groupId>cn.iocoder.mall</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.mall</groupId>
|
||||
<artifactId>product-rpc-api</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<!-- DB 相关 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- RPC 相关 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-dubbo</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Registry 和 Config 相关 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- MQ 相关 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-stream-rocketmq</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 工具类相关 -->
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mapstruct</groupId>
|
||||
<artifactId>mapstruct</artifactId> <!-- use mapstruct-jdk8 for Java 8 or higher -->
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mapstruct</groupId>
|
||||
<artifactId>mapstruct-jdk8</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- test -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId> <!-- 引入该包,为了写单元测试用 -->
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 自动化配置 Spring Data Jest -->
|
||||
<dependency>
|
||||
<groupId>com.github.vanroy</groupId>
|
||||
<artifactId>spring-boot-starter-data-jest</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<!-- 提供给 mapstruct 使用 -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,86 @@
|
||||
package cn.iocoder.mall.search.biz.bo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品 ES BO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductBO implements Serializable {
|
||||
|
||||
private Integer id;
|
||||
|
||||
// ========== 基本信息 =========
|
||||
/**
|
||||
* SPU 名字
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 卖点
|
||||
*/
|
||||
private String sellPoint;
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 分类编号
|
||||
*/
|
||||
private Integer cid;
|
||||
/**
|
||||
* 分类名
|
||||
*/
|
||||
private String categoryName;
|
||||
/**
|
||||
* 商品主图地数组
|
||||
*/
|
||||
private List<String> picUrls;
|
||||
|
||||
// ========== 其他信息 =========
|
||||
/**
|
||||
* 是否上架商品(是否可见)。
|
||||
*
|
||||
* true 为已上架
|
||||
* false 为已下架
|
||||
*/
|
||||
private Boolean visible;
|
||||
/**
|
||||
* 排序字段
|
||||
*/
|
||||
private Integer sort;
|
||||
|
||||
// ========== Sku 相关字段 =========
|
||||
/**
|
||||
* 原价格,单位:分
|
||||
*/
|
||||
private Integer originalPrice;
|
||||
/**
|
||||
* 购买价格,单位:分。
|
||||
*/
|
||||
private Integer buyPrice;
|
||||
/**
|
||||
* 库存数量
|
||||
*/
|
||||
private Integer quantity;
|
||||
|
||||
// ========== 促销活动相关字段 =========
|
||||
// 目前只促销单体商品促销,目前仅限制折扣。
|
||||
/**
|
||||
* 促销活动编号
|
||||
*/
|
||||
private Integer promotionActivityId;
|
||||
/**
|
||||
* 促销活动标题
|
||||
*/
|
||||
private String promotionActivityTitle;
|
||||
/**
|
||||
* 促销活动类型
|
||||
*/
|
||||
private Integer promotionActivityType;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package cn.iocoder.mall.search.biz.bo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品搜索条件返回 BO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductConditionBO {
|
||||
|
||||
/**
|
||||
* 商品分类数组
|
||||
*/
|
||||
private List<Category> categories;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public static class Category {
|
||||
|
||||
/**
|
||||
* 分类编号
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 分类名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package cn.iocoder.mall.search.biz.bo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductPageBO implements Serializable {
|
||||
|
||||
/**
|
||||
* 管理员数组
|
||||
*/
|
||||
private List<ProductBO> list;
|
||||
/**
|
||||
* 总量
|
||||
*/
|
||||
private Integer total;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package cn.iocoder.mall.search.biz.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
||||
|
||||
@Configuration
|
||||
@EnableElasticsearchRepositories(basePackages = "cn.iocoder.mall.search.biz.dao")
|
||||
public class JPAConfiguration {
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package cn.iocoder.mall.search.biz.constant;
|
||||
|
||||
/**
|
||||
* ES 字段分析器的枚举类
|
||||
*
|
||||
* 关于 IK 分词,文章 https://blog.csdn.net/xsdxs/article/details/72853288 不错。
|
||||
* 目前项目使用的 ES 版本是 6.7.1 ,可以在 https://www.elastic.co/cn/downloads/past-releases/elasticsearch-6-7-1 下载。
|
||||
* 如果不知道怎么安装 ES ,可以看 https://blog.csdn.net/chengyuqiang/article/details/78837712 简单。
|
||||
*/
|
||||
public class FieldAnalyzer {
|
||||
|
||||
/**
|
||||
* IK 最大化分词
|
||||
*
|
||||
* 会将文本做最细粒度的拆分
|
||||
*/
|
||||
public static final String IK_MAX_WORD = "ik_max_word";
|
||||
|
||||
/**
|
||||
* IK 智能分词
|
||||
*
|
||||
* 会做最粗粒度的拆分
|
||||
*/
|
||||
public static final String IK_SMART = "ik_smart";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package cn.iocoder.mall.search.biz.convert;
|
||||
|
||||
import cn.iocoder.mall.search.biz.bo.ProductBO;
|
||||
import cn.iocoder.mall.search.biz.dataobject.ESProductDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ProductSearchConvert {
|
||||
|
||||
ProductSearchConvert INSTANCE = Mappers.getMapper(ProductSearchConvert.class);
|
||||
|
||||
List<ProductBO> convert(List<ESProductDO> list);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package cn.iocoder.mall.search.biz.dao;
|
||||
|
||||
import cn.iocoder.common.framework.util.CollectionUtil;
|
||||
import cn.iocoder.common.framework.util.StringUtil;
|
||||
import cn.iocoder.common.framework.vo.SortingField;
|
||||
import cn.iocoder.mall.search.biz.dataobject.ESProductDO;
|
||||
import org.elasticsearch.common.lucene.search.function.FunctionScoreQuery;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder;
|
||||
import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders;
|
||||
import org.elasticsearch.search.sort.SortBuilders;
|
||||
import org.elasticsearch.search.sort.SortOrder;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.elasticsearch.index.query.QueryBuilders.matchQuery;
|
||||
|
||||
@Repository
|
||||
public interface ProductRepository extends ElasticsearchRepository<ESProductDO, Integer> {
|
||||
|
||||
@Deprecated
|
||||
ESProductDO findByName(String name);
|
||||
|
||||
default Page<ESProductDO> search(Integer cid, String keyword, Integer pageNo, Integer pageSize,
|
||||
List<SortingField> sortFields) {
|
||||
NativeSearchQueryBuilder nativeSearchQueryBuilder = new NativeSearchQueryBuilder()
|
||||
.withPageable(PageRequest.of(pageNo - 1, pageSize));
|
||||
// 筛选条件 cid
|
||||
if (cid != null) {
|
||||
nativeSearchQueryBuilder.withFilter(QueryBuilders.termQuery("cid", cid));
|
||||
}
|
||||
// 筛选
|
||||
if (StringUtil.hasText(keyword)) {
|
||||
FunctionScoreQueryBuilder.FilterFunctionBuilder[] functions = { // TODO 芋艿,分值随便打的
|
||||
new FunctionScoreQueryBuilder.FilterFunctionBuilder(matchQuery("name", keyword),
|
||||
ScoreFunctionBuilders.weightFactorFunction(10)),
|
||||
new FunctionScoreQueryBuilder.FilterFunctionBuilder(matchQuery("sellPoint", keyword),
|
||||
ScoreFunctionBuilders.weightFactorFunction(2)),
|
||||
new FunctionScoreQueryBuilder.FilterFunctionBuilder(matchQuery("categoryName", keyword),
|
||||
ScoreFunctionBuilders.weightFactorFunction(3)),
|
||||
// new FunctionScoreQueryBuilder.FilterFunctionBuilder(matchQuery("description", keyword),
|
||||
// ScoreFunctionBuilders.weightFactorFunction(2)), // TODO 芋艿,目前这么做,如果商品描述很长,在按照价格降序,会命中超级多的关键字。
|
||||
};
|
||||
FunctionScoreQueryBuilder functionScoreQueryBuilder = QueryBuilders.functionScoreQuery(functions)
|
||||
.scoreMode(FunctionScoreQuery.ScoreMode.SUM)
|
||||
.setMinScore(2F); // TODO 芋艿,需要考虑下 score
|
||||
nativeSearchQueryBuilder.withQuery(functionScoreQueryBuilder);
|
||||
} else {
|
||||
nativeSearchQueryBuilder.withQuery(QueryBuilders.matchAllQuery());
|
||||
}
|
||||
// 排序
|
||||
if (!CollectionUtil.isEmpty(sortFields)) {
|
||||
sortFields.forEach(sortField -> nativeSearchQueryBuilder.withSort(SortBuilders.fieldSort(sortField.getField())
|
||||
.order(SortOrder.fromString(sortField.getOrder()))));
|
||||
} else if (StringUtil.hasText(keyword)) {
|
||||
nativeSearchQueryBuilder.withSort(SortBuilders.scoreSort().order(SortOrder.DESC));
|
||||
} else {
|
||||
nativeSearchQueryBuilder.withSort(SortBuilders.fieldSort("sort").order(SortOrder.DESC));
|
||||
}
|
||||
// 执行查询
|
||||
return search(nativeSearchQueryBuilder.build());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package cn.iocoder.mall.search.biz.dataobject;
|
||||
|
||||
import cn.iocoder.mall.search.biz.constant.FieldAnalyzer;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
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.FieldType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品 ES DO
|
||||
*/
|
||||
@Document(indexName = "product", type = "spu", shards = 1, replicas = 0)
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ESProductDO {
|
||||
|
||||
@Id
|
||||
private Integer id;
|
||||
|
||||
// ========== 基本信息 =========
|
||||
/**
|
||||
* SPU 名字
|
||||
*/
|
||||
@Field(analyzer = FieldAnalyzer.IK_MAX_WORD, type = FieldType.Text)
|
||||
private String name;
|
||||
/**
|
||||
* 卖点
|
||||
*/
|
||||
@Field(analyzer = FieldAnalyzer.IK_MAX_WORD, type = FieldType.Text)
|
||||
private String sellPoint;
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
@Field(analyzer = FieldAnalyzer.IK_MAX_WORD, type = FieldType.Text)
|
||||
private String description;
|
||||
/**
|
||||
* 分类编号
|
||||
*/
|
||||
private Integer cid;
|
||||
/**
|
||||
* 分类名
|
||||
*/
|
||||
@Field(analyzer = FieldAnalyzer.IK_MAX_WORD, type = FieldType.Text)
|
||||
private String categoryName;
|
||||
/**
|
||||
* 商品主图地数组
|
||||
*/
|
||||
private List<String> picUrls;
|
||||
|
||||
// ========== 其他信息 =========
|
||||
/**
|
||||
* 是否上架商品(是否可见)。
|
||||
*
|
||||
* true 为已上架
|
||||
* false 为已下架
|
||||
*/
|
||||
private Boolean visible;
|
||||
/**
|
||||
* 排序字段
|
||||
*/
|
||||
private Integer sort;
|
||||
|
||||
// ========== Sku 相关字段 =========
|
||||
/**
|
||||
* 原价格,单位:分
|
||||
*/
|
||||
private Integer originalPrice;
|
||||
/**
|
||||
* 购买价格,单位:分。
|
||||
*/
|
||||
private Integer buyPrice;
|
||||
/**
|
||||
* 库存数量
|
||||
*/
|
||||
private Integer quantity;
|
||||
|
||||
// ========== 促销活动相关字段 =========
|
||||
// 目前只促销单体商品促销,目前仅限制折扣。
|
||||
/**
|
||||
* 促销活动编号
|
||||
*/
|
||||
private Integer promotionActivityId;
|
||||
/**
|
||||
* 促销活动标题
|
||||
*/
|
||||
private String promotionActivityTitle;
|
||||
/**
|
||||
* 促销活动类型
|
||||
*/
|
||||
private Integer promotionActivityType;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package cn.iocoder.mall.search.biz.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* 获得商品检索条件 DTO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductConditionDTO {
|
||||
|
||||
/**
|
||||
* Field - 商品分类
|
||||
*/
|
||||
public static final String FIELD_CATEGORY = "category";
|
||||
|
||||
/**
|
||||
* 关键字
|
||||
*/
|
||||
private String keyword;
|
||||
/**
|
||||
* 需要返回的搜索条件的 fields 名
|
||||
*/
|
||||
private Collection<String> fields;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package cn.iocoder.mall.search.biz.dto;
|
||||
|
||||
import cn.iocoder.common.framework.util.CollectionUtil;
|
||||
import cn.iocoder.common.framework.vo.SortingField;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 商品检索分页 DTO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductSearchPageDTO {
|
||||
|
||||
public static final Set<String> SORT_FIELDS = CollectionUtil.asSet("buyPrice");
|
||||
|
||||
/**
|
||||
* 分类编号
|
||||
*/
|
||||
private Integer cid;
|
||||
/**
|
||||
* 关键字
|
||||
*/
|
||||
private String keyword;
|
||||
|
||||
/**
|
||||
* 页码
|
||||
*/
|
||||
private Integer pageNo;
|
||||
/**
|
||||
* 分页大小
|
||||
*/
|
||||
private Integer pageSize;
|
||||
|
||||
/**
|
||||
* 排序字段数组
|
||||
*/
|
||||
private List<SortingField> sorts;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package cn.iocoder.mall.search.biz.service;
|
||||
|
||||
|
||||
public interface ProductSearchService {
|
||||
|
||||
Integer rebuild();
|
||||
|
||||
/**
|
||||
* 构建商品的搜索索引
|
||||
*
|
||||
* @param id 商品编号
|
||||
* @return 构建结果
|
||||
*/
|
||||
Boolean save(Integer id);
|
||||
//
|
||||
// ProductPageBO getSearchPage(ProductSearchPageDTO searchPageDTO);
|
||||
//
|
||||
// ProductConditionBO getSearchCondition(ProductConditionDTO conditionDTO);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
package cn.iocoder.mall.search.biz.service;
|
||||
|
||||
import cn.iocoder.common.framework.util.CollectionUtil;
|
||||
import cn.iocoder.common.framework.vo.SortingField;
|
||||
import cn.iocoder.mall.search.biz.dao.ProductRepository;
|
||||
import cn.iocoder.mall.search.biz.dto.ProductSearchPageDTO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@org.apache.dubbo.config.annotation.Service(validation = "true", version = "${dubbo.provider.ProductSearchService.version}")
|
||||
public class ProductSearchServiceImpl implements ProductSearchService {
|
||||
|
||||
private static final Integer REBUILD_FETCH_PER_SIZE = 100;
|
||||
|
||||
@Autowired
|
||||
private ProductRepository productRepository;
|
||||
@Autowired
|
||||
private ElasticsearchTemplate elasticsearchTemplate; // 因为需要使用到聚合操作,只好引入 ElasticsearchTemplate 。
|
||||
|
||||
// @Reference(validation = "true", version = "${dubbo.consumer.ProductSpuService.version}")
|
||||
// private ProductSpuService productSpuService;
|
||||
// @Reference(validation = "true", version = "${dubbo.consumer.ProductCategoryService.version}")
|
||||
// private ProductCategoryService productCategoryService;
|
||||
// @Reference(validation = "true", version = "${dubbo.consumer.CartService.version}")
|
||||
// private CartService cartService;
|
||||
|
||||
// @Override
|
||||
// public Integer rebuild() {
|
||||
// // TODO 芋艿,因为目前商品比较少,所以写的很粗暴。等未来重构
|
||||
// Integer lastId = null;
|
||||
// int rebuildCounts = 0;
|
||||
// while (true) {
|
||||
// List<ProductSpuDetailBO> spus = productSpuService.getProductSpuDetailListForSync(lastId, REBUILD_FETCH_PER_SIZE);
|
||||
// rebuildCounts += spus.size();
|
||||
// // 存储到 ES 中
|
||||
// List<ESProductDO> products = spus.stream().map(this::convert).collect(Collectors.toList());
|
||||
// productRepository.saveAll(products);
|
||||
// // 设置新的 lastId ,或者结束
|
||||
// if (spus.size() < REBUILD_FETCH_PER_SIZE) {
|
||||
// break;
|
||||
// } else {
|
||||
// lastId = spus.get(spus.size() - 1).getId();
|
||||
// }
|
||||
// }
|
||||
// // 返回成功
|
||||
// return rebuildCounts;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Boolean save(Integer id) {
|
||||
// // 获得商品性情
|
||||
// ProductSpuDetailBO result = productSpuService.getProductSpuDetail(id);
|
||||
// // 存储到 ES 中
|
||||
// ESProductDO product = convert(result);
|
||||
// productRepository.save(product);
|
||||
// // 返回成功
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// @SuppressWarnings("OptionalGetWithoutIsPresent")
|
||||
// private ESProductDO convert(ProductSpuDetailBO spu) {
|
||||
// // 获得最小价格的 SKU ,用于下面的价格计算
|
||||
// ProductSpuDetailBO.Sku sku = spu.getSkus().stream().min(Comparator.comparing(ProductSpuDetailBO.Sku::getPrice)).get();
|
||||
// // 价格计算
|
||||
// CalcSkuPriceBO calSkuPriceResult = cartService.calcSkuPrice(sku.getId());
|
||||
// // 拼装结果
|
||||
// return ProductSearchConvert.INSTANCE.convert(spu, calSkuPriceResult);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public ProductPageBO getSearchPage(ProductSearchPageDTO searchPageDTO) {
|
||||
// checkSortFieldInvalid(searchPageDTO.getSorts());
|
||||
// // 执行查询
|
||||
// Page<ESProductDO> searchPage = productRepository.search(searchPageDTO.getCid(), searchPageDTO.getKeyword(),
|
||||
// searchPageDTO.getPageNo(), searchPageDTO.getPageSize(), searchPageDTO.getSorts());
|
||||
// // 转换结果
|
||||
// return new ProductPageBO()
|
||||
// .setList(ProductSearchConvert.INSTANCE.convert(searchPage.getContent()))
|
||||
// .setTotal((int) searchPage.getTotalElements());
|
||||
// }
|
||||
|
||||
private void checkSortFieldInvalid(List<SortingField> sorts) {
|
||||
if (CollectionUtil.isEmpty(sorts)) {
|
||||
return;
|
||||
}
|
||||
sorts.forEach(sortingField -> Assert.isTrue(ProductSearchPageDTO.SORT_FIELDS.contains(sortingField.getField()),
|
||||
String.format("排序字段(%s) 不在允许范围内", sortingField.getField())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer rebuild() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean save(Integer id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public ProductConditionBO getSearchCondition(ProductConditionDTO conditionDTO) {
|
||||
// // 创建 ES 搜索条件
|
||||
// NativeSearchQueryBuilder nativeSearchQueryBuilder = new NativeSearchQueryBuilder();
|
||||
// // 筛选
|
||||
// if (StringUtil.hasText(conditionDTO.getKeyword())) { // 如果有 keyword ,就去匹配
|
||||
// nativeSearchQueryBuilder.withQuery(QueryBuilders.multiMatchQuery(conditionDTO.getKeyword(),
|
||||
// "name", "sellPoint", "categoryName"));
|
||||
// } else {
|
||||
// nativeSearchQueryBuilder.withQuery(QueryBuilders.matchAllQuery());
|
||||
// }
|
||||
// // 聚合
|
||||
// if (conditionDTO.getFields().contains(ProductConditionDTO.FIELD_CATEGORY)) { // 商品分类
|
||||
// nativeSearchQueryBuilder.addAggregation(AggregationBuilders.terms("cids").field("cid"));
|
||||
// }
|
||||
// // 执行查询
|
||||
// ProductConditionBO condition = elasticsearchTemplate.query(nativeSearchQueryBuilder.build(), response -> {
|
||||
// ProductConditionBO result = new ProductConditionBO();
|
||||
// // categoryIds 聚合
|
||||
// Aggregation categoryIdsAggregation = response.getAggregations().get("cids");
|
||||
// if (categoryIdsAggregation != null) {
|
||||
// result.setCategories(new ArrayList<>());
|
||||
// for (LongTerms.Bucket bucket : (((LongTerms) categoryIdsAggregation).getBuckets())) {
|
||||
// result.getCategories().add(new ProductConditionBO.Category().setId(bucket.getKeyAsNumber().intValue()));
|
||||
// }
|
||||
// }
|
||||
// // 返回结果
|
||||
// return result;
|
||||
// });
|
||||
// // 聚合其它数据源
|
||||
// if (!CollectionUtil.isEmpty(condition.getCategories())) {
|
||||
// // 查询指定的 ProductCategoryBO 数组,并转换成 ProductCategoryBO Map
|
||||
// Map<Integer, ProductCategoryBO> categoryMap = productCategoryService.getListByIds(
|
||||
// condition.getCategories().stream().map(ProductConditionBO.Category::getId).collect(Collectors.toList()))
|
||||
// .stream().collect(Collectors.toMap(ProductCategoryBO::getId, category -> category));
|
||||
// // 设置分类名
|
||||
// condition.getCategories().forEach(category -> category.setName(categoryMap.get(category.getId()).getName()));
|
||||
// }
|
||||
// // 返回结果
|
||||
// return condition;
|
||||
// }
|
||||
|
||||
}
|
||||
8
search/search-biz/src/main/resources/biz.properties
Normal file
8
search/search-biz/src/main/resources/biz.properties
Normal file
@@ -0,0 +1,8 @@
|
||||
##################### 业务模块 #####################
|
||||
## OAuth2CodeService
|
||||
modules.oauth2-code-service.access-token-expire-time-millis = 2880000
|
||||
modules.oauth2-code-service.refresh-token-expire-time-millis = 43200000
|
||||
## OAuth2MobileCodeService
|
||||
modules.oauth2-mobile-code-service.code-expire-time-millis = 600000
|
||||
modules.oauth2-mobile-code-service.send-maximum-quantity-per-day = 10
|
||||
modules.oauth2-mobile-code-service.send-frequency = 60000
|
||||
7
search/search-biz/src/main/resources/biz.yaml
Normal file
7
search/search-biz/src/main/resources/biz.yaml
Normal file
@@ -0,0 +1,7 @@
|
||||
spring:
|
||||
data:
|
||||
# Jest 配置项
|
||||
jest:
|
||||
uri: http://127.0.0.1:9200
|
||||
|
||||
|
||||
Reference in New Issue
Block a user