热词获取改为根据数量,传递count获取系统热搜词语
This commit is contained in:
parent
6e611d3464
commit
0760c72ef8
@ -115,8 +115,8 @@ public class GoodsBuyerController {
|
|||||||
|
|
||||||
@ApiOperation(value = "获取搜索热词")
|
@ApiOperation(value = "获取搜索热词")
|
||||||
@GetMapping("/hot-words")
|
@GetMapping("/hot-words")
|
||||||
public ResultMessage<List<String>> getGoodsHotWords(Integer start, Integer end) {
|
public ResultMessage<List<String>> getGoodsHotWords(Integer count) {
|
||||||
List<String> hotWords = goodsSearchService.getHotWords(start, end);
|
List<String> hotWords = goodsSearchService.getHotWords(count);
|
||||||
return ResultUtil.data(hotWords);
|
return ResultUtil.data(hotWords);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
11
framework/src/main/java/cn/lili/cache/Cache.java
vendored
11
framework/src/main/java/cn/lili/cache/Cache.java
vendored
@ -244,6 +244,17 @@ public interface Cache<T> {
|
|||||||
*/
|
*/
|
||||||
Set<ZSetOperations.TypedTuple<Object>> reverseRangeWithScores(String sortedSetName, Integer start, Integer end);
|
Set<ZSetOperations.TypedTuple<Object>> reverseRangeWithScores(String sortedSetName, Integer start, Integer end);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* zrevrange命令, 查询Sorted Set中指定范围的值
|
||||||
|
* 返回的有序集合中,score大的在前面
|
||||||
|
* zrevrange方法无需担心用于指定范围的start和end出现越界报错问题
|
||||||
|
*
|
||||||
|
* @param sortedSetName sortedSetName
|
||||||
|
* @param count 查询数量
|
||||||
|
* @return 获取满足条件的集合
|
||||||
|
*/
|
||||||
|
Set<ZSetOperations.TypedTuple<Object>> reverseRangeWithScores(String sortedSetName, Integer count);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 向Zset里添加成员
|
* 向Zset里添加成员
|
||||||
|
@ -224,7 +224,7 @@ public class RedisCache implements Cache {
|
|||||||
@Override
|
@Override
|
||||||
public void incrementScore(String sortedSetName, String keyword) {
|
public void incrementScore(String sortedSetName, String keyword) {
|
||||||
//指向key名为KEY的zset元素
|
//指向key名为KEY的zset元素
|
||||||
redisTemplate.opsForZSet().incrementScore(sortedSetName,keyword, 1);
|
redisTemplate.opsForZSet().incrementScore(sortedSetName, keyword, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -247,6 +247,20 @@ public class RedisCache implements Cache {
|
|||||||
return this.redisTemplate.opsForZSet().reverseRangeWithScores(sortedSetName, start, end);
|
return this.redisTemplate.opsForZSet().reverseRangeWithScores(sortedSetName, start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* zrevrange命令, 查询Sorted Set中指定范围的值
|
||||||
|
* 返回的有序集合中,score大的在前面
|
||||||
|
* zrevrange方法无需担心用于指定范围的start和end出现越界报错问题
|
||||||
|
*
|
||||||
|
* @param sortedSetName sortedSetName
|
||||||
|
* @param count 获取数量
|
||||||
|
* @return 符合排序的集合
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Set<ZSetOperations.TypedTuple<Object>> reverseRangeWithScores(String sortedSetName, Integer count) {
|
||||||
|
return this.redisTemplate.opsForZSet().reverseRangeWithScores(sortedSetName, 0, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 向Zset里添加成员
|
* 向Zset里添加成员
|
||||||
|
@ -29,14 +29,14 @@ public interface EsGoodsSearchService {
|
|||||||
/**
|
/**
|
||||||
* 获取热门关键词
|
* 获取热门关键词
|
||||||
*
|
*
|
||||||
* @param start 查询范围开始位置
|
* @param count 热词数量
|
||||||
* @param end 查询范围结束位置
|
* @return 热词集合
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
List<String> getHotWords(Integer start, Integer end);
|
List<String> getHotWords(Integer count);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置热门关键词
|
* 设置热门关键词
|
||||||
|
*
|
||||||
* @param hotWords 热词分数
|
* @param hotWords 热词分数
|
||||||
*/
|
*/
|
||||||
void setHotWords(HotWordsDTO hotWords);
|
void setHotWords(HotWordsDTO hotWords);
|
||||||
|
@ -102,9 +102,9 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getHotWords(Integer start, Integer end) {
|
public List<String> getHotWords(Integer count) {
|
||||||
List<String> hotWords = new ArrayList<>();
|
List<String> hotWords = new ArrayList<>();
|
||||||
Set<DefaultTypedTuple> set = cache.reverseRangeWithScores(CachePrefix.HOT_WORD.getPrefix(), start, end);
|
Set<DefaultTypedTuple> set = cache.reverseRangeWithScores(CachePrefix.HOT_WORD.getPrefix(), count);
|
||||||
for (DefaultTypedTuple defaultTypedTuple : set) {
|
for (DefaultTypedTuple defaultTypedTuple : set) {
|
||||||
hotWords.add(Objects.requireNonNull(defaultTypedTuple.getValue()).toString());
|
hotWords.add(Objects.requireNonNull(defaultTypedTuple.getValue()).toString());
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ public class HotWordsManagerController {
|
|||||||
@ApiOperation(value = "获取热词")
|
@ApiOperation(value = "获取热词")
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public ResultMessage getHotWords() {
|
public ResultMessage getHotWords() {
|
||||||
return ResultUtil.data(esGoodsSearchService.getHotWords(0, 99));
|
return ResultUtil.data(esGoodsSearchService.getHotWords(99));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "设置热词")
|
@ApiOperation(value = "设置热词")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user