|
|
@@ -1,5 +1,6 @@
|
|
|
package com.doc.biz.controller;
|
|
|
|
|
|
+import cn.hutool.http.HttpRequest;
|
|
|
import com.doc.biz.domain.DocInfo;
|
|
|
import com.doc.biz.domain.DocSpace;
|
|
|
import com.doc.biz.domain.EsDocInfo;
|
|
|
@@ -15,11 +16,10 @@ import io.swagger.annotations.ApiImplicitParam;
|
|
|
import io.swagger.annotations.ApiImplicitParams;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import javafx.util.Pair;
|
|
|
-import org.apache.http.HttpResponse;
|
|
|
-import org.apache.http.nio.protocol.HttpAsyncResponseConsumer;
|
|
|
import org.elasticsearch.client.HeapBufferedAsyncResponseConsumer;
|
|
|
import org.elasticsearch.client.HttpAsyncResponseConsumerFactory;
|
|
|
import org.elasticsearch.client.RequestOptions;
|
|
|
+import org.springframework.core.env.Environment;
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.data.domain.Sort;
|
|
|
@@ -54,6 +54,8 @@ public class ElasticSearchController {
|
|
|
private IDocSpaceService spaceService;
|
|
|
@Resource
|
|
|
private IDocDirService dirService;
|
|
|
+ @Resource
|
|
|
+ private Environment environment;
|
|
|
|
|
|
|
|
|
/**
|
|
|
@@ -115,9 +117,8 @@ public class ElasticSearchController {
|
|
|
page = page - 1;
|
|
|
String indexName = "docs_" + spaceId;
|
|
|
esConfig.setIndexName(indexName);
|
|
|
-
|
|
|
try {
|
|
|
- setBuffer();
|
|
|
+ setParam();
|
|
|
Pageable pageable = PageRequest.of(page, size, Sort.by(Sort.Order.desc("id")));
|
|
|
long total = esService.countByContent(keyword);
|
|
|
List<SearchHit<EsDocInfo>> all = esService.findByContent(keyword, pageable);
|
|
|
@@ -132,6 +133,9 @@ public class ElasticSearchController {
|
|
|
docInfo.setDir(dirService.selectDocDirByDirId(docInfo.getDirId()));
|
|
|
esDocInfo.setDocInfo(docInfo);
|
|
|
result.add(re);
|
|
|
+ } else {
|
|
|
+ esService.delete(esDocInfo);
|
|
|
+ total--;
|
|
|
}
|
|
|
}
|
|
|
return new Pair<>(total, result);
|
|
|
@@ -144,11 +148,26 @@ public class ElasticSearchController {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 设置es查询buffer大小
|
|
|
+ * 设置高量显示偏移
|
|
|
+ * 设置查询BUFFER大小
|
|
|
*/
|
|
|
- private void setBuffer() {
|
|
|
+ private void setParam() {
|
|
|
try {
|
|
|
- //设置es查询buffer大小
|
|
|
+ //设置高亮显示偏移--start
|
|
|
+ String esUri = environment.getProperty("spring.elasticsearch.rest.uris");
|
|
|
+ String offset = environment.getProperty("spring.elasticsearch.highlight.max-analyzed-offset");
|
|
|
+ String body = "{" +
|
|
|
+ " \"index\" : {" +
|
|
|
+ " \"highlight.max_analyzed_offset\":%s" +
|
|
|
+ " }" +
|
|
|
+ "}";
|
|
|
+ body = String.format(body, offset);
|
|
|
+ HttpRequest.put(esUri + "/_settings").header("Content-Type", "application/json")
|
|
|
+ .body(body).execute().body();
|
|
|
+ //设置高亮显示偏移--end
|
|
|
+
|
|
|
+
|
|
|
+ //设置es查询buffer大小--start
|
|
|
RequestOptions requestOptions = RequestOptions.DEFAULT;
|
|
|
Class<? extends RequestOptions> reqClass = requestOptions.getClass();
|
|
|
Field reqField = reqClass.getDeclaredField("httpAsyncResponseConsumerFactory");
|
|
|
@@ -158,16 +177,13 @@ public class ElasticSearchController {
|
|
|
modifiersField.setAccessible(true);
|
|
|
modifiersField.setInt(reqField, reqField.getModifiers() & ~Modifier.FINAL);
|
|
|
//设置默认的工厂
|
|
|
- reqField.set(requestOptions, new HttpAsyncResponseConsumerFactory() {
|
|
|
- @Override
|
|
|
- public HttpAsyncResponseConsumer<HttpResponse> createHttpAsyncResponseConsumer() {
|
|
|
- //1GB
|
|
|
- return new HeapBufferedAsyncResponseConsumer(5 * 100 * 1024 * 1024);
|
|
|
- }
|
|
|
+ reqField.set(requestOptions, (HttpAsyncResponseConsumerFactory) () -> {
|
|
|
+ //500MB
|
|
|
+ return new HeapBufferedAsyncResponseConsumer(5 * 100 * 1024 * 1024);
|
|
|
});
|
|
|
- } catch (NoSuchIndexException | IllegalAccessException e) {
|
|
|
- } catch (NoSuchFieldException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
+ //设置es查询buffer大小--end
|
|
|
+ } catch (NoSuchFieldException | IllegalAccessException e) {
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
}
|