Skip to content
This repository has been archived by the owner on Sep 12, 2018. It is now read-only.

Commit

Permalink
Search: select not empty type
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Keesun Baik committed Aug 19, 2014
1 parent f1bb99c commit 3b1e724
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 6 deletions.
10 changes: 6 additions & 4 deletions app/controllers/SearchApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
48 changes: 48 additions & 0 deletions app/models/SearchResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion app/models/enumeration/SearchType.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion app/views/common/navbar.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
}
<li>
<form action="@makeSearchLink()" class="input-prepend gnb-search-form" name="gnb-search-form">
<input type="hidden" name="searchType" value="issue">
<input type="hidden" name="searchType" value="auto">
@if(project != null || org !=null) {

<div class="btn-group">
Expand Down

0 comments on commit 3b1e724

Please sign in to comment.