优化搜索热词管理,增加搜索热词删除

This commit is contained in:
paulGao 2021-12-24 16:11:53 +08:00
parent b648aa94b3
commit ed840a95a1
3 changed files with 27 additions and 7 deletions

View File

@ -41,6 +41,13 @@ public interface EsGoodsSearchService {
*/ */
void setHotWords(HotWordsDTO hotWords); void setHotWords(HotWordsDTO hotWords);
/**
* 删除热门关键词
*
* @param keywords 热词
*/
void deleteHotWords(String keywords);
/** /**
* 获取筛选器 * 获取筛选器
* *

View File

@ -114,6 +114,16 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService {
cache.incrementScore(CachePrefix.HOT_WORD.getPrefix(), hotWords.getKeywords(), hotWords.getPoint()); cache.incrementScore(CachePrefix.HOT_WORD.getPrefix(), hotWords.getKeywords(), hotWords.getPoint());
} }
/**
* 删除热门关键词
*
* @param keywords 热词
*/
@Override
public void deleteHotWords(String keywords) {
cache.zRemove(CachePrefix.HOT_WORD.getPrefix(), keywords);
}
@Override @Override
public EsGoodsRelatedInfo getSelector(EsGoodsSearchDTO goodsSearch, PageVO pageVo) { public EsGoodsRelatedInfo getSelector(EsGoodsSearchDTO goodsSearch, PageVO pageVo) {
NativeSearchQueryBuilder builder = createSearchQueryBuilder(goodsSearch, null); NativeSearchQueryBuilder builder = createSearchQueryBuilder(goodsSearch, null);

View File

@ -8,10 +8,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/** /**
* 管理端,app版本控制器 * 管理端,app版本控制器
@ -29,16 +26,22 @@ public class HotWordsManagerController {
@ApiOperation(value = "获取热词") @ApiOperation(value = "获取热词")
@GetMapping @GetMapping
public ResultMessage getHotWords() { public ResultMessage<Object> getHotWords() {
return ResultUtil.data(esGoodsSearchService.getHotWords(100)); return ResultUtil.data(esGoodsSearchService.getHotWords(100));
} }
@ApiOperation(value = "设置热词") @ApiOperation(value = "设置热词")
@PostMapping @PostMapping
public ResultMessage paymentForm(@Validated HotWordsDTO hotWords) { public ResultMessage<Object> paymentForm(@Validated HotWordsDTO hotWords) {
esGoodsSearchService.setHotWords(hotWords); esGoodsSearchService.setHotWords(hotWords);
return ResultUtil.success(); return ResultUtil.success();
} }
@ApiOperation(value = "设置热词")
@DeleteMapping("/{words}")
public ResultMessage<Object> deleteWords(@PathVariable String words) {
esGoodsSearchService.deleteHotWords(words);
return ResultUtil.success();
}
} }