@Override public int doDistinctOffsetQuery(String column, String value, boolean isAscending) throws BrowseException { DiscoverResult resp = getSolrResponse(); List<FacetResult> facets = resp.getFacetResult(facetField); Comparator comparator = new SolrBrowseDAO.FacetValueComparator(); Collections.sort(facets, comparator); int x = Collections.binarySearch(facets, value, comparator); int ascValue = (x >= 0) ? x : -(x + 1); if (isAscending) { return ascValue; } else { return doCountQuery() - ascValue; } }
throws BrowseException { DiscoverQuery query = new DiscoverQuery(); addLocationScopeFilter(query); addStatusFilter(query); query.setMaxResults(0); query.addFilterQueries("search.resourcetype:" + Constants.ITEM);
@Override public List<Item> doQuery() throws BrowseException { DiscoverResult resp = getSolrResponse(); List<Item> bitems = new ArrayList<>(); for (DSpaceObject solrDoc : resp.getDspaceObjects()) { // FIXME introduce project, don't retrieve Item immediately when // processing the query... Item item = (Item) solrDoc; bitems.add(item); } return bitems; }
/** * Get an instance of the relevant Read Only DAO class, which will * conform to the BrowseDAO interface * * @param context the DSpace context * @return the relevant DAO * @throws BrowseException if browse error */ public static BrowseDAO getInstance(Context context) throws BrowseException { String className = ConfigurationManager.getProperty("browseDAO.class"); if (className == null) { // SOLR implementation is the default since DSpace 4.0 return new SolrBrowseDAO(context); } try { return (BrowseDAO) Class .forName(ConfigurationManager.getProperty("browseDAO.class")) .getConstructor(Context.class).newInstance(context); } catch (Exception e) { throw new BrowseException("The configuration for browseDAO is invalid: " + className, e); } } }
private DiscoverResult getSolrResponse() throws BrowseException { if (sResponse == null) { DiscoverQuery query = new DiscoverQuery(); addLocationScopeFilter(query); addStatusFilter(query); if (distinct) { DiscoverFacetField dff;
@Override public int doCountQuery() throws BrowseException { DiscoverResult resp = getSolrResponse(); int count = 0; if (distinct) { List<FacetResult> facetResults = resp.getFacetResult(facetField); count = facetResults.size(); } else { // we need to cast to int to respect the BrowseDAO contract... count = (int) resp.getTotalSearchResults(); // FIXME null the response cache // the BrowseEngine send fake argument to the BrowseDAO for the // count... sResponse = null; } return count; }
@Override public List doValueQuery() throws BrowseException { DiscoverResult resp = getSolrResponse(); List<FacetResult> facet = resp.getFacetResult(facetField); int count = doCountQuery(); int start = offset > 0 ? offset : 0; int max = limit > 0 ? limit : count; //if negative, return everything List<String[]> result = new ArrayList<>(); if (ascending) { for (int i = start; i < (start + max) && i < count; i++) { FacetResult c = facet.get(i); String freq = showFrequencies ? String.valueOf(c.getCount()) : ""; result.add(new String[] {c.getDisplayedValue(), c.getAuthorityKey(), freq}); } } else { for (int i = count - start - 1; i >= count - (start + max) && i >= 0; i--) { FacetResult c = facet.get(i); String freq = showFrequencies ? String.valueOf(c.getCount()) : ""; result.add(new String[] {c.getDisplayedValue(), c.getAuthorityKey(), freq}); } } return result; }