diff --git a/app/controllers/SearchApp.java b/app/controllers/SearchApp.java index 2aa182e43..64820d318 100644 --- a/app/controllers/SearchApp.java +++ b/app/controllers/SearchApp.java @@ -57,8 +57,7 @@ public static Result searchInAll() { } SearchResult searchResult = getSearchResult(keyword, user, searchType); - - switch (searchType) { + switch (searchResult.getSearchType()) { case ISSUE: searchResult.setIssues(Search.findIssues(keyword, user, pageParam)); break; @@ -99,6 +98,7 @@ private static SearchResult getSearchResult(String keyword, User user, SearchTyp searchResult.setIssueCommentsCount(Search.countIssueComments(keyword, user)); searchResult.setPostCommentsCount(Search.countPostComments(keyword, user)); searchResult.setReviewsCount(Search.countReviews(keyword, user)); + searchResult.updateSearchType(); return searchResult; } @@ -129,7 +129,7 @@ public static Result searchInAGroup(String organizationName) { SearchResult searchResult = getSearchResult(keyword, user, organization, searchType); - switch (searchType) { + switch (searchResult.getSearchType()) { case ISSUE: searchResult.setIssues(Search.findIssues(keyword, user, organization, pageParam)); break; @@ -171,6 +171,7 @@ private static SearchResult getSearchResult(String keyword, User user, Organizat searchResult.setIssueCommentsCount(Search.countIssueComments(keyword, user, organization)); searchResult.setPostCommentsCount(Search.countPostComments(keyword, user, organization)); searchResult.setReviewsCount(Search.countReviews(keyword, user, organization)); + searchResult.updateSearchType(); return searchResult; } @@ -203,7 +204,7 @@ public static Result searchInAProject(String loginId, String projectName) { SearchResult searchResult = getSearchResult(keyword, user, project, searchType); - switch (searchType) { + switch (searchResult.getSearchType()) { case ISSUE: searchResult.setIssues(Search.findIssues(keyword, user, project, pageParam)); break; @@ -241,6 +242,7 @@ private static SearchResult getSearchResult(String keyword, User user, Project p searchResult.setIssueCommentsCount(Search.countIssueComments(keyword, user, project)); searchResult.setPostCommentsCount(Search.countPostComments(keyword, user, project)); searchResult.setReviewsCount(Search.countReviews(keyword, user, project)); + searchResult.updateSearchType(); return searchResult; } diff --git a/app/models/SearchResult.java b/app/models/SearchResult.java index bbb7d9ce7..c68d10805 100644 --- a/app/models/SearchResult.java +++ b/app/models/SearchResult.java @@ -106,6 +106,54 @@ private int endIndex(int keywordEndIndex, int contentLength, int threshold) { return endIndex < contentLength ? endIndex : contentLength; } + public void updateSearchType() { + if(!(this.searchType == SearchType.AUTO)) { + return; + } + + if (getIssuesCount() > 0) { + setSearchType(SearchType.ISSUE); + return; + } + + if (getUsersCount() > 0) { + setSearchType(SearchType.USER); + return; + } + + if (getProjectsCount() > 0) { + setSearchType(SearchType.PROJECT); + return; + } + + if (getPostsCount() > 0) { + setSearchType(SearchType.POST); + return; + } + + if (getMilestonesCount() > 0) { + setSearchType(SearchType.MILESTONE); + return; + } + + if (getIssueCommentsCount() > 0) { + setSearchType(SearchType.ISSUE_COMMENT); + return; + } + + if (getPostCommentsCount() > 0) { + setSearchType(SearchType.POST_COMMENT); + return; + } + + if (getReviewsCount() > 0) { + setSearchType(SearchType.REVIEW); + return; + } + + setSearchType(SearchType.ISSUE); + } + private class BeginAndEnd { int beginIndex; int endIndex; diff --git a/app/models/enumeration/SearchType.java b/app/models/enumeration/SearchType.java index 8f78e6e46..c04ca30fd 100644 --- a/app/models/enumeration/SearchType.java +++ b/app/models/enumeration/SearchType.java @@ -5,7 +5,7 @@ */ public enum SearchType { - NA("not available"), USER("user"), PROJECT("project"), ISSUE("issue"), POST("post"), + AUTO("auto"), NA("not available"), USER("user"), PROJECT("project"), ISSUE("issue"), POST("post"), MILESTONE("milestone"), ISSUE_COMMENT("issue_comment"), POST_COMMENT("post_comment"), REVIEW("review"); private String searchType; diff --git a/app/views/common/navbar.scala.html b/app/views/common/navbar.scala.html index 29212a96b..cfc65394a 100644 --- a/app/views/common/navbar.scala.html +++ b/app/views/common/navbar.scala.html @@ -65,7 +65,7 @@ }