示例#1
0
  /**
   * Get the recently submitted items for the given community or collection.
   *
   * @param scope The collection.
   */
  protected DiscoverResult getQueryResponse(DSpaceObject scope) {

    Request request = ObjectModelHelper.getRequest(objectModel);

    if (queryResults != null) {
      return queryResults;
    }

    queryArgs = new DiscoverQuery();

    // Make sure we add our default filters
    // queryArgs.addFilterQueries(SearchUtils.getDefaultFilters("browse"));

    queryArgs.setQuery(
        "search.resourcetype: "
            + Constants.ITEM
            + ((request.getParameter("query") != null && !"".equals(request.getParameter("query")))
                ? " AND (" + request.getParameter("query") + ")"
                : ""));
    //        queryArgs.setQuery("search.resourcetype:" + Constants.ITEM);

    queryArgs.setMaxResults(0);

    //        TODO: change this !
    queryArgs.setSortField(
        ConfigurationManager.getProperty("recent.submissions.sort-option"),
        DiscoverQuery.SORT_ORDER.asc);
    queryArgs.addFilterQueries(getParameterFacetQueries());

    // Set the default limit to 11
    // query.setFacetLimit(11);
    queryArgs.setFacetMinCount(1);

    // sort
    // TODO: why this kind of sorting ? Should the sort not be on how many times the value appears
    // like we do in the filter by sidebar ?
    //        queryArgs.setFacetSort(config.getPropertyAsType("solr.browse.sort","lex"));

    //        queryArgs.setFacet(true);

    int offset = RequestUtils.getIntParameter(request, OFFSET);
    if (offset == -1) {
      offset = 0;
    }
    queryArgs.setFacetOffset(offset);

    // We add +1 so we can use the extra one to make sure that we need to show the next page
    // queryArgs.setFacetLimit(DEFAULT_PAGE_SIZE + 1);

    // queryArgs.addFacetField(new DiscoverFacetField(request.getParameter(FACET_FIELD)));

    try {
      queryResults = searchService.search(context, scope, queryArgs);
    } catch (SearchServiceException e) {
      log.error(e.getMessage(), e);
    }

    return queryResults;
  }
  /**
   * Get the query parameters supplied to the browse.
   *
   * @return
   * @throws SQLException
   * @throws UIException
   */
  private BrowseParams getUserParams() throws SQLException, UIException {
    if (this.userParams != null) return this.userParams;

    Context context = ContextUtil.obtainContext(objectModel);
    Request request = ObjectModelHelper.getRequest(objectModel);

    BrowseParams params = new BrowseParams();

    params.month = request.getParameter(BrowseParams.MONTH);
    params.year = request.getParameter(BrowseParams.YEAR);
    params.etAl = RequestUtils.getIntParameter(request, BrowseParams.ETAL);

    params.scope = new BrowserScope(context);

    // Are we in a community or collection?
    DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
    if (dso instanceof Community) params.scope.setCommunity((Community) dso);
    if (dso instanceof Collection) params.scope.setCollection((Collection) dso);

    try {
      String type = request.getParameter(BrowseParams.TYPE);
      int sortBy = RequestUtils.getIntParameter(request, BrowseParams.SORT_BY);

      BrowseIndex bi = BrowseIndex.getBrowseIndex(type);
      if (bi == null) {
        throw new BrowseException("There is no browse index of the type: " + type);
      }

      // If we don't have a sort column
      if (sortBy == -1) {
        // Get the default one
        SortOption so = bi.getSortOption();
        if (so != null) {
          sortBy = so.getNumber();
        }
      } else if (bi.isItemIndex() && !bi.isInternalIndex()) {
        // If a default sort option is specified by the index, but it isn't
        // the same as sort option requested, attempt to find an index that
        // is configured to use that sort by default
        // This is so that we can then highlight the correct option in the navigation
        SortOption bso = bi.getSortOption();
        SortOption so = SortOption.getSortOption(sortBy);
        if (bso != null && bso != so) {
          BrowseIndex newBi = BrowseIndex.getBrowseIndex(so);
          if (newBi != null) {
            bi = newBi;
            type = bi.getName();
          }
        }
      }

      params.scope.setBrowseIndex(bi);
      params.scope.setSortBy(sortBy);

      params.scope.setJumpToItem(RequestUtils.getIntParameter(request, BrowseParams.JUMPTO_ITEM));
      params.scope.setOrder(request.getParameter(BrowseParams.ORDER));
      params.scope.setResultsPerPage(
          RequestUtils.getIntParameter(request, BrowseParams.RESULTS_PER_PAGE));
      params.scope.setStartsWith(request.getParameter(BrowseParams.STARTS_WITH));
      params.scope.setFilterValue(request.getParameter(BrowseParams.FILTER_VALUE));
      params.scope.setJumpToValue(request.getParameter(BrowseParams.JUMPTO_VALUE));
      params.scope.setJumpToValueLang(request.getParameter(BrowseParams.JUMPTO_VALUE_LANG));
      params.scope.setFilterValueLang(request.getParameter(BrowseParams.FILTER_VALUE_LANG));

      // Filtering to a value implies this is a second level browse
      if (params.scope.getFilterValue() != null) params.scope.setBrowseLevel(1);

      // if year and perhaps month have been selected, we translate these
      // into "startsWith"
      // if startsWith has already been defined then it is overwritten
      if (params.year != null && !"".equals(params.year) && !"-1".equals(params.year)) {
        String startsWith = params.year;
        if ((params.month != null) && !"-1".equals(params.month) && !"".equals(params.month)) {
          // subtract 1 from the month, so the match works
          // appropriately
          if ("ASC".equals(params.scope.getOrder())) {
            params.month = Integer.toString((Integer.parseInt(params.month) - 1));
          }

          // They've selected a month as well
          if (params.month.length() == 1) {
            // Ensure double-digit month number
            params.month = "0" + params.month;
          }

          startsWith = params.year + "-" + params.month;
        }

        params.scope.setStartsWith(startsWith);
      }
    } catch (BrowseException bex) {
      throw new UIException("Unable to create browse parameters", bex);
    }

    this.userParams = params;
    return params;
  }