List of usage examples for org.apache.solr.client.solrj SolrQuery setRows
public SolrQuery setRows(Integer rows)
From source file:org.dspace.app.webui.cris.servlet.ResearcherNetworkServlet.java
private boolean checkAvailableData(HttpServletRequest request, String connection, String authority) throws SearchServiceException { String query = "type:" + connection + " AND focus_auth:" + authority + " AND entity:" + ConstantNetwork.ENTITY_RP; SolrQuery solrQuery = new SolrQuery(); solrQuery.setQuery(query);// w w w .j av a 2 s . c om solrQuery.setStart(0); solrQuery.setRows(0); QueryResponse rsp = getService().search(solrQuery); SolrDocumentList docs = rsp.getResults(); if (docs != null) { if (docs.getNumFound() > 0) { return true; } } return false; }
From source file:org.dspace.app.webui.cris.util.RelationPreferenceUtil.java
public RelatedObjects getRelatedObject(Context context, ACrisObject cris, String relationType, String userQuery, String status, List<Sort> sorts, int rpp, int offset) throws SearchServiceException, SQLException { String uuid = cris.getUuid(); String configurationName = preferenceService.getConfigurationName(cris, relationType); RelationPreferenceConfiguration configuration = preferenceService.getConfigurationService() .getRelationPreferenceConfiguration(configurationName); List<ColumnVisualizationConfiguration> columns = configuration.getColumnsVisualizationConfiguration(); RelatedObjects result = new RelatedObjects(); List<RelatedObject> related = result.getObjects(); String query = MessageFormat.format(configuration.getRelationConfiguration().getQuery(), cris.getCrisID(), cris.getUuid());//from w w w .ja v a2s .c o m boolean sysAdmin = AuthorizeManager.isAdmin(context); SolrQuery solrQuery = new SolrQuery(); if (StringUtils.isNotEmpty(userQuery)) { solrQuery.addFilterQuery("{!tag=user}" + ClientUtils.escapeQueryChars(userQuery) + "*"); solrQuery.addFacetQuery("{!ex=user}*:*"); } if (!configuration.isActionEnabled(RelationPreference.HIDED, sysAdmin)) { solrQuery.addFilterQuery(getHiddenFilter(cris, configurationName)); } if (!configuration.isActionEnabled(RelationPreference.SELECTED, sysAdmin)) { solrQuery.addFilterQuery(getSelectedFilter(cris, configurationName)); } if (configuration.isActionEnabled(RelationPreference.UNLINKED, sysAdmin)) { query = getUnlinkedFilter(cris, configurationName, query); } solrQuery.setQuery(query); if (StringUtils.isNotEmpty(status)) { solrQuery.addFilterQuery(RelationPreference.PREFIX_RELATIONPREFERENCES + configurationName + "." + status.toLowerCase() + ":\"" + cris.getUuid() + "\""); } if (sorts != null) { for (Sort s : sorts) { if (s.col < 0) { solrQuery.addSortField("cris-uuid", s.asc ? ORDER.asc : ORDER.desc); solrQuery.addSortField("search.resourceid", s.asc ? ORDER.asc : ORDER.desc); } else { solrQuery.addSortField(columns.get(s.col).getSortField(), s.asc ? ORDER.asc : ORDER.desc); } } } solrQuery.setRows(rpp); solrQuery.setStart(offset); solrQuery.setFields("search.resourceid", "cris-uuid", RelationPreference.PREFIX_RELATIONPREFERENCES + configurationName + "." + RelationPreference.UNLINKED, RelationPreference.PREFIX_RELATIONPREFERENCES + configurationName + "." + RelationPreference.HIDED, RelationPreference.PREFIX_RELATIONPREFERENCES + configurationName + "." + RelationPreference.SELECTED); QueryResponse qRes = searcher.search(solrQuery); result.setFilterRecords((int) qRes.getResults().getNumFound()); if (StringUtils.isNotEmpty(userQuery)) { result.setTotalRecords(qRes.getFacetQuery().get("{!ex=user}*:*")); } else { result.setTotalRecords((int) qRes.getResults().getNumFound()); } List<Object[]> dsoList = new ArrayList<Object[]>(); for (SolrDocument doc : qRes.getResults()) { List<String> unlinked = (List<String>) doc.getFieldValue(RelationPreference.PREFIX_RELATIONPREFERENCES + configurationName + "." + RelationPreference.UNLINKED); List<String> hided = (List<String>) doc.getFieldValue(RelationPreference.PREFIX_RELATIONPREFERENCES + configurationName + "." + RelationPreference.HIDED); List<String> selected = (List<String>) doc.getFieldValue(RelationPreference.PREFIX_RELATIONPREFERENCES + configurationName + "." + RelationPreference.SELECTED); String relStatus = null; if (unlinked != null && unlinked.contains(uuid)) { relStatus = RelationPreference.UNLINKED; } else if (hided != null && hided.contains(uuid)) { relStatus = RelationPreference.HIDED; } else if (selected != null && selected.contains(uuid)) { relStatus = RelationPreference.SELECTED; } if (doc.getFieldValue("cris-uuid") == null) { try { dsoList.add(new Object[] { Item.find(context, (Integer) doc.getFieldValue("search.resourceid")), relStatus }); } catch (SQLException e) { throw new RuntimeException(e.getMessage(), e); } } else { dsoList.add(new Object[] { applicationService.getEntityByUUID((String) doc.getFieldValue("cris-uuid")), relStatus }); } } for (Object[] dso : dsoList) { related.add(convert(context, (DSpaceObject) dso[0], configuration, (String) dso[1])); } return result; }
From source file:org.dspace.app.xmlui.aspect.discovery.BrowseFacet.java
License:Open Source License
/** * Retrieves the lowest date value in the given field * @param query a solr query/*from w w w . j av a2 s .c o m*/ * @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(String query, String dateField, String... filterquery) { try { SolrQuery solrQuery = new SolrQuery(); solrQuery.setQuery(query); solrQuery.setFields(dateField); solrQuery.setRows(1); solrQuery.setSortField(dateField, SolrQuery.ORDER.asc); solrQuery.setFilterQueries(filterquery); QueryResponse rsp = searchService.search(solrQuery); if (0 < rsp.getResults().getNumFound()) { return (Date) rsp.getResults().get(0).getFieldValue(dateField); } } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:org.dspace.authority.SolrAuthority.java
License:BSD License
@Override public String getLabel(String field, String key, String locale) { try {//from ww w . jav a 2s . c o m if (log.isDebugEnabled()) { log.debug("requesting label for key " + key + " using locale " + locale); } SolrQuery queryArgs = new SolrQuery(); queryArgs.setQuery("id:" + key); queryArgs.setRows(1); QueryResponse searchResponse = getSearchService().search(queryArgs); SolrDocumentList docs = searchResponse.getResults(); if (docs.getNumFound() == 1) { String label = null; try { label = (String) docs.get(0).getFieldValue("value_" + locale); } catch (Exception e) { //ok to fail here } if (label != null) { if (log.isDebugEnabled()) { log.debug("returning label " + label + " for key " + key + " using locale " + locale + " and fieldvalue " + "value_" + locale); } return label; } try { label = (String) docs.get(0).getFieldValue("value"); } catch (Exception e) { log.error("couldn't get field value for key " + key, e); } if (label != null) { if (log.isDebugEnabled()) { log.debug("returning label " + label + " for key " + key + " using locale " + locale + " and fieldvalue " + "value"); } return label; } try { label = (String) docs.get(0).getFieldValue("value_en"); } catch (Exception e) { log.error("couldn't get field value for key " + key, e); } if (label != null) { if (log.isDebugEnabled()) { log.debug("returning label " + label + " for key " + key + " using locale " + locale + " and fieldvalue " + "value_en"); } return label; } } } catch (Exception e) { log.error("error occurred while trying to get label for key " + key, e); } return key; }
From source file:org.dspace.discovery.SolrServiceImpl.java
License:BSD License
protected SolrQuery resolveToSolrQuery(Context context, DiscoverQuery discoveryQuery, boolean includeUnDiscoverable) { SolrQuery solrQuery = new SolrQuery(); String query = "*:*"; if (discoveryQuery.getQuery() != null) { query = discoveryQuery.getQuery(); }//from w w w.java 2s.co m solrQuery.setQuery(query); if (discoveryQuery.isSpellCheck()) { solrQuery.setParam(SpellingParams.SPELLCHECK_Q, query); solrQuery.setParam(SpellingParams.SPELLCHECK_COLLATE, Boolean.TRUE); solrQuery.setParam("spellcheck", Boolean.TRUE); } if (!includeUnDiscoverable) { solrQuery.addFilterQuery("NOT(withdrawn:true)"); solrQuery.addFilterQuery("NOT(discoverable:false)"); } for (int i = 0; i < discoveryQuery.getFilterQueries().size(); i++) { String filterQuery = discoveryQuery.getFilterQueries().get(i); solrQuery.addFilterQuery(filterQuery); } if (discoveryQuery.getDSpaceObjectFilter() != -1) { solrQuery.addFilterQuery("search.resourcetype:" + discoveryQuery.getDSpaceObjectFilter()); } for (int i = 0; i < discoveryQuery.getFieldPresentQueries().size(); i++) { String filterQuery = discoveryQuery.getFieldPresentQueries().get(i); solrQuery.addFilterQuery(filterQuery + ":[* TO *]"); } if (discoveryQuery.getStart() != -1) { solrQuery.setStart(discoveryQuery.getStart()); } if (discoveryQuery.getMaxResults() != -1) { solrQuery.setRows(discoveryQuery.getMaxResults()); } if (discoveryQuery.getSortField() != null) { SolrQuery.ORDER order = SolrQuery.ORDER.asc; if (discoveryQuery.getSortOrder().equals(DiscoverQuery.SORT_ORDER.desc)) order = SolrQuery.ORDER.desc; solrQuery.addSortField(discoveryQuery.getSortField(), order); } for (String property : discoveryQuery.getProperties().keySet()) { List<String> values = discoveryQuery.getProperties().get(property); solrQuery.add(property, values.toArray(new String[values.size()])); } List<DiscoverFacetField> facetFields = discoveryQuery.getFacetFields(); if (0 < facetFields.size()) { //Only add facet information if there are any facets for (DiscoverFacetField facetFieldConfig : facetFields) { String field = transformFacetField(facetFieldConfig, facetFieldConfig.getField(), false); solrQuery.addFacetField(field); // Setting the facet limit in this fashion ensures that each facet can have its own max solrQuery.add("f." + field + "." + FacetParams.FACET_LIMIT, String.valueOf(facetFieldConfig.getLimit())); String facetSort; if (DiscoveryConfigurationParameters.SORT.COUNT.equals(facetFieldConfig.getSortOrder())) { facetSort = FacetParams.FACET_SORT_COUNT; } else { facetSort = FacetParams.FACET_SORT_INDEX; } solrQuery.add("f." + field + "." + FacetParams.FACET_SORT, facetSort); if (facetFieldConfig.getOffset() != -1) { solrQuery.setParam("f." + field + "." + FacetParams.FACET_OFFSET, String.valueOf(facetFieldConfig.getOffset())); } if (facetFieldConfig.getPrefix() != null) { solrQuery.setFacetPrefix(field, facetFieldConfig.getPrefix()); } } List<String> facetQueries = discoveryQuery.getFacetQueries(); for (String facetQuery : facetQueries) { solrQuery.addFacetQuery(facetQuery); } if (discoveryQuery.getFacetMinCount() != -1) { solrQuery.setFacetMinCount(discoveryQuery.getFacetMinCount()); } solrQuery.setParam(FacetParams.FACET_OFFSET, String.valueOf(discoveryQuery.getFacetOffset())); } if (0 < discoveryQuery.getHitHighlightingFields().size()) { solrQuery.setHighlight(true); solrQuery.add(HighlightParams.USE_PHRASE_HIGHLIGHTER, Boolean.TRUE.toString()); for (DiscoverHitHighlightingField highlightingField : discoveryQuery.getHitHighlightingFields()) { solrQuery.addHighlightField(highlightingField.getField() + "_hl"); solrQuery.add("f." + highlightingField.getField() + "_hl." + HighlightParams.FRAGSIZE, String.valueOf(highlightingField.getMaxChars())); solrQuery.add("f." + highlightingField.getField() + "_hl." + HighlightParams.SNIPPETS, String.valueOf(highlightingField.getMaxSnippets())); } } //Add any configured search plugins ! List<SolrServiceSearchPlugin> solrServiceSearchPlugins = new DSpace().getServiceManager() .getServicesByType(SolrServiceSearchPlugin.class); for (SolrServiceSearchPlugin searchPlugin : solrServiceSearchPlugins) { searchPlugin.additionalSearchParameters(context, discoveryQuery, solrQuery); } return solrQuery; }
From source file:org.dspace.discovery.SolrServiceImpl.java
License:BSD License
public List<DSpaceObject> search(Context context, String query, String orderfield, boolean ascending, int offset, int max, String... filterquery) { try {//from w w w.j ava2 s .c om if (getSolr() == null) { return Collections.emptyList(); } SolrQuery solrQuery = new SolrQuery(); solrQuery.setQuery(query); solrQuery.setFields("search.resourceid", "search.resourcetype"); solrQuery.setStart(offset); solrQuery.setRows(max); if (orderfield != null) { solrQuery.setSortField(orderfield, ascending ? SolrQuery.ORDER.asc : SolrQuery.ORDER.desc); } if (filterquery != null) { solrQuery.addFilterQuery(filterquery); } QueryResponse rsp = getSolr().query(solrQuery); SolrDocumentList docs = rsp.getResults(); Iterator iter = docs.iterator(); List<DSpaceObject> result = new ArrayList<DSpaceObject>(); while (iter.hasNext()) { SolrDocument doc = (SolrDocument) iter.next(); DSpaceObject o = DSpaceObject.find(context, (Integer) doc.getFirstValue("search.resourcetype"), (Integer) doc.getFirstValue("search.resourceid")); if (o != null) { result.add(o); } } return result; } catch (Exception e) { // Any acception that we get ignore it. // We do NOT want any crashed to shown by the user log.error(LogManager.getHeader(context, "Error while quering solr", "Queyr: " + query), e); return new ArrayList<DSpaceObject>(0); } }
From source file:org.dspace.resourcesync.ResourceSyncAuditService.java
License:BSD License
protected HttpSolrServer getSolr() { if (solr == null) { String solrService = new DSpace().getConfigurationService().getProperty("resourcesync.solr.server"); try {/*from w w w.j a v a2s. c o m*/ log.debug("Solr URL: " + solrService); solr = new HttpSolrServer(solrService); solr.setBaseURL(solrService); solr.setUseMultiPartPost(true); SolrQuery solrQuery = new SolrQuery().setQuery("*:*"); solrQuery.setFields(RESOURCE_ID_FIELD, RESOURCE_TYPE_FIELD, CHANGETYPE_FIELD, DATETIME_FIELD, SCOPES_FIELD); solrQuery.setRows(1); solr.query(solrQuery); } catch (SolrServerException e) { log.error("Error while initializing solr server", e); } } return solr; }
From source file:org.dspace.resourcesync.ResourceSyncAuditService.java
License:BSD License
public List<ResourceSyncEvent> listEvents(Date from, Date to, String scope) { // SolrQuery solrQuery = new SolrQuery(buildTimeQuery(from, to)); SolrQuery solrQuery = new SolrQuery((buildTimeQuery(from, to))); solrQuery.setRows(Integer.MAX_VALUE); solrQuery.addSort(new SortClause(DATETIME_FIELD, ORDER.asc)); solrQuery.addFilterQuery(SCOPES_FIELD + ":" + scope); // solrQuery.addFilterQuery("scope:" + scope); QueryResponse queryResponse;//from w w w . j a v a 2 s . c om try { queryResponse = getSolr().query(solrQuery); } catch (SolrServerException e) { throw new RuntimeException(e.getMessage(), e); } List<ResourceSyncEvent> listResourceSyncEvent = new ArrayList<ResourceSyncEvent>(); // queryResponse.getResults().iterator().next().get(RESOURCE_ID_FIELD); Iterator<SolrDocument> iterator = queryResponse.getResults().iterator(); while (iterator.hasNext()) { ResourceSyncEvent rse = new ResourceSyncEvent(); SolrDocument sd = iterator.next(); rse.setResource_id((UUID) sd.getFieldValue(RESOURCE_ID_FIELD)); rse.setResource_type((int) sd.getFieldValue(RESOURCE_TYPE_FIELD)); rse.setChangetype((String) sd.getFieldValue(CHANGETYPE_FIELD)); rse.setDatetime((Date) sd.getFieldValue(DATETIME_FIELD)); rse.setScopes((List<String>) sd.getFieldValue(SCOPES_FIELD)); rse.setHandle((String) sd.getFieldValue(HANDLE_FIELD)); rse.setScopes((List<String>) sd.getFieldValue(EXTRA_FIELD)); // System.out.println("+++Resource id = "+rse.getResource_id()+" Resource Type = "+ // rse.getResource_type()+" changeType = "+rse.getChangetype()+ " datetime = "+rse.getDatetime()+ // " scopes = "+rse.getScopes()); listResourceSyncEvent.add(rse); } return listResourceSyncEvent; }
From source file:org.dspace.statistics.SolrLogger.java
License:BSD License
public static void shardSolrIndex() throws IOException, SolrServerException { /*/*ww w . j ava 2s.c o m*/ Start by faceting by year so we can include each year in a separate core ! */ SolrQuery yearRangeQuery = new SolrQuery(); yearRangeQuery.setQuery("*:*"); yearRangeQuery.setRows(0); yearRangeQuery.setFacet(true); yearRangeQuery.add(FacetParams.FACET_RANGE, "time"); //We go back to 2000 the year 2000, this is a bit overkill but this way we ensure we have everything //The alternative would be to sort but that isn't recommended since it would be a very costly query ! yearRangeQuery.add(FacetParams.FACET_RANGE_START, "NOW/YEAR-" + (Calendar.getInstance().get(Calendar.YEAR) - 2000) + "YEARS"); //Add the +0year to ensure that we DO NOT include the current year yearRangeQuery.add(FacetParams.FACET_RANGE_END, "NOW/YEAR+0YEARS"); yearRangeQuery.add(FacetParams.FACET_RANGE_GAP, "+1YEAR"); yearRangeQuery.add(FacetParams.FACET_MINCOUNT, String.valueOf(1)); //Create a temp directory to store our files in ! File tempDirectory = new File( ConfigurationManager.getProperty("dspace.dir") + File.separator + "temp" + File.separator); tempDirectory.mkdirs(); QueryResponse queryResponse = solr.query(yearRangeQuery); //We only have one range query ! List<RangeFacet.Count> yearResults = queryResponse.getFacetRanges().get(0).getCounts(); for (RangeFacet.Count count : yearResults) { long totalRecords = count.getCount(); //Create a range query from this ! //We start with out current year DCDate dcStart = new DCDate(count.getValue()); Calendar endDate = Calendar.getInstance(); //Advance one year for the start of the next one ! endDate.setTime(dcStart.toDate()); endDate.add(Calendar.YEAR, 1); DCDate dcEndDate = new DCDate(endDate.getTime()); StringBuilder filterQuery = new StringBuilder(); filterQuery.append("time:(["); filterQuery.append(ClientUtils.escapeQueryChars(dcStart.toString())); filterQuery.append(" TO "); filterQuery.append(ClientUtils.escapeQueryChars(dcEndDate.toString())); filterQuery.append("]"); //The next part of the filter query excludes the content from midnight of the next year ! filterQuery.append(" NOT ").append(ClientUtils.escapeQueryChars(dcEndDate.toString())); filterQuery.append(")"); Map<String, String> yearQueryParams = new HashMap<String, String>(); yearQueryParams.put(CommonParams.Q, "*:*"); yearQueryParams.put(CommonParams.ROWS, String.valueOf(10000)); yearQueryParams.put(CommonParams.FQ, filterQuery.toString()); yearQueryParams.put(CommonParams.WT, "csv"); //Start by creating a new core String coreName = "statistics-" + dcStart.getYear(); HttpSolrServer statisticsYearServer = createCore(solr, coreName); System.out.println("Moving: " + totalRecords + " into core " + coreName); log.info("Moving: " + totalRecords + " records into core " + coreName); List<File> filesToUpload = new ArrayList<File>(); for (int i = 0; i < totalRecords; i += 10000) { String solrRequestUrl = solr.getBaseURL() + "/select"; solrRequestUrl = generateURL(solrRequestUrl, yearQueryParams); HttpGet get = new HttpGet(solrRequestUrl); HttpResponse response = new DefaultHttpClient().execute(get); InputStream csvInputstream = response.getEntity().getContent(); //Write the csv ouput to a file ! File csvFile = new File(tempDirectory.getPath() + File.separatorChar + "temp." + dcStart.getYear() + "." + i + ".csv"); FileUtils.copyInputStreamToFile(csvInputstream, csvFile); filesToUpload.add(csvFile); //Add 10000 & start over again yearQueryParams.put(CommonParams.START, String.valueOf((i + 10000))); } for (File tempCsv : filesToUpload) { //Upload the data in the csv files to our new solr core ContentStreamUpdateRequest contentStreamUpdateRequest = new ContentStreamUpdateRequest( "/update/csv"); contentStreamUpdateRequest.setParam("stream.contentType", "text/plain;charset=utf-8"); contentStreamUpdateRequest.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true); contentStreamUpdateRequest.addFile(tempCsv, "text/plain;charset=utf-8"); statisticsYearServer.request(contentStreamUpdateRequest); } statisticsYearServer.commit(true, true); //Delete contents of this year from our year query ! solr.deleteByQuery(filterQuery.toString()); solr.commit(true, true); log.info("Moved " + totalRecords + " records into core: " + coreName); } FileUtils.deleteDirectory(tempDirectory); }
From source file:org.dspace.statistics.SolrLogger.java
License:BSD License
public static void reindexBitstreamHits(boolean removeDeletedBitstreams) throws Exception { Context context = new Context(); try {/*from w w w .ja v a2s. com*/ //First of all retrieve the total number of records to be updated SolrQuery query = new SolrQuery(); query.setQuery("*:*"); query.addFilterQuery("type:" + Constants.BITSTREAM); //Only retrieve records which do not have a bundle name query.addFilterQuery("-bundleName:[* TO *]"); query.setRows(0); addAdditionalSolrYearCores(query); long totalRecords = solr.query(query).getResults().getNumFound(); File tempDirectory = new File( ConfigurationManager.getProperty("dspace.dir") + File.separator + "temp" + File.separator); tempDirectory.mkdirs(); List<File> tempCsvFiles = new ArrayList<File>(); for (int i = 0; i < totalRecords; i += 10000) { Map<String, String> params = new HashMap<String, String>(); params.put(CommonParams.Q, "*:*"); params.put(CommonParams.FQ, "-bundleName:[* TO *] AND type:" + Constants.BITSTREAM); params.put(CommonParams.WT, "csv"); params.put(CommonParams.ROWS, String.valueOf(10000)); params.put(CommonParams.START, String.valueOf(i)); String solrRequestUrl = solr.getBaseURL() + "/select"; solrRequestUrl = generateURL(solrRequestUrl, params); HttpGet get = new HttpGet(solrRequestUrl); HttpResponse response = new DefaultHttpClient().execute(get); InputStream csvOutput = response.getEntity().getContent(); Reader csvReader = new InputStreamReader(csvOutput); List<String[]> rows = new CSVReader(csvReader).readAll(); String[][] csvParsed = rows.toArray(new String[rows.size()][]); String[] header = csvParsed[0]; //Attempt to find the bitstream id index ! int idIndex = 0; for (int j = 0; j < header.length; j++) { if (header[j].equals("id")) { idIndex = j; } } File tempCsv = new File(tempDirectory.getPath() + File.separatorChar + "temp." + i + ".csv"); tempCsvFiles.add(tempCsv); CSVWriter csvp = new CSVWriter(new FileWriter(tempCsv)); //csvp.setAlwaysQuote(false); //Write the header ! csvp.writeNext((String[]) ArrayUtils.add(header, "bundleName")); Map<Integer, String> bitBundleCache = new HashMap<Integer, String>(); //Loop over each line (skip the headers though)! for (int j = 1; j < csvParsed.length; j++) { String[] csvLine = csvParsed[j]; //Write the default line ! int bitstreamId = Integer.parseInt(csvLine[idIndex]); //Attempt to retrieve our bundle name from the cache ! String bundleName = bitBundleCache.get(bitstreamId); if (bundleName == null) { //Nothing found retrieve the bitstream Bitstream bitstream = Bitstream.find(context, bitstreamId); //Attempt to retrieve our bitstream ! if (bitstream != null) { Bundle[] bundles = bitstream.getBundles(); if (bundles != null && 0 < bundles.length) { Bundle bundle = bundles[0]; bundleName = bundle.getName(); context.removeCached(bundle, bundle.getID()); } else { //No bundle found, we are either a collection or a community logo, check for it ! DSpaceObject parentObject = bitstream.getParentObject(); if (parentObject instanceof Collection) { bundleName = "LOGO-COLLECTION"; } else if (parentObject instanceof Community) { bundleName = "LOGO-COMMUNITY"; } if (parentObject != null) { context.removeCached(parentObject, parentObject.getID()); } } //Cache the bundle name bitBundleCache.put(bitstream.getID(), bundleName); //Remove the bitstream from cache context.removeCached(bitstream, bitstreamId); } //Check if we don't have a bundlename //If we don't have one & we do not need to delete the deleted bitstreams ensure that a BITSTREAM_DELETED bundle name is given ! if (bundleName == null && !removeDeletedBitstreams) { bundleName = "BITSTREAM_DELETED"; } } csvp.writeNext((String[]) ArrayUtils.add(csvLine, bundleName)); } //Loop over our parsed csv csvp.flush(); csvp.close(); } //Add all the separate csv files for (File tempCsv : tempCsvFiles) { ContentStreamUpdateRequest contentStreamUpdateRequest = new ContentStreamUpdateRequest( "/update/csv"); contentStreamUpdateRequest.setParam("stream.contentType", "text/plain;charset=utf-8"); contentStreamUpdateRequest.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true); contentStreamUpdateRequest.addFile(tempCsv, "text/plain;charset=utf-8"); solr.request(contentStreamUpdateRequest); } //Now that all our new bitstream stats are in place, delete all the old ones ! solr.deleteByQuery("-bundleName:[* TO *] AND type:" + Constants.BITSTREAM); //Commit everything to wrap up solr.commit(true, true); //Clean up our directory ! FileUtils.deleteDirectory(tempDirectory); } catch (Exception e) { log.error("Error while updating the bitstream statistics", e); throw e; } finally { context.abort(); } }