示例#1
0
 public boolean hasResults() {
   SearchList sr = (SearchList) search();
   if (sr == null) {
     return false;
   } else {
     return (sr.size() > 0);
   }
 }
示例#2
0
  /*
   * (non-Javadoc)
   *
   * @see org.sakaiproject.search.tool.SearchBean#getPages()
   */
  public List<SearchPage> getPages() {
    List<SearchPage> pages = new ArrayList<SearchPage>();
    try {
      SearchList sr = (SearchList) search();
      if (sr == null) return pages;
      int npages = (sr.getFullSize() - 1) / pagesize;
      int cpage = requestPage - (nlistPages / 2);
      if (cpage < 0) {
        cpage = 0;
      }
      int lastPage = Math.min(cpage + nlistPages, npages);
      boolean first = true;
      if (cpage == lastPage) {
        return pages;
      } else {
        while (cpage <= lastPage) {
          final String searchURL =
              "?search="
                  + URLEncoder.encode(search, "UTF-8")
                  + "&page="
                  + String.valueOf(cpage)
                  + "&scope="
                  + this.scope;

          final String name = String.valueOf(cpage + 1);
          String cssInd = "1";
          if (first) {
            cssInd = "0";
            first = false;
          } else if (cpage == (lastPage)) {
            cssInd = "2";
          }
          pages.add(
              new SearchPage() {

                public String getName() {
                  return FormattedText.escapeHtml(name, false);
                }

                public String getUrl() {
                  return FormattedText.escapeHtml(searchURL, false);
                }
              });
          cpage++;
        }
      }

    } catch (Exception ex) {
      log.debug(ex);
    }
    return pages;
  }
示例#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)
       });
 }
示例#4
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;
  }
示例#5
0
  /*
   * (non-Javadoc)
   *
   * @see org.sakaiproject.search.tool.SearchBean#getResults()
   */
  @SuppressWarnings("unchecked")
  public List<SearchOutputItem> getResults() {
    if (outputItems == null) {

      outputItems = new ArrayList<SearchOutputItem>();
      SearchList sl = search();
      for (Iterator<SearchResult> i = sl.iterator(); i.hasNext(); ) {
        final SearchResult sr = (SearchResult) i.next();

        if (!sr.isCensored()) {
          outputItems.add(
              new SearchOutputItem() {

                public String getSearchResult() {
                  try {
                    return sr.getSearchResult();
                  } catch (Exception ex) {
                    return "";
                  }
                }

                public String getTitle() {
                  try {
                    return FormattedText.escapeHtml(sr.getTitle(), false);
                  } catch (Exception ex) {
                    return "";
                  }
                }

                public String getTool() {
                  try {
                    return FormattedText.escapeHtml(sr.getTool(), false);
                  } catch (Exception ex) {
                    return "";
                  }
                }

                public String getUrl() {
                  try {
                    return FormattedText.escapeHtml(sr.getUrl(), false);
                  } catch (Exception ex) {
                    return "";
                  }
                }

                private Site site = null;

                public String getSiteURL() {

                  if (site == null) site = getSite();

                  return (site != null) ? site.getUrl() : null;
                }

                public String getSiteTitle() {
                  if (site == null) site = getSite();

                  if (site != null) return FormattedText.escapeHtml(site.getTitle(), false);

                  return "";
                }

                private Site getSite() {
                  try {
                    Site s = siteService.getSite(sr.getSiteId());
                    return s;
                  } catch (IdUnusedException e) {
                    log.warn(
                        "site: " + sr.getSiteId() + "referenced in search results doesn't exits");
                  }

                  return null;
                }

                public boolean isVisible() {
                  if (sr.isCensored()) return false;
                  else return true;
                }

                public boolean hasPortalUrl() {
                  return sr.hasPortalUrl();
                }
              });

        } else {
          censoredResults++;
        }
      }
    }

    return outputItems;
  }
示例#6
0
 /**
  * The Total number of results
  *
  * @return
  */
 public int getNresults() {
   return searchResults.getFullSize();
 }