Author: bbrossaud Date: 2010-05-31 15:54:19 +0200 (Mon, 31 May 2010) New Revision: 45 Url: http://chorem.org/repositories/revision/bow/45 Log: the opensearch now suggest the url if there are less than 5 bookmarks Modified: trunk/src/main/java/org/chorem/bow/ControllerServlet.java trunk/src/main/java/org/chorem/bow/OpenSearchActions.java Modified: trunk/src/main/java/org/chorem/bow/ControllerServlet.java =================================================================== --- trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-31 10:21:08 UTC (rev 44) +++ trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-05-31 13:54:19 UTC (rev 45) @@ -12,7 +12,6 @@ import java.security.NoSuchAlgorithmException; import java.util.ArrayList; import java.util.Arrays; -import java.util.Date; import java.util.Iterator; import java.util.List; import javax.servlet.ServletException; @@ -182,7 +181,6 @@ log.debug("Going to actionOrderDesc"); } this.actionOrderDesc(request, response, user); - request.getRequestDispatcher("openSearchResult.jsp").forward(request, response); } else if (action.equals("addClick") && user != null) { if (log.isDebugEnabled()) { log.debug("Going to actionAddClic"); @@ -228,13 +226,19 @@ protected void actionOpenSearchResult(HttpServletRequest request, HttpServletResponse response, User user, String token) throws IOException, ServletException { - WikittyProxy proxy = model.getProxy(); - Criteria criteria = Search.query().eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria(). - addSortDescending(Bookmark.FQ_FIELD_CLICK); - List<Bookmark> bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll(); - BookmarkActions bookmarkActions = createBookmarkActions(request, bookList); - request.setAttribute("bookmarkActions", bookmarkActions); - request.setAttribute("token", token); + String searchLine = request.getParameter("searchLine"); + if (searchLine != null && searchLine.matches("^http://[^ ]*") && !searchLine.contains(" ")) { + response.sendRedirect(searchLine); + } else { + WikittyProxy proxy = model.getProxy(); + Criteria criteria = Search.query().eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria(). + addSortDescending(Bookmark.FQ_FIELD_CLICK); + List<Bookmark> bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll(); + BookmarkActions bookmarkActions = createBookmarkActions(request, bookList); + request.setAttribute("bookmarkActions", bookmarkActions); + request.setAttribute("token", token); + request.getRequestDispatcher("openSearchResult.jsp").forward(request, response); + } } protected void actionOpenSearchSuggestion(HttpServletRequest request, HttpServletResponse response, User user) @@ -244,16 +248,23 @@ if (search != null) { OpenSearchActions openSearchActions = new OpenSearchActions(); WikittyProxy proxy = model.getProxy(); - Criteria criteria = Search.query().eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria(); - List<Bookmark> bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll(); - openSearchActions.setBookmarkList(bookList); String[] words = search.split("\\s+"); List<String> searchLine = new ArrayList<String>(Arrays.asList(words)); if (search.charAt(search.length() - 1) == ' ') { searchLine.add(""); } + Criteria criteria = null; + if (searchLine.size() > 1) { + List<String> cpy = new ArrayList<String>(searchLine); + cpy.remove(cpy.size() - 1); + criteria = Search.query().eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()). + contains(Bookmark.FQ_FIELD_TAGS, cpy).criteria(); + } else { + criteria = Search.query().eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria(); + } + List<Bookmark> bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll(); + openSearchActions.setBookmarkList(bookList); openSearchActions.findSuggestions(searchLine); - log.debug("result={" + openSearchActions.getJsonResult() + "}"); request.setAttribute("openSearchAction", openSearchActions); } } @@ -276,8 +287,8 @@ ++click; bookmark.setClick(click); proxy.store(bookmark); - String url = bookmark.getLink(); - response.sendRedirect(url); + String link = bookmark.getLink(); + response.sendRedirect(link); } } } @@ -445,15 +456,15 @@ } protected void addUrl(HttpServletRequest request, User user) { - String url = request.getParameter("url"); // url of the website + String link = request.getParameter("url"); // url of the website String name = request.getParameter("name"); Bookmark bookmark = null; if (name != null) { String tags = request.getParameter("tags"); // tags - bookmark = BookmarkActions.createBookmark(url, name, tags, user, null); + bookmark = BookmarkActions.createBookmark(link, name, tags, user, null); } else { String nameAndTags = request.getParameter("nameAndTags"); - bookmark = BookmarkActions.createBookmark(url, nameAndTags, user); + bookmark = BookmarkActions.createBookmark(link, nameAndTags, user); } if (bookmark != null) { WikittyProxy proxy = model.getProxy(); @@ -520,7 +531,6 @@ bookmarkActions.emptySearchline(); } request.setAttribute("bookmarkActions", bookmarkActions); - } protected BookmarkActions createBookmarkActions(HttpServletRequest request, List<Bookmark> bookList) { Modified: trunk/src/main/java/org/chorem/bow/OpenSearchActions.java =================================================================== --- trunk/src/main/java/org/chorem/bow/OpenSearchActions.java 2010-05-31 10:21:08 UTC (rev 44) +++ trunk/src/main/java/org/chorem/bow/OpenSearchActions.java 2010-05-31 13:54:19 UTC (rev 45) @@ -26,28 +26,20 @@ public void findSuggestions(List<String> searchLine) { int size = searchLine.size(); search = searchLine.toArray(new String[size]); - if (!bookmarkList.isEmpty()) { - int i; - for (i = 0; i < (search.length - 1); ++i) { - List<Bookmark> newList = new ArrayList<Bookmark>(bookmarkList); - for (Bookmark bookmark : newList) { - if (!bookmarkHasTag(bookmark, search[i])) { - bookmarkList.remove(bookmark); - } - } - } - fieldSuggestionList(search[i], searchLine); - } + fieldSuggestionList(search[size - 1], searchLine); } protected void fieldSuggestionList(String word, List<String> searchLine) { if (bookmarkList != null) { Map<String, Integer> map = new HashMap<String, Integer>(); - for (Bookmark bookmark : bookmarkList) { + List<Bookmark> save = new ArrayList<Bookmark>(bookmarkList); + for (Bookmark bookmark : save) { Set<String> tagList = bookmark.getTags(); + boolean contain = false; if (tagList != null) { for (String tag : tagList) { if (tag.indexOf(word) == 0 && !searchLine.contains(tag)) { + contain = true; if (map.containsKey(tag)) { Integer count = map.get(tag); ++count; @@ -58,6 +50,9 @@ } } } + if (contain == false) { + bookmarkList.remove(bookmark); + } } Set<String> keys = map.keySet(); for (String key : keys) { @@ -114,6 +109,11 @@ str += ","; } } + if (bookmarkList.size() <= 5 && suggestions.size() > 0) { + for (Bookmark bookmark : bookmarkList) { + str += ",\"" + bookmark.getLink() + "\""; + } + } str += "]"; return str; }
participants (1)
-
bbrossaudï¼ users.chorem.org