Exemple #1
0
  /**
   * Perform the search
   *
   * @return a list of page names that match the search criteria
   */
  public SearchList search() {

    if (searchResults == null && errorMessage == null) {
      if (search != null && search.trim().length() > 0) {

        List<String> l = getSearchSites(getToolPropertySiteIds());
        long start = System.currentTimeMillis();
        int searchStart = requestPage * pagesize;
        int searchEnd = searchStart + pagesize;
        try {
          searchResults =
              searchService.search(search, l, searchStart, searchEnd, filterName, sortName);
          if (searchResults != null && searchResults.size() < 3) {
            if ((searchResults.size() > 0 && searchResults.get(0).getScore() < 1)) {
              log.debug("closest match: " + searchResults.get(0).getScore());
              String sug = searchService.getSearchSuggestion(search);
              log.debug("got suggestion: " + sug);
              this.searchTermSuggestion = sug;
            } else if (searchResults.size() == 0) {
              log.debug("No hits getting suggestion");
              String sug = searchService.getSearchSuggestion(search);
              log.debug("got suggestion: " + sug);
              this.searchTermSuggestion = sug;
            }
          } else if (searchResults == null || searchResults.size() == 0) {
            log.debug("No hits getting suggestion");
            String sug = searchService.getSearchSuggestion(search);
            log.debug("got suggestion: " + sug);
            this.searchTermSuggestion = sug;
          }
        } catch (Exception ex) {
          ex.printStackTrace();
          errorMessage = ex.getMessage();
          log.warn(
              "Search Error encoutered, generated by a user action "
                  + ex.getClass().getName()
                  + ":"
                  + ex.getMessage());
          log.debug("Search Error Traceback ", ex);
        }
        long end = System.currentTimeMillis();
        timeTaken = 0.001 * (end - start);
      }
    }

    return searchResults;
  }
Exemple #2
0
 public boolean hasResults() {
   SearchList sr = (SearchList) search();
   if (sr == null) {
     return false;
   } else {
     return (sr.size() > 0);
   }
 }
Exemple #3
0
 /*
  * (non-Javadoc)
  *
  * @see org.sakaiproject.search.tool.SearchBean#getSearchFound()
  */
 public String getSearchFound() {
   SearchList sr = (SearchList) search();
   if (sr == null) return "";
   int total = sr.getFullSize();
   int start = 0;
   int end = 0;
   if (total > 0) {
     start = sr.getStart();
     end = Math.min(start + sr.size(), total);
     start++;
   }
   return MessageFormat.format(
       Messages.getString("jsp_found_line"),
       new Object[] {
         Integer.valueOf(start),
         Integer.valueOf(end),
         Integer.valueOf(total),
         Double.valueOf(timeTaken)
       });
 }