Redis + jieba分词 做到排序索引

<!-- pom 文件-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>

<!-- https://mvnrepository.com/artifact/com.huaban/jieba-analysis -->
<dependency>
<groupId>com.huaban</groupId>
<artifactId>jieba-analysis</artifactId>
<version>1.0.2</version>
</dependency>

//商品名分词
@RequestMapping(value = "/Particple")
@ResponseBody
public void commnameParticple(){
List<Commodity> list = commodityService.findAll();
ParticipleUtils participleUtils = new ParticipleUtils();
participleUtils.getparticiple(list);
}

//Jieba分词   有不同的分词策略  
public  void  getparticiple(List<Commodity> participle){
Jedis jedis = new Jedis("127.0.0.1", 6379);
JiebaSegmenter jiebaSegmenter = new JiebaSegmenter();
for (Commodity part: participle){
List<SegToken> process = jiebaSegmenter.process(part.getComname(), JiebaSegmenter.SegMode.SEARCH);
for (SegToken segToken: process ){
if(segToken.toString().length()>1){
jedis.sadd(segToken.word,String.valueOf(part.getId()));
}
}
}
}
posted @ 2020-08-11 17:49  爵士灬  阅读(587)  评论(0编辑  收藏  举报