Skip to content

Commit

Permalink
Merge pull request #55 from jamebal/lucene
Browse files Browse the repository at this point in the history
perf: 优化标签页面搜索
  • Loading branch information
jamebal authored May 22, 2024
2 parents 44574a1 + 46714a4 commit 367e5c4
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/main/java/com/jmal/clouddisk/service/impl/LuceneService.java
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,6 @@ private Query getQuery(SearchDTO searchDTO) throws ParseException {
continue;
}
regexpQueryBuilder.add(new BoostQuery(new RegexpQuery(new Term(field, ".*" + keyword + ".*")), boosts.get(field)), BooleanClause.Occur.SHOULD);
// regexpQueryBuilder.add(new BoostQuery(new WildcardQuery(new Term("field", "*" + keyword + "*")), boosts.get(field)), BooleanClause.Occur.SHOULD);
}
Query regExpQuery = regexpQueryBuilder.build();
BoostQuery boostedRegExpQuery = new BoostQuery(regExpQuery, 10.0f);
Expand Down Expand Up @@ -552,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 TermQuery(new Term("tag", tagDO.getName())), BooleanClause.Occur.MUST);
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 367e5c4

Please sign in to comment.