Skip to content

Commit

Permalink
perf: 优化标签页和收藏页下级目录的搜索
Browse files Browse the repository at this point in the history
  • Loading branch information
jamebal committed May 20, 2024
1 parent 90a1f05 commit 46714a4
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/main/java/com/jmal/clouddisk/service/impl/LuceneService.java
Original file line number Diff line number Diff line change
Expand Up @@ -551,24 +551,25 @@ private Query getQuery(SearchDTO searchDTO) throws ParseException {
}

private void otherQueryParams(SearchDTO searchDTO, BooleanQuery.Builder builder) {
if (StrUtil.isNotBlank(searchDTO.getType())) {
boolean queryPath = StrUtil.isNotBlank(searchDTO.getCurrentDirectory()) && searchDTO.getCurrentDirectory().length() > 1;
if (queryPath) {
Term prefixTerm = new Term("path", searchDTO.getCurrentDirectory());
PrefixQuery prefixQuery = new PrefixQuery(prefixTerm);
builder.add(prefixQuery, BooleanClause.Occur.MUST);
}
if (!queryPath && StrUtil.isNotBlank(searchDTO.getType())) {
builder.add(new TermQuery(new Term("type", searchDTO.getType())), BooleanClause.Occur.MUST);
}
if (searchDTO.getTagId() != null) {
if (!queryPath && searchDTO.getTagId() != null) {
TagDO tagDO = tagService.getTagInfo(searchDTO.getTagId());
if (tagDO != null) {
builder.add(new RegexpQuery(new Term("tag", ".*" + tagDO.getName() + ".*")), BooleanClause.Occur.MUST);
}
}
if (StrUtil.isNotBlank(searchDTO.getCurrentDirectory()) && searchDTO.getCurrentDirectory().length() > 1) {
Term prefixTerm = new Term("path", searchDTO.getCurrentDirectory());
PrefixQuery prefixQuery = new PrefixQuery(prefixTerm);
builder.add(prefixQuery, BooleanClause.Occur.MUST);
}
if (searchDTO.getIsFolder() != null) {
if (!queryPath && searchDTO.getIsFolder() != null) {
builder.add(IntPoint.newExactQuery("isFolder", searchDTO.getIsFolder() ? 1 : 0), BooleanClause.Occur.MUST);
}
if (searchDTO.getIsFavorite() != null) {
if (!queryPath && searchDTO.getIsFavorite() != null) {
builder.add(IntPoint.newExactQuery("isFavorite", searchDTO.getIsFavorite() ? 1 : 0), BooleanClause.Occur.MUST);
}
}
Expand Down

0 comments on commit 46714a4

Please sign in to comment.