
Search: select not empty type
When a user search something with a keyword, this commit supports automatically select not-empty resource type. If there are many not-empty types, select the most top resource type in side menu. If all resource types are empty, select issue as a default.
@3b1e72415226efcb8937f63d07833967daa2397a
--- app/controllers/SearchApp.java
+++ app/controllers/SearchApp.java
... | ... | @@ -57,8 +57,7 @@ |
57 | 57 |
} |
58 | 58 |
|
59 | 59 |
SearchResult searchResult = getSearchResult(keyword, user, searchType); |
60 |
- |
|
61 |
- switch (searchType) { |
|
60 |
+ switch (searchResult.getSearchType()) { |
|
62 | 61 |
case ISSUE: |
63 | 62 |
searchResult.setIssues(Search.findIssues(keyword, user, pageParam)); |
64 | 63 |
break; |
... | ... | @@ -99,6 +98,7 @@ |
99 | 98 |
searchResult.setIssueCommentsCount(Search.countIssueComments(keyword, user)); |
100 | 99 |
searchResult.setPostCommentsCount(Search.countPostComments(keyword, user)); |
101 | 100 |
searchResult.setReviewsCount(Search.countReviews(keyword, user)); |
101 |
+ searchResult.updateSearchType(); |
|
102 | 102 |
return searchResult; |
103 | 103 |
} |
104 | 104 |
|
... | ... | @@ -129,7 +129,7 @@ |
129 | 129 |
|
130 | 130 |
SearchResult searchResult = getSearchResult(keyword, user, organization, searchType); |
131 | 131 |
|
132 |
- switch (searchType) { |
|
132 |
+ switch (searchResult.getSearchType()) { |
|
133 | 133 |
case ISSUE: |
134 | 134 |
searchResult.setIssues(Search.findIssues(keyword, user, organization, pageParam)); |
135 | 135 |
break; |
... | ... | @@ -171,6 +171,7 @@ |
171 | 171 |
searchResult.setIssueCommentsCount(Search.countIssueComments(keyword, user, organization)); |
172 | 172 |
searchResult.setPostCommentsCount(Search.countPostComments(keyword, user, organization)); |
173 | 173 |
searchResult.setReviewsCount(Search.countReviews(keyword, user, organization)); |
174 |
+ searchResult.updateSearchType(); |
|
174 | 175 |
return searchResult; |
175 | 176 |
} |
176 | 177 |
|
... | ... | @@ -203,7 +204,7 @@ |
203 | 204 |
|
204 | 205 |
SearchResult searchResult = getSearchResult(keyword, user, project, searchType); |
205 | 206 |
|
206 |
- switch (searchType) { |
|
207 |
+ switch (searchResult.getSearchType()) { |
|
207 | 208 |
case ISSUE: |
208 | 209 |
searchResult.setIssues(Search.findIssues(keyword, user, project, pageParam)); |
209 | 210 |
break; |
... | ... | @@ -241,6 +242,7 @@ |
241 | 242 |
searchResult.setIssueCommentsCount(Search.countIssueComments(keyword, user, project)); |
242 | 243 |
searchResult.setPostCommentsCount(Search.countPostComments(keyword, user, project)); |
243 | 244 |
searchResult.setReviewsCount(Search.countReviews(keyword, user, project)); |
245 |
+ searchResult.updateSearchType(); |
|
244 | 246 |
return searchResult; |
245 | 247 |
} |
246 | 248 |
|
--- app/models/SearchResult.java
+++ app/models/SearchResult.java
... | ... | @@ -106,6 +106,54 @@ |
106 | 106 |
return endIndex < contentLength ? endIndex : contentLength; |
107 | 107 |
} |
108 | 108 |
|
109 |
+ public void updateSearchType() { |
|
110 |
+ if(!(this.searchType == SearchType.AUTO)) { |
|
111 |
+ return; |
|
112 |
+ } |
|
113 |
+ |
|
114 |
+ if (getIssuesCount() > 0) { |
|
115 |
+ setSearchType(SearchType.ISSUE); |
|
116 |
+ return; |
|
117 |
+ } |
|
118 |
+ |
|
119 |
+ if (getUsersCount() > 0) { |
|
120 |
+ setSearchType(SearchType.USER); |
|
121 |
+ return; |
|
122 |
+ } |
|
123 |
+ |
|
124 |
+ if (getProjectsCount() > 0) { |
|
125 |
+ setSearchType(SearchType.PROJECT); |
|
126 |
+ return; |
|
127 |
+ } |
|
128 |
+ |
|
129 |
+ if (getPostsCount() > 0) { |
|
130 |
+ setSearchType(SearchType.POST); |
|
131 |
+ return; |
|
132 |
+ } |
|
133 |
+ |
|
134 |
+ if (getMilestonesCount() > 0) { |
|
135 |
+ setSearchType(SearchType.MILESTONE); |
|
136 |
+ return; |
|
137 |
+ } |
|
138 |
+ |
|
139 |
+ if (getIssueCommentsCount() > 0) { |
|
140 |
+ setSearchType(SearchType.ISSUE_COMMENT); |
|
141 |
+ return; |
|
142 |
+ } |
|
143 |
+ |
|
144 |
+ if (getPostCommentsCount() > 0) { |
|
145 |
+ setSearchType(SearchType.POST_COMMENT); |
|
146 |
+ return; |
|
147 |
+ } |
|
148 |
+ |
|
149 |
+ if (getReviewsCount() > 0) { |
|
150 |
+ setSearchType(SearchType.REVIEW); |
|
151 |
+ return; |
|
152 |
+ } |
|
153 |
+ |
|
154 |
+ setSearchType(SearchType.ISSUE); |
|
155 |
+ } |
|
156 |
+ |
|
109 | 157 |
private class BeginAndEnd { |
110 | 158 |
int beginIndex; |
111 | 159 |
int endIndex; |
--- app/models/enumeration/SearchType.java
+++ app/models/enumeration/SearchType.java
... | ... | @@ -5,7 +5,7 @@ |
5 | 5 |
*/ |
6 | 6 |
public enum SearchType { |
7 | 7 |
|
8 |
- NA("not available"), USER("user"), PROJECT("project"), ISSUE("issue"), POST("post"), |
|
8 |
+ AUTO("auto"), NA("not available"), USER("user"), PROJECT("project"), ISSUE("issue"), POST("post"), |
|
9 | 9 |
MILESTONE("milestone"), ISSUE_COMMENT("issue_comment"), POST_COMMENT("post_comment"), REVIEW("review"); |
10 | 10 |
|
11 | 11 |
private String searchType; |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?