修复图片检索问题

master
guoxin 1 year ago
parent 5520a6a07e
commit f3b10b3ba7
  1. 27
      shandan-browser/src/main/java/com/keyware/shandan/browser/service/FileSearchService.java
  2. 8
      shandan-browser/src/main/resources/static/js/browser.js
  3. 4
      shandan-browser/src/main/resources/view/browser.html

@ -21,6 +21,7 @@ import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.Requests;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.MatchPhraseQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.SearchHits;
@ -138,11 +139,16 @@ public class FileSearchService {
return PageVo.ofSearchHits(response.getHits(), param);
}
private List<String> getChildrenByDirId(String dirId) {
DirectoryVo dir = directoryService.getById(dirId);
return StreamUtil.as(directoryService.childrenLists(dir, ReviewStatus.SUBMITTED)).map(DirectoryVo::getId).toList();
}
/**
* 图片检索
*
* @param dirId
* @param searchText
* @param pageNo
* @param pageSize
* @return
* @throws IOException
*/
public PageVo<Object> searchImage(String dirId, String searchText, int pageNo, int pageSize) throws IOException {
SearchRequest request = Requests.searchRequest("shandan");
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
@ -159,8 +165,9 @@ public class FileSearchService {
}
if (StringUtils.hasText(searchText)) {
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
boolQuery.should(QueryBuilders.matchPhraseQuery("fileName", searchText));
queryBuilder.must(boolQuery);
MatchPhraseQueryBuilder matchPhraseQuery = QueryBuilders.matchPhraseQuery("fileName", searchText);
boolQuery.should();
queryBuilder.must(matchPhraseQuery);
}
searchSourceBuilder.query(queryBuilder);
@ -184,4 +191,10 @@ public class FileSearchService {
}).collect(Collectors.toList()));
return PageVo.ofSearchHits(response.getHits(), page);
}
private List<String> getChildrenByDirId(String dirId) {
DirectoryVo dir = directoryService.getById(dirId);
return StreamUtil.as(directoryService.childrenLists(dir, ReviewStatus.SUBMITTED)).map(DirectoryVo::getId).toList();
}
}

@ -499,19 +499,25 @@ layui.use(['layer', 'listPage', 'globalTree', 'gtable', 'form', 'element', 'drop
* 流式加载图片
*/
function queryImages(dirId, searchText) {
const {protocol, host, port} = window.location;
let pageNo = 1, pageSize = 20;
$('#layer-photos').html('')
$('#pic-container').html('')
layui.flow.load({
elem: '#pic-container',
isAuto: true,
mb: 100,
scrollElem: $('#pic-container').parent(),
done: function (page, next) { //执行下一页的回调
pageNo = page;
Util.get(`/search/image/page/${dirId}`, {pageNo, pageSize, searchText}).then(({flag, data, msg}) => {
if (flag) {
console.info(data);
const {records, pageTotal} = data, picItems = [];
const domain = protocol + "//" + host, pubDomain = 'http://24.47.112.32:6688';
for (const pic of records) {
if (pic.src.startsWith(pubDomain) && host !== '24.47.112.32') {
pic.src = pic.src.replace(pubDomain, domain)
}
const htm = `
<li class="pic-item">
<img layer-pid="${pic.id}" layer-src="${pic.src}" src="${pic.src}" alt="${pic.title}">

@ -257,6 +257,7 @@
<input class="layui-input" id="picSearchKey" placeholder="输入关键字进行查询" autocomplete>
<button class="layui-btn layui-btn-sm" lay-event="query" id="imageSearchBtn">查询</button>
</div>
<div class="pic-box" style="overflow-y: auto;">
<ul class="picture-container" id="pic-container"></ul>
</div>
</div>
@ -265,6 +266,7 @@
</div>
</div>
</div>
</div>
</body>
<!-- js -->
@ -273,7 +275,7 @@
const sizeInit = () => {
$(".layui-card-body").height(window.innerHeight - 20);
$("#tree-toobar-div").height($(".layui-card-body").height() - 25 - 45);
$(".picture-container").height($(".layui-card-body").height() - 140);
$(".pic-box").height($(".layui-card-body").height() - 140);
}
window.onresize = sizeInit;
sizeInit();