对于之前的版本,高亮显示又一定的问题,对此做出了改进。
Controller:
//关键词搜索#新新
@GetMapping("/searchByKeyWords")
public Result searchByKeyWords(@RequestParam(defaultValue = "1") int PageNum,
@RequestParam(defaultValue = "10") int PageSize,
@RequestParam(defaultValue = "") String words) throws IOException {
return patentService.searchByKeyWords(PageNum,PageSize,words);
}
Service接口:
Result searchByKeyWords(int PageNum,int PageSize,String words) throws IOException;
ServiceImpl:(Jieba分词和ListToOne的方法见之前的博客)
//根据关键词搜索专利,Lucene版
@Override
public Result searchByKeyWords(int PageNum, int PageSize, String words) throws IOException {
JieBaUtil jieBaUtil = new JieBaUtil();
Page page = new Page();
List<String> keyWords = jieBaUtil.separateAndClear(words);
List<Patent> result = new ArrayList<>();
if (keyWords.isEmpty()) {
result = DataBaseSearcher.searchData(words,words);
}
else {
for (String keyword : keyWords) {
List<Patent> perResult = DataBaseSearcher.searchData(keyword,words);
result = jieBaUtil.listsToOne(r