Example #1
0
  private String getPreviousPageURL(Request request) {
    // If our offset should be 0 then we shouldn't be able to view a previous page url
    if (0 == queryArgs.getFacetOffset()) {
      return null;
    }

    Map<String, String> parameters = new HashMap<String, String>();
    parameters.put(FACET_FIELD, request.getParameter(FACET_FIELD));
    if (queryArgs.getFacetOffset() != -1) {
      parameters.put(OFFSET, String.valueOf(queryArgs.getFacetOffset() - DEFAULT_PAGE_SIZE));
    }

    // Add the filter queries
    String url = generateURL("browse-discovery", parameters);
    String[] fqs = getParameterFacetQueries();
    if (fqs != null) {
      StringBuilder urlBuilder = new StringBuilder(url);
      for (String fq : fqs) {
        urlBuilder.append("&fq=").append(fq);
      }

      url = urlBuilder.toString();
    }

    return url;
  }
Example #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;
  }
Example #3
0
  private String getNextPageURL(Request request) {
    Map<String, String> parameters = new HashMap<String, String>();
    parameters.put(FACET_FIELD, request.getParameter(FACET_FIELD));
    if (queryArgs.getFacetOffset() != -1) {
      parameters.put(OFFSET, String.valueOf(queryArgs.getFacetOffset() + DEFAULT_PAGE_SIZE));
    }

    // Add the filter queries
    String url = generateURL("browse-discovery", parameters);
    String[] fqs = getParameterFacetQueries();
    if (fqs != null) {
      StringBuilder urlBuilder = new StringBuilder(url);
      for (String fq : fqs) {
        urlBuilder.append("&fq=").append(fq);
      }

      url = urlBuilder.toString();
    }

    return url;
  }
Example #4
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;
  }
Example #5
0
  @Override
  public void addBody(Body body)
      throws SAXException, WingException, UIException, SQLException, IOException,
          AuthorizeException {

    Request request = ObjectModelHelper.getRequest(objectModel);

    DSpaceObject dso = HandleUtil.obtainHandle(objectModel);

    // Set up the major variables
    // Collection collection = (Collection) dso;

    // Build the collection viewer division.

    // Make sure we get our results
    queryResults = getQueryResponse(dso);
    if (this.queryResults != null) {

      Map<String, List<DiscoverResult.FacetResult>> facetFields =
          this.queryResults.getFacetResults();
      if (facetFields == null) {
        facetFields = new LinkedHashMap<String, List<DiscoverResult.FacetResult>>();
      }

      //            facetFields.addAll(this.queryResults.getFacetDates());

      if (facetFields.size() > 0) {
        String facetField =
            String.valueOf(facetFields.keySet().toArray(new String[facetFields.size()])[0]);
        java.util.List<DiscoverResult.FacetResult> values = facetFields.get(facetField);

        if (values != null && 0 < values.size()) {

          Division results = body.addDivision("browse-by-" + facetField + "-results", "primary");

          results.setHead(
              message(
                  "xmlui.ArtifactBrowser.AbstractSearch.type_"
                      + request.getParameter(FACET_FIELD)
                      + "_browse"));

          // Find our faceting offset
          int offSet = queryArgs.getFacetOffset();
          if (offSet == -1) {
            offSet = 0;
          }

          // Only show the nextpageurl if we have at least one result following our current results
          String nextPageUrl = null;
          if (values.size() == (DEFAULT_PAGE_SIZE + 1)) {
            nextPageUrl = getNextPageURL(request);
          }

          results.setSimplePagination(
              (int) queryResults.getDspaceObjects().size(),
              offSet + 1,
              (offSet + (values.size() - 1)),
              getPreviousPageURL(request),
              nextPageUrl);

          Table singleTable =
              results.addTable(
                  "browse-by-" + facetField + "-results",
                  (int) (queryResults.getDspaceObjects().size() + 1),
                  1);

          List<String> filterQueries = new ArrayList<String>();
          if (request.getParameterValues("fq") != null) {
            filterQueries = Arrays.asList(request.getParameterValues("fq"));
          }
          for (int i = 0; i < values.size(); i++) {
            DiscoverResult.FacetResult value = values.get(i);

            String displayedValue = value.getDisplayedValue();
            String filterQuery = value.getAsFilterQuery();

            //                        if(field.getGap() != null){
            //                            //We have a date get the year so we can display it
            //                            DateFormat simpleDateformat = new
            // SimpleDateFormat("yyyy");
            //                            displayedValue =
            // simpleDateformat.format(SolrServiceImpl.toDate(displayedValue));
            //                            filterQuery =
            // ClientUtils.escapeQueryChars(value.getFacetField().getName()) + ":" + displayedValue
            // + "*";
            //                        }

            Cell cell = singleTable.addRow().addCell();

            // No use in selecting the same filter twice
            if (filterQueries.contains(filterQuery)) {
              cell.addContent(displayedValue + " (" + value.getCount() + ")");
            } else {
              cell.addXref(
                  contextPath
                      + (dso == null ? "" : "/handle/" + dso.getHandle())
                      + "/discover?"
                      + "&fq="
                      + URLEncoder.encode(filterQuery, "UTF-8")
                      + (request.getQueryString() != null ? "&" + request.getQueryString() : ""),
                  displayedValue + " (" + value.getCount() + ")");
            }
          }
        }
      }
    }

    // DSpaceObject dso = HandleUtil.obtainHandle(objectModel);

    /*
    if (dso != null)
    {
        if (dso instanceof Collection)
        {
            browseContext.addItem().addXref(contextPath + "/discovery/?q=search.resourcetype%3A2+AND+location%3Al" + dso.getID(), T_head_this_collection );
        }
        if (dso instanceof Community)
        {
            browseContext.addItem().addXref(contextPath + "/discovery/?q=search.resourcetype%3A2+AND+location%3Am" + dso.getID(), T_head_this_community );
        }
    }

    browseGlobal.addItem().addXref(contextPath + "/discovery/?q=search.resourcetype%3A2", T_head_all_of_dspace );
    */
  }