按庞云意思讲全文检索默认使用推荐词进行搜索

master
guoxin 1 year ago
parent 82a64d8df7
commit d74eded61f
  1. 18
      shandan-browser/src/main/java/com/keyware/shandan/browser/service/FileSearchService.java

@ -4,6 +4,7 @@ import cn.hutool.core.util.ReflectUtil;
import com.keyware.shandan.bianmu.entity.DirectoryVo;
import com.keyware.shandan.bianmu.enums.ReviewStatus;
import com.keyware.shandan.bianmu.service.DirectoryService;
import com.keyware.shandan.browser.SearchLogProcessor;
import com.keyware.shandan.browser.entity.FullSearchParam;
import com.keyware.shandan.browser.entity.PageVo;
import com.keyware.shandan.common.constants.DirConstant;
@ -45,15 +46,28 @@ public class FileSearchService {
private RestHighLevelClient esClient;
@Autowired
private DirectoryService directoryService;
@Autowired
private SearchLogProcessor searchLogProcessor;
public PageVo searchFile(FullSearchParam param) throws IOException {
SearchRequest request = Requests.searchRequest("shandan");
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.from(param.getPage() * param.getSize() - param.getSize()).size(param.getSize());
String metaId = param.getMetaId();
String text = param.getSearch();
boolean defaultSearch = StringUtils.isBlank(text) && (StringUtils.isBlank(metaId) || "ROOT".equals(metaId));
if (defaultSearch) {
List<String> words = new ArrayList<>();
for (String systemWord : searchLogProcessor.getSystemWords()) {
words.add(systemWord);
if (words.size() == 5) {
break;
}
}
text = String.join(" ", words);
}
String[] searchFields = param.getSearchFields().split(",");
BoolQueryBuilder builder = QueryBuilders.boolQuery();
@ -63,7 +77,7 @@ public class FileSearchService {
ids.addAll(getChildrenByDirId(metaId));
builder.must(QueryBuilders.termsQuery("entityId", ids));
}
if (StringUtils.isNotBlank(text)) {
if (StringUtils.hasText(text)) {
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
String[] includesCol = {"fileName", "entryStaff", "equipmentModel", "source", "taskCode", "taskNature", "troopCode", "targetNumber", "missileNumber", "themeTask", "remark", "text"};