示例#1
0
  // returns recently changed items, checking for accessibility
  private Item[] getItems(Context context, DSpaceObject dso) throws IOException, SQLException {
    try {
      // new method of doing the browse:
      String idx = ConfigurationManager.getProperty("recent.submissions.sort-option");
      if (idx == null) {
        throw new IOException(
            "There is no configuration supplied for: recent.submissions.sort-option");
      }
      BrowseIndex bix = BrowseIndex.getItemBrowseIndex();
      if (bix == null) {
        throw new IOException("There is no browse index with the name: " + idx);
      }

      BrowserScope scope = new BrowserScope(context);
      scope.setBrowseIndex(bix);
      if (dso != null) {
        scope.setBrowseContainer(dso);
      }

      for (SortOption so : SortOption.getSortOptions()) {
        if (so.getName().equals(idx)) {
          scope.setSortBy(so.getNumber());
        }
      }
      scope.setOrder(SortOption.DESCENDING);
      scope.setResultsPerPage(itemCount);

      // gather & add items to the feed.
      BrowseEngine be = new BrowseEngine(context);
      BrowseInfo bi = be.browseMini(scope);
      Item[] results = bi.getItemResults(context);

      if (includeAll) {
        return results;
      } else {
        // Check to see if we can include this item
        // Group[] authorizedGroups = AuthorizeManager.getAuthorizedGroups(context, results[i],
        // Constants.READ);
        // boolean added = false;
        List<Item> items = new ArrayList<Item>();
        for (Item result : results) {
          checkAccess:
          for (Group group :
              AuthorizeManager.getAuthorizedGroups(context, result, Constants.READ)) {
            if ((group.getID() == Group.ANONYMOUS_ID)) {
              items.add(result);
              break checkAccess;
            }
          }
        }
        return items.toArray(new Item[items.size()]);
      }
    } catch (SortException se) {
      log.error("caught exception: ", se);
      throw new IOException(se.getMessage(), se);
    } catch (BrowseException e) {
      log.error("caught exception: ", e);
      throw new IOException(e.getMessage(), e);
    }
  }
示例#2
0
  /**
   * Convert the value into an offset into the table for this browse
   *
   * @return the focus value to use
   * @throws BrowseException
   */
  private int getOffsetForValue(String value) throws BrowseException {
    // get the table name.  We don't really need to care about whether we are in a
    // community or collection at this point.  This is only for full or second
    // level browse, so there is no need to worry about distinct value browsing
    String tableName = browseIndex.getTableName();

    // we need to make sure that we select from the correct column.  If the sort option
    // is the 0th option then we use sort_value, but if it is one of the others we have
    // to select from that column instead.  Otherwise, we end up missing the focus value
    // to do comparisons in other columns.  The use of the focus value needs to be consistent
    // across the browse
    SortOption so = scope.getSortOption();
    if (so == null || so.getNumber() == 0) {
      if (browseIndex.getSortOption() != null) so = browseIndex.getSortOption();
    }

    String col = "sort_1";
    if (so.getNumber() > 0) {
      col = "sort_" + Integer.toString(so.getNumber());
    }

    // now get the DAO to do the query for us, returning the highest
    // string value in the given column in the given table for the
    // item (I think)
    return dao.doOffsetQuery(col, value, scope.isAscending());
  }
示例#3
0
  /**
   * Get the defined sort option by number (.1, .2, etc).
   *
   * @param number the number of the sort option as given in the config file
   * @return the configured sort option with given number
   * @throws SortException if sort error
   */
  public static SortOption getSortOption(int number) throws SortException {
    for (SortOption so : SortOption.getSortOptions()) {
      if (so.getNumber() == number) {
        return so;
      }
    }

    return null;
  }
示例#4
0
  /**
   * Return the focus value.
   *
   * @return the focus value to use
   * @throws BrowseException
   */
  private String getJumpToValue() throws BrowseException {
    log.debug(LogManager.getHeader(context, "get_focus_value", ""));

    // if the focus is by value, just return it
    if (scope.hasJumpToValue()) {
      log.debug(
          LogManager.getHeader(
              context, "get_focus_value_return", "return=" + scope.getJumpToValue()));
      return scope.getJumpToValue();
    }

    // if the focus is to start with, then we need to return the value of the starts with
    if (scope.hasStartsWith()) {
      log.debug(
          LogManager.getHeader(
              context, "get_focus_value_return", "return=" + scope.getStartsWith()));
      return scope.getStartsWith();
    }

    // since the focus is not by value, we need to obtain it

    // get the id of the item to focus on
    int id = scope.getJumpToItem();

    // get the table name.  We don't really need to care about whether we are in a
    // community or collection at this point.  This is only for full or second
    // level browse, so there is no need to worry about distinct value browsing
    String tableName = browseIndex.getTableName();

    // we need to make sure that we select from the correct column.  If the sort option
    // is the 0th option then we use sort_value, but if it is one of the others we have
    // to select from that column instead.  Otherwise, we end up missing the focus value
    // to do comparisons in other columns.  The use of the focus value needs to be consistent
    // across the browse
    SortOption so = scope.getSortOption();
    if (so == null || so.getNumber() == 0) {
      if (browseIndex.getSortOption() != null) {
        so = browseIndex.getSortOption();
      }
    }

    String col = "sort_1";
    if (so.getNumber() > 0) {
      col = "sort_" + Integer.toString(so.getNumber());
    }

    // now get the DAO to do the query for us, returning the highest
    // string value in the given column in the given table for the
    // item (I think)
    String max = dao.doMaxQuery(col, tableName, id);

    log.debug(LogManager.getHeader(context, "get_focus_value_return", "return=" + max));

    return max;
  }
示例#5
0
  /**
   * Convert the value into an offset into the table for this browse
   *
   * @return the focus value to use
   * @throws BrowseException
   */
  private int getOffsetForValue(String value) throws BrowseException {
    // we need to make sure that we select from the correct column.  If the sort option
    // is the 0th option then we use sort_value, but if it is one of the others we have
    // to select from that column instead.  Otherwise, we end up missing the focus value
    // to do comparisons in other columns.  The use of the focus value needs to be consistent
    // across the browse
    SortOption so = scope.getSortOption();
    if (so == null || so.getNumber() == 0) {
      if (browseIndex.getSortOption() != null) {
        so = browseIndex.getSortOption();
      }
    }

    String col = "sort_1";
    if (so.getNumber() > 0) {
      col = "sort_" + Integer.toString(so.getNumber());
    }

    // now get the DAO to do the query for us, returning the highest
    // string value in the given column in the given table for the
    // item (I think)
    return dao.doOffsetQuery(col, value, scope.isAscending());
  }
示例#6
0
  protected void buildSearchControls(Division div) throws WingException {
    Table controlsTable = div.addTable("search-controls", 1, 3);
    Row controlsRow = controlsTable.addRow(Row.ROLE_DATA);

    // Create a control for the number of records to display
    Cell rppCell = controlsRow.addCell();
    rppCell.addContent(T_rpp);
    Select rppSelect = rppCell.addSelect("rpp");
    for (int i : RESULTS_PER_PAGE_PROGRESSION) {
      rppSelect.addOption((i == getParameterRpp()), i, Integer.toString(i));
    }

    Cell sortCell = controlsRow.addCell();
    try {
      // Create a drop down of the different sort columns available
      sortCell.addContent(T_sort_by);
      Select sortSelect = sortCell.addSelect("sort_by");
      sortSelect.addOption(false, 0, T_sort_by_relevance);
      for (SortOption so : SortOption.getSortOptions()) {
        if (so.isVisible()) {
          sortSelect.addOption(
              (so.getNumber() == getParameterSortBy()),
              so.getNumber(),
              message("xmlui.ArtifactBrowser.AbstractSearch.sort_by." + so.getName()));
        }
      }
    } catch (SortException se) {
      throw new WingException("Unable to get sort options", se);
    }

    // Create a control to changing ascending / descending order
    Cell orderCell = controlsRow.addCell();
    orderCell.addContent(T_order);
    Select orderSelect = orderCell.addSelect("order");
    orderSelect.addOption(
        SortOption.ASCENDING.equals(getParameterOrder()), SortOption.ASCENDING, T_order_asc);
    orderSelect.addOption(
        SortOption.DESCENDING.equals(getParameterOrder()), SortOption.DESCENDING, T_order_desc);

    // Create a control for the number of authors per item to display
    // FIXME This is currently disabled, as the supporting functionality
    // is not currently present in xmlui
    // if (isItemBrowse(info))
    // {
    //    controlsForm.addContent(T_etal);
    //    Select etalSelect = controlsForm.addSelect(BrowseParams.ETAL);
    //
    //    etalSelect.addOption((info.getEtAl() < 0), 0, T_etal_all);
    //    etalSelect.addOption(1 == info.getEtAl(), 1, Integer.toString(1));
    //
    //    for (int i = 5; i <= 50; i += 5)
    //    {
    //        etalSelect.addOption(i == info.getEtAl(), i, Integer.toString(i));
    //    }
    // }
  }
示例#7
0
  /**
   * Query DSpace for a list of all items / collections / or communities that match the given search
   * query.
   */
  protected void performSearch() throws SQLException, IOException, UIException {
    if (queryResults != null) {
      return;
    }

    Context context = ContextUtil.obtainContext(objectModel);
    String query = getQuery();
    DSpaceObject scope = getScope();
    int page = getParameterPage();

    queryArgs = new QueryArgs();
    queryArgs.setPageSize(getParameterRpp());
    try {
      queryArgs.setSortOption(SortOption.getSortOption(getParameterSortBy()));
    } catch (SortException se) {
    }

    queryArgs.setSortOrder(getParameterOrder());

    queryArgs.setQuery(query);
    if (page > 1) {
      queryArgs.setStart((Integer.valueOf(page) - 1) * queryArgs.getPageSize());
    } else {
      queryArgs.setStart(0);
    }

    QueryResults qResults = null;
    if (scope instanceof Community) {
      qResults = DSQuery.doQuery(context, queryArgs, (Community) scope);
    } else if (scope instanceof Collection) {
      qResults = DSQuery.doQuery(context, queryArgs, (Collection) scope);
    } else {
      qResults = DSQuery.doQuery(context, queryArgs);
    }

    this.queryResults = qResults;
  }
示例#8
0
  /**
   * Utility method for obtaining a string representation of the browse. This is useful only for
   * debug
   */
  public String toString() {
    try {
      StringBuffer sb = new StringBuffer();

      // calculate the range for display
      String from = Integer.toString(overallPosition + 1);
      String to = Integer.toString(overallPosition + results.size());
      String of = Integer.toString(total);

      // report on the positional information of the browse
      sb.append("BrowseInfo String Representation: ");
      sb.append("Browsing " + from + " to " + to + " of " + of + " ");

      // insert the information about which index
      sb.append(
          "in index: "
              + browseIndex.getName()
              + " (data type: "
              + browseIndex.getDataType()
              + ", display type: "
              + browseIndex.getDisplayType()
              + ") ");

      sb.append("||");

      // report on the browse scope container
      String container = "all of DSpace";
      DSpaceObject theContainer = null;
      if (inCollection()) {
        container = "collection";
        theContainer = this.collection;
      } else if (inCommunity()) {
        container = "community";
        theContainer = this.community;
      }

      String containerID = "no id available/necessary";
      if (theContainer != null) {
        containerID =
            Integer.toString(theContainer.getID()) + " (" + theContainer.getHandle() + ")";
      }

      sb.append("Browsing in " + container + ": " + containerID);
      sb.append("||");

      // load the item list display configuration
      ItemListConfig config = new ItemListConfig();

      // some information about the columns to be displayed
      if (browseIndex.isItemIndex()) {
        sb.append("Listing over " + Integer.toString(config.numCols()) + " columns: ");
        for (int k = 1; k <= config.numCols(); k++) {
          if (k > 1) {
            sb.append(",");
          }
          String[] meta = config.getMetadata(k);
          sb.append(meta[0] + "." + meta[1] + "." + meta[2]);
        }

        if (value != null) {
          sb.append(" on value: ").append(value);
        }

        if (isStartsWith()) {
          sb.append(" sort column starting with: ").append(focus);
        } else if (hasFocus()) {
          sb.append(" sort column focus: ").append(focus);
        }
      } else if (browseIndex.isMetadataIndex()) {
        sb.append("Listing single column: ").append(browseIndex.getMetadata());
        if (isStartsWith()) {
          sb.append(" sort column starting with: ").append(focus);
        } else if (hasFocus()) {
          sb.append(" sort column focus: ").append(focus);
        }
      }

      sb.append("||");

      // some information about how the data is sorted
      String direction = (ascending ? "ASC" : "DESC");
      sb.append(
          "Sorting by: "
              + sortOption.getMetadata()
              + " "
              + direction
              + " (option "
              + Integer.toString(sortOption.getNumber())
              + ")");
      sb.append("||");

      // output the results
      if (browseIndex.isMetadataIndex() && !isSecondLevel()) {
        sb.append(valueListingString());
      } else if (browseIndex.isItemIndex() || isSecondLevel()) {
        sb.append(fullListingString(config));
      }

      sb.append("||");

      // tell us what the next and previous values are going to be
      sb.append("Top of next page: ");
      if (hasNextPage()) {
        sb.append("offset: ").append(Integer.toString(this.nextOffset));
      } else {
        sb.append("n/a");
      }
      sb.append(";");

      sb.append("Top of previous page: ");
      if (hasPrevPage()) {
        sb.append("offset: ").append(Integer.toString(this.prevOffset));
      } else {
        sb.append("n/a");
      }

      sb.append("||");

      return sb.toString();
    } catch (SQLException e) {
      return e.getMessage();
    } catch (BrowseException e) {
      return e.getMessage();
    }
  }
  protected void doDSGet(Context context, HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException, SQLException, AuthorizeException {
    // dispense with simple service document requests
    String scope = request.getParameter("scope");
    if (scope != null && "".equals(scope)) {
      scope = null;
    }
    String path = request.getPathInfo();
    if (path != null && path.endsWith("description.xml")) {
      String svcDescrip = OpenSearch.getDescription(scope);
      response.setContentType(OpenSearch.getContentType("opensearchdescription"));
      response.setContentLength(svcDescrip.length());
      response.getWriter().write(svcDescrip);
      return;
    }

    // get enough request parameters to decide on action to take
    String format = request.getParameter("format");
    if (format == null || "".equals(format)) {
      // default to atom
      format = "atom";
    }

    // do some sanity checking
    if (!OpenSearch.getFormats().contains(format)) {
      response.sendError(HttpServletResponse.SC_BAD_REQUEST);
      return;
    }

    // then the rest - we are processing the query
    String query = request.getParameter("query");
    int start = Util.getIntParameter(request, "start");
    int rpp = Util.getIntParameter(request, "rpp");
    int sort = Util.getIntParameter(request, "sort_by");
    String order = request.getParameter("order");
    String sortOrder =
        (order == null || order.length() == 0 || order.toLowerCase().startsWith("asc"))
            ? SortOption.ASCENDING
            : SortOption.DESCENDING;

    QueryArgs qArgs = new QueryArgs();
    // can't start earlier than 0 in the results!
    if (start < 0) {
      start = 0;
    }
    qArgs.setStart(start);

    if (rpp > 0) {
      qArgs.setPageSize(rpp);
    }
    qArgs.setSortOrder(sortOrder);

    if (sort > 0) {
      try {
        qArgs.setSortOption(SortOption.getSortOption(sort));
      } catch (Exception e) {
        // invalid sort id - do nothing
      }
    }
    qArgs.setSortOrder(sortOrder);

    // Ensure the query is non-null
    if (query == null) {
      query = "";
    }

    // If there is a scope parameter, attempt to dereference it
    // failure will only result in its being ignored
    DSpaceObject container = (scope != null) ? HandleManager.resolveToObject(context, scope) : null;

    // Build log information
    String logInfo = "";

    // get the start of the query results page
    qArgs.setQuery(query);

    // Perform the search
    QueryResults qResults = null;
    if (container == null) {
      qResults = DSQuery.doQuery(context, qArgs);
    } else if (container instanceof Collection) {
      logInfo = "collection_id=" + container.getID() + ",";
      qResults = DSQuery.doQuery(context, qArgs, (Collection) container);
    } else if (container instanceof Community) {
      logInfo = "community_id=" + container.getID() + ",";
      qResults = DSQuery.doQuery(context, qArgs, (Community) container);
    }

    // now instantiate the results
    DSpaceObject[] results = new DSpaceObject[qResults.getHitHandles().size()];
    for (int i = 0; i < qResults.getHitHandles().size(); i++) {
      String myHandle = (String) qResults.getHitHandles().get(i);
      DSpaceObject dso = HandleManager.resolveToObject(context, myHandle);
      if (dso == null) {
        throw new SQLException("Query \"" + query + "\" returned unresolvable handle: " + myHandle);
      }
      results[i] = dso;
    }

    // Log
    log.info(
        LogManager.getHeader(
            context,
            "search",
            logInfo + "query=\"" + query + "\",results=(" + results.length + ")"));

    // format and return results
    Map<String, String> labelMap = getLabels(request);
    Document resultsDoc =
        OpenSearch.getResultsDoc(format, query, qResults, container, results, labelMap);
    try {
      Transformer xf = TransformerFactory.newInstance().newTransformer();
      response.setContentType(OpenSearch.getContentType(format));
      xf.transform(new DOMSource(resultsDoc), new StreamResult(response.getWriter()));
    } catch (TransformerException e) {
      log.error(e);
      throw new ServletException(e.toString());
    }
  }
  protected void doDSGet(Context context, HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException, SQLException, AuthorizeException {
    // Get the query
    String query = request.getParameter("query");
    int start = UIUtil.getIntParameter(request, "start");
    String advanced = request.getParameter("advanced");
    String fromAdvanced = request.getParameter("from_advanced");
    int sortBy = UIUtil.getIntParameter(request, "sort_by");
    String order = request.getParameter("order");
    int rpp = UIUtil.getIntParameter(request, "rpp");
    String advancedQuery = "";
    HashMap queryHash = new HashMap();

    // can't start earlier than 0 in the results!
    if (start < 0) {
      start = 0;
    }

    int collCount = 0;
    int commCount = 0;
    int itemCount = 0;

    Item[] resultsItems;
    Collection[] resultsCollections;
    Community[] resultsCommunities;

    QueryResults qResults = null;
    QueryArgs qArgs = new QueryArgs();
    SortOption sortOption = null;

    if (request.getParameter("etal") != null)
      qArgs.setEtAl(UIUtil.getIntParameter(request, "etal"));

    try {
      if (sortBy > 0) {
        sortOption = SortOption.getSortOption(sortBy);
        qArgs.setSortOption(sortOption);
      }

      if (SortOption.ASCENDING.equalsIgnoreCase(order)) {
        qArgs.setSortOrder(SortOption.ASCENDING);
      } else {
        qArgs.setSortOrder(SortOption.DESCENDING);
      }
    } catch (Exception e) {
    }

    if (rpp > 0) {
      qArgs.setPageSize(rpp);
    }

    // if the "advanced" flag is set, build the query string from the
    // multiple query fields
    if (advanced != null) {
      query = qArgs.buildQuery(request);
      advancedQuery = qArgs.buildHTTPQuery(request);
    }

    // Ensure the query is non-null
    if (query == null) {
      query = "";
    }

    // Get the location parameter, if any
    String location = request.getParameter("location");
    String newURL;

    // If there is a location parameter, we should redirect to
    // do the search with the correct location.
    if ((location != null) && !location.equals("")) {
      String url = "";

      if (!location.equals("/")) {
        // Location points to a resource
        url = "/resource/" + location;
      }

      // Encode the query
      query = URLEncoder.encode(query, Constants.DEFAULT_ENCODING);

      if (advancedQuery.length() > 0) {
        query = query + "&from_advanced=true&" + advancedQuery;
      }

      // Do the redirect
      response.sendRedirect(
          response.encodeRedirectURL(
              request.getContextPath() + url + "/simple-search?query=" + query));

      return;
    }

    // Build log information
    String logInfo = "";

    // Get our location
    Community community = UIUtil.getCommunityLocation(request);
    Collection collection = UIUtil.getCollectionLocation(request);

    // get the start of the query results page
    //        List resultObjects = null;
    qArgs.setQuery(query);
    qArgs.setStart(start);

    // Perform the search
    if (collection != null) {
      logInfo = "collection_id=" + collection.getID() + ",";

      // Values for drop-down box
      request.setAttribute("community", community);
      request.setAttribute("collection", collection);

      qResults = DSQuery.doQuery(context, qArgs, collection);
    } else if (community != null) {
      logInfo = "community_id=" + community.getID() + ",";

      request.setAttribute("community", community);

      // Get the collections within the community for the dropdown box
      request.setAttribute("collection.array", community.getCollections());

      qResults = DSQuery.doQuery(context, qArgs, community);
    } else {
      // Get all communities for dropdown box
      //            Community[] communities = Community.findAll(context);
      Community[] communities =
          (Community[]) ApplicationService.findAllCommunities(context).toArray();
      request.setAttribute("community.array", communities);

      qResults = DSQuery.doQuery(context, qArgs);
    }

    // now instantiate the results and put them in their buckets
    for (int i = 0; i < qResults.getHitTypes().size(); i++) {
      String myURI = (String) qResults.getHitURIs().get(i);
      Integer myType = (Integer) qResults.getHitTypes().get(i);

      // add the URI to the appropriate lists
      switch (myType.intValue()) {
        case Constants.ITEM:
          itemCount++;
          break;

        case Constants.COLLECTION:
          collCount++;
          break;

        case Constants.COMMUNITY:
          commCount++;
          break;
      }
    }

    // Make objects from the URIs - make arrays, fill them out
    resultsCommunities = new Community[commCount];
    resultsCollections = new Collection[collCount];
    resultsItems = new Item[itemCount];

    for (int i = 0; i < qResults.getHitTypes().size(); i++) {
      Integer myId = (Integer) qResults.getHitIds().get(i);
      String myURI = (String) qResults.getHitURIs().get(i);
      Integer myType = (Integer) qResults.getHitTypes().get(i);

      switch (myType.intValue()) {
        case Constants.ITEM:
          if (myId != null) {
            //                    resultsItems[itemCount] = Item.find(context, myId);
            resultsItems[itemCount] = ApplicationService.get(context, Item.class, myId);
          } else {
            ObjectIdentifier oi = ObjectIdentifier.parseCanonicalForm(myURI);
            resultsItems[itemCount] = (Item) oi.getObject(context);
          }

          if (resultsItems[itemCount] == null) {
            throw new SQLException("Query \"" + query + "\" returned unresolvable item");
          }
          itemCount++;
          break;

        case Constants.COLLECTION:
          if (myId != null) {
            //                    resultsCollections[collCount] = Collection.find(context, myId);
            resultsCollections[collCount] = ApplicationService.get(context, Collection.class, myId);
          } else {
            ObjectIdentifier oi = ObjectIdentifier.parseCanonicalForm(myURI);
            resultsCollections[collCount] = (Collection) oi.getObject(context);
          }

          if (resultsCollections[collCount] == null) {
            throw new SQLException("Query \"" + query + "\" returned unresolvable collection");
          }

          collCount++;
          break;

        case Constants.COMMUNITY:
          if (myId != null) {
            //                    resultsCommunities[commCount] = Community.find(context, myId);
            resultsCommunities[commCount] = ApplicationService.get(context, Community.class, myId);
          } else {
            ObjectIdentifier oi = ObjectIdentifier.parseCanonicalForm(myURI);
            resultsCommunities[commCount] = (Community) oi.getObject(context);
          }

          if (resultsCommunities[commCount] == null) {
            throw new SQLException("Query \"" + query + "\" returned unresolvable community");
          }

          commCount++;
          break;
      }
    }

    // Log
    log.info(
        LogManager.getHeader(
            context,
            "search",
            logInfo
                + "query=\""
                + query
                + "\",results=("
                + resultsCommunities.length
                + ","
                + resultsCollections.length
                + ","
                + resultsItems.length
                + ")"));

    // Pass in some page qualities
    // total number of pages
    int pageTotal = 1 + ((qResults.getHitCount() - 1) / qResults.getPageSize());

    // current page being displayed
    int pageCurrent = 1 + (qResults.getStart() / qResults.getPageSize());

    // pageLast = min(pageCurrent+9,pageTotal)
    int pageLast = ((pageCurrent + 9) > pageTotal) ? pageTotal : (pageCurrent + 9);

    // pageFirst = max(1,pageCurrent-9)
    int pageFirst = ((pageCurrent - 9) > 1) ? (pageCurrent - 9) : 1;

    // Pass the results to the display JSP
    request.setAttribute("items", resultsItems);
    request.setAttribute("communities", resultsCommunities);
    request.setAttribute("collections", resultsCollections);

    request.setAttribute("pagetotal", new Integer(pageTotal));
    request.setAttribute("pagecurrent", new Integer(pageCurrent));
    request.setAttribute("pagelast", new Integer(pageLast));
    request.setAttribute("pagefirst", new Integer(pageFirst));

    request.setAttribute("queryresults", qResults);

    // And the original query string
    request.setAttribute("query", query);

    request.setAttribute("order", qArgs.getSortOrder());
    request.setAttribute("sortedBy", sortOption);

    if ((fromAdvanced != null) && (qResults.getHitCount() == 0)) {
      // send back to advanced form if no results
      Community[] communities =
          (Community[]) ApplicationService.findAllCommunities(context).toArray();
      //            Community[] communities = Community.findAll(context);
      request.setAttribute("communities", communities);
      request.setAttribute("no_results", "yes");

      queryHash = qArgs.buildQueryHash(request);

      Iterator i = queryHash.keySet().iterator();

      while (i.hasNext()) {
        String key = (String) i.next();
        String value = (String) queryHash.get(key);

        request.setAttribute(key, value);
      }

      JSPManager.showJSP(request, response, "/search/advanced.jsp");
    } else {
      JSPManager.showJSP(request, response, "/search/results.jsp");
    }
  }