修复图片检索问题

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.Requests;
import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.index.query.BoolQueryBuilder; import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.MatchPhraseQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.SearchHits; import org.elasticsearch.search.SearchHits;
@ -138,11 +139,16 @@ public class FileSearchService {
return PageVo.ofSearchHits(response.getHits(), param); 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 { public PageVo<Object> searchImage(String dirId, String searchText, int pageNo, int pageSize) throws IOException {
SearchRequest request = Requests.searchRequest("shandan"); SearchRequest request = Requests.searchRequest("shandan");
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
@ -159,8 +165,9 @@ public class FileSearchService {
} }
if (StringUtils.hasText(searchText)) { if (StringUtils.hasText(searchText)) {
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery(); BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
boolQuery.should(QueryBuilders.matchPhraseQuery("fileName", searchText)); MatchPhraseQueryBuilder matchPhraseQuery = QueryBuilders.matchPhraseQuery("fileName", searchText);
queryBuilder.must(boolQuery); boolQuery.should();
queryBuilder.must(matchPhraseQuery);
} }
searchSourceBuilder.query(queryBuilder); searchSourceBuilder.query(queryBuilder);
@ -184,4 +191,10 @@ public class FileSearchService {
}).collect(Collectors.toList())); }).collect(Collectors.toList()));
return PageVo.ofSearchHits(response.getHits(), page); 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) { function queryImages(dirId, searchText) {
const {protocol, host, port} = window.location;
let pageNo = 1, pageSize = 20; let pageNo = 1, pageSize = 20;
$('#layer-photos').html('') $('#pic-container').html('')
layui.flow.load({ layui.flow.load({
elem: '#pic-container', elem: '#pic-container',
isAuto: true, isAuto: true,
mb: 100, mb: 100,
scrollElem: $('#pic-container').parent(),
done: function (page, next) { //执行下一页的回调 done: function (page, next) { //执行下一页的回调
pageNo = page; pageNo = page;
Util.get(`/search/image/page/${dirId}`, {pageNo, pageSize, searchText}).then(({flag, data, msg}) => { Util.get(`/search/image/page/${dirId}`, {pageNo, pageSize, searchText}).then(({flag, data, msg}) => {
if (flag) { if (flag) {
console.info(data); console.info(data);
const {records, pageTotal} = data, picItems = []; const {records, pageTotal} = data, picItems = [];
const domain = protocol + "//" + host, pubDomain = 'http://24.47.112.32:6688';
for (const pic of records) { for (const pic of records) {
if (pic.src.startsWith(pubDomain) && host !== '24.47.112.32') {
pic.src = pic.src.replace(pubDomain, domain)
}
const htm = ` const htm = `
<li class="pic-item"> <li class="pic-item">
<img layer-pid="${pic.id}" layer-src="${pic.src}" src="${pic.src}" alt="${pic.title}"> <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> <input class="layui-input" id="picSearchKey" placeholder="输入关键字进行查询" autocomplete>
<button class="layui-btn layui-btn-sm" lay-event="query" id="imageSearchBtn">查询</button> <button class="layui-btn layui-btn-sm" lay-event="query" id="imageSearchBtn">查询</button>
</div> </div>
<div class="pic-box" style="overflow-y: auto;">
<ul class="picture-container" id="pic-container"></ul> <ul class="picture-container" id="pic-container"></ul>
</div> </div>
</div> </div>
@ -265,6 +266,7 @@
</div> </div>
</div> </div>
</div> </div>
</div>
</body> </body>
<!-- js --> <!-- js -->
@ -273,7 +275,7 @@
const sizeInit = () => { const sizeInit = () => {
$(".layui-card-body").height(window.innerHeight - 20); $(".layui-card-body").height(window.innerHeight - 20);
$("#tree-toobar-div").height($(".layui-card-body").height() - 25 - 45); $("#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; window.onresize = sizeInit;
sizeInit(); sizeInit();