Exemplo n.º 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;
  }
Exemplo n.º 2
0
  /**
   * Retrieves the lowest date value in the given field
   *
   * @param query a solr query
   * @param dateField the field for which we want to retrieve our date
   * @param filterquery the filterqueries
   * @return the lowest date found, in a date object
   */
  private Date getLowestDateValue(
      Context context, String query, String dateField, String... filterquery) {

    try {
      DiscoverQuery discoverQuery = new DiscoverQuery();
      discoverQuery.setQuery(query);
      discoverQuery.setMaxResults(1);
      discoverQuery.setSortField(dateField, DiscoverQuery.SORT_ORDER.asc);
      discoverQuery.addFilterQueries(filterquery);

      DiscoverResult rsp = searchService.search(context, discoverQuery);
      //            if(0 < rsp.getResults().getNumFound()){
      //                return (Date) rsp.getResults().get(0).getFieldValue(dateField);
      //            }
    } catch (Exception e) {
      log.error("Unable to get lowest date", e);
    }
    return null;
  }