Author: bbrossaud Date: 2010-06-01 12:02:53 +0200 (Tue, 01 Jun 2010) New Revision: 50 Url: http://chorem.org/repositories/revision/bow/50 Log: retrieve bookmarks by research thanks to criteria Modified: trunk/src/main/java/org/chorem/bow/BookmarkActions.java trunk/src/main/java/org/chorem/bow/ControllerServlet.java Modified: trunk/src/main/java/org/chorem/bow/BookmarkActions.java =================================================================== --- trunk/src/main/java/org/chorem/bow/BookmarkActions.java 2010-06-01 09:02:01 UTC (rev 49) +++ trunk/src/main/java/org/chorem/bow/BookmarkActions.java 2010-06-01 10:02:53 UTC (rev 50) @@ -251,7 +251,6 @@ public void createTagCloud() { tagCloud.clear(); - //deleteBookmarkBySearch(); createTagClougByBookmarks(); defineTValues(); } Modified: trunk/src/main/java/org/chorem/bow/ControllerServlet.java =================================================================== --- trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-06-01 09:02:01 UTC (rev 49) +++ trunk/src/main/java/org/chorem/bow/ControllerServlet.java 2010-06-01 10:02:53 UTC (rev 50) @@ -239,7 +239,7 @@ Criteria criteria = getBookmarkListCriteriaByUser(user, searchLine); criteria = criteria.addSortDescending(Bookmark.FQ_FIELD_CLICK); List<Bookmark> bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll(); - BookmarkActions bookmarkActions = createBookmarkActions(request, bookList); + BookmarkActions bookmarkActions = createBookmarkActions(request, bookList, searchLine); request.setAttribute("bookmarkActions", bookmarkActions); request.setAttribute("token", token); request.getRequestDispatcher("openSearchResult.jsp").forward(request, response); @@ -301,7 +301,7 @@ protected void actionOrderAsc(HttpServletRequest request, HttpServletResponse response, User user) throws IOException, ServletException { String type = request.getParameter("type"); - String searchLine = request.getParameter("searchline"); + String searchLine = request.getParameter("searchLine"); Criteria baseCriteria = getBookmarkListCriteriaByUser(user, searchLine); if (type != null && baseCriteria != null && !type.isEmpty()) { WikittyProxy proxy = model.getProxy(); @@ -316,14 +316,14 @@ Criteria criteria = baseCriteria.addSortAscending(Bookmark.FQ_FIELD_CLICK); bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll(); } - BookmarkActions bookmarkActions = createBookmarkActions(request, bookList); + BookmarkActions bookmarkActions = createBookmarkActions(request, bookList, searchLine); request.setAttribute("bookmarkActions", bookmarkActions); } } protected void actionOrderDesc(HttpServletRequest request, HttpServletResponse response, User user) throws IOException, ServletException { - String searchLine = request.getParameter("searchline"); + String searchLine = request.getParameter("searchLine"); String type = request.getParameter("type"); Criteria baseCriteria = getBookmarkListCriteriaByUser(user, searchLine); if (type != null && baseCriteria != null && !type.isEmpty()) { @@ -339,7 +339,7 @@ Criteria criteria = baseCriteria.addSortDescending(Bookmark.FQ_FIELD_CLICK); bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll(); } - BookmarkActions bookmarkActions = createBookmarkActions(request, bookList); + BookmarkActions bookmarkActions = createBookmarkActions(request, bookList, searchLine); request.setAttribute("bookmarkActions", bookmarkActions); } } @@ -499,17 +499,24 @@ protected void actionSearch(HttpServletRequest request, User user) throws IOException, ServletException { String searchLine = request.getParameter("searchLine"); + String tag = request.getParameter("addTag"); + if (tag != null && !tag.isEmpty()) { + if (searchLine == null || searchLine.isEmpty()) { + searchLine = tag; + } else { + searchLine += " " + tag; + } + } WikittyProxy proxy = model.getProxy(); Criteria criteria = getBookmarkListCriteriaByUser(user, searchLine); criteria = criteria.addSortDescending(Bookmark.FQ_FIELD_CLICK); List<Bookmark> bookList = proxy.findAllByCriteria(Bookmark.class, criteria).getAll(); // select all bookmarks by user - BookmarkActions bookmarkActions = createBookmarkActions(request, bookList); + BookmarkActions bookmarkActions = createBookmarkActions(request, bookList, searchLine); request.setAttribute("bookmarkActions", bookmarkActions); } - protected BookmarkActions createBookmarkActions(HttpServletRequest request, List<Bookmark> bookList) { + protected BookmarkActions createBookmarkActions(HttpServletRequest request, List<Bookmark> bookList, String searchLine) { String fullText = request.getParameter("fullTextLine"); - String searchLine = request.getParameter("searchLine"); // retrieve informations taping in the search field BookmarkActions bookmarkActions = new BookmarkActions(); if (bookList != null) { bookmarkActions.setBookmarks(bookList); @@ -523,10 +530,6 @@ bookmarkActions.emptySearchline(); } else { bookmarkActions.addTags(searchLine); // add the new tags - String tag = request.getParameter("addTag"); - if (tag != null && !tag.isEmpty()) { - bookmarkActions.addTag(tag); - } } bookmarkActions.createTagCloud(); // create the tags cloud with the new informations } @@ -650,7 +653,7 @@ List<Bookmark> bookList = proxy.findAllByCriteria(Bookmark.class, sortCriteria).getAll(); // select all bookmarks by user sortCriteria = criteria.addSortDescending(Bookmark.FQ_FIELD_DATE).setEndIndex(10); List<Bookmark> lastBookmarks = proxy.findAllByCriteria(Bookmark.class, sortCriteria).getAll(); - BookmarkActions bookmarkActions = createBookmarkActions(request, bookList); + BookmarkActions bookmarkActions = createBookmarkActions(request, bookList, null); bookList = bookmarkActions.getBookmarks(); if (bookList.size() > 10) { bookList = bookmarkActions.getBookmarks().subList(0, 10); @@ -769,7 +772,7 @@ 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(); - BookmarkActions bookmarkActions = createBookmarkActions(request, bookList); + BookmarkActions bookmarkActions = createBookmarkActions(request, bookList, null); request.setAttribute("bookmarkActions", bookmarkActions); } @@ -787,16 +790,16 @@ } } - protected Criteria getBookmarkListCriteriaByUser(User user, String searchline) { + protected Criteria getBookmarkListCriteriaByUser(User user, String searchLine) { Criteria criteria = null; if (user != null) { - if (searchline != null && !searchline.isEmpty()) { - String[] words = searchline.split("\\s+"); // put the tags in an array + if (searchLine != null && !searchLine.isEmpty()) { + String[] words = searchLine.split("\\s+"); // put the tags in an array List<String> tags = new ArrayList<String>(Arrays.asList(words)); - criteria = Search.query().eq(User.FQ_FIELD_EMAIL, user.getEmail()). - contains(Bookmark.FQ_FIELD_TAGS, tags).criteria(); + log.debug(tags.size()); + criteria = Search.query().eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).eq(Bookmark.FQ_FIELD_TAGS, tags).criteria(); } else { - criteria = Search.query().eq(User.FQ_FIELD_EMAIL, user.getEmail()).criteria(); + criteria = Search.query().eq(Bookmark.FQ_FIELD_EMAIL, user.getEmail()).criteria(); } } return criteria;