|
@@ -1,57 +1,26 @@
|
|
|
package com.dayou.controller;
|
|
|
|
|
|
-import cn.hutool.core.util.StrUtil;
|
|
|
-import com.dayou.annotation.IgnoreAuth;
|
|
|
+
|
|
|
import com.dayou.dto.TaskRecordDTO;
|
|
|
import com.dayou.dto.WorkNodeCommit;
|
|
|
-import com.dayou.vo.LuceneSearchVO;
|
|
|
import com.dayou.vo.PersonalVO;
|
|
|
import com.dayou.vo.TaskTodoVO;
|
|
|
import com.dayou.workflow.annotation.FinishTask;
|
|
|
-import org.apache.lucene.analysis.Analyzer;
|
|
|
-import org.apache.lucene.analysis.TokenStream;
|
|
|
-import org.apache.lucene.analysis.cn.smart.SmartChineseAnalyzer;
|
|
|
-import org.apache.lucene.document.Document;
|
|
|
-import org.apache.lucene.index.DirectoryReader;
|
|
|
-import org.apache.lucene.queryparser.classic.MultiFieldQueryParser;
|
|
|
-import org.apache.lucene.queryparser.classic.ParseException;
|
|
|
-import org.apache.lucene.queryparser.classic.QueryParser;
|
|
|
-import org.apache.lucene.search.IndexSearcher;
|
|
|
-import org.apache.lucene.search.Query;
|
|
|
-import org.apache.lucene.search.ScoreDoc;
|
|
|
-import org.apache.lucene.search.TopDocs;
|
|
|
-import org.apache.lucene.search.highlight.*;
|
|
|
-import org.apache.lucene.store.Directory;
|
|
|
-import org.apache.lucene.store.FSDirectory;
|
|
|
-import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
-import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
-import com.dayou.controller.BaseController;
|
|
|
import com.dayou.service.IPersonalService;
|
|
|
import com.dayou.entity.Personal;
|
|
|
import com.dayou.common.RestResponse;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
-import com.dayou.utils.ConvertUtil;
|
|
|
-import com.dayou.utils.HttpKit;
|
|
|
-import com.dayou.exception.ErrorCode;
|
|
|
-
|
|
|
-import java.io.IOException;
|
|
|
-import java.io.StringReader;
|
|
|
-import java.nio.file.FileSystems;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
+
|
|
|
import java.util.List;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
-import org.springframework.http.MediaType;
|
|
|
-import org.springframework.web.multipart.MultipartFile;
|
|
|
-import org.wltea.analyzer.lucene.IKAnalyzer;
|
|
|
|
|
|
import javax.validation.Valid;
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 个贷业务订单
|
|
|
*
|
|
@@ -182,45 +151,6 @@ public class PersonalController extends BaseController {
|
|
|
return RestResponse.data(pages);
|
|
|
}
|
|
|
|
|
|
- @IgnoreAuth
|
|
|
- @GetMapping("/search/{keyword}")
|
|
|
- public RestResponse<List<LuceneSearchVO>> searchText(@PathVariable("keyword") String keyword) throws IOException, ParseException, InvalidTokenOffsetsException {
|
|
|
-
|
|
|
- Directory directory = FSDirectory.open(FileSystems.getDefault().getPath("G:\\luceneIndex"));
|
|
|
- DirectoryReader reader = DirectoryReader.open(directory);
|
|
|
- IndexSearcher indexSearcher = new IndexSearcher(reader);
|
|
|
- QueryParser parser = new QueryParser ("result", new IKAnalyzer());
|
|
|
- Query query = parser.parse(keyword);
|
|
|
- TopDocs topDocs = indexSearcher.search(query, 15);
|
|
|
-
|
|
|
- //加入高亮显示的
|
|
|
- SimpleHTMLFormatter simpleHTMLFormatter = new SimpleHTMLFormatter("<span style='color:red'>", "</span>");
|
|
|
- Highlighter highlighter = new Highlighter(simpleHTMLFormatter, new QueryScorer(query));
|
|
|
- //高亮后的段落范围在100字内
|
|
|
- Fragmenter fragmenter = new SimpleFragmenter(50);
|
|
|
- highlighter.setTextFragmenter(fragmenter);
|
|
|
-
|
|
|
-
|
|
|
- log.info("本次搜索共找到" + topDocs.totalHits + "条数据");
|
|
|
- ScoreDoc[] scoreDocs = topDocs.scoreDocs;
|
|
|
- List<LuceneSearchVO> results = new ArrayList<>();
|
|
|
- for (ScoreDoc scoreDoc :scoreDocs){
|
|
|
- LuceneSearchVO luceneSearchVO = new LuceneSearchVO();
|
|
|
- // 取出文档编号
|
|
|
- int docId = scoreDoc.doc;
|
|
|
- Document doc = reader.document(docId);
|
|
|
- luceneSearchVO.setId(doc.get("id"));
|
|
|
- String result = doc.get("result");
|
|
|
- if (StrUtil.isNotBlank(result)){
|
|
|
- result = highlighter.getBestFragment(new IKAnalyzer(), "result", result);
|
|
|
- }
|
|
|
- luceneSearchVO.setResult(result);
|
|
|
- luceneSearchVO.setBusinessEnum(doc.get("businessEnum"));
|
|
|
- luceneSearchVO.setMenuName(doc.get("menuName"));
|
|
|
- luceneSearchVO.setUrl(doc.get("url"));
|
|
|
- results.add(luceneSearchVO);
|
|
|
- }
|
|
|
- return RestResponse.data(results);
|
|
|
- }
|
|
|
+
|
|
|
}
|
|
|
|