/** * reIndexContent removes something from the index, then re-indexes it * * @param context context object * @param dso object to re-index */ @Override public void reIndexContent(Context context, DSpaceObject dso) throws SQLException, IOException { try { indexContent(context, dso); } catch (Exception exception) { log.error(exception.getMessage(), exception); emailException(exception); } }
protected String transformSortValue(Context context, String field, String value) throws SQLException { if (field.equals("location.comm") || field.equals("location.coll")) { value = locationToName(context, field, value); } else if (field.endsWith("_filter") || field.endsWith("_ac") || field.endsWith("_acid")) { //We have a filter make sure we split ! String separator = DSpaceServicesFactory.getInstance().getConfigurationService() .getProperty("discovery.solr.facets.split.char"); if (separator == null) { separator = FILTER_SEPARATOR; } //Escape any regex chars separator = java.util.regex.Pattern.quote(separator); String[] fqParts = value.split(separator); StringBuffer valueBuffer = new StringBuffer(); int end = fqParts.length / 2; for (int i = 0; i < end; i++) { valueBuffer.append(fqParts[i]); } value = valueBuffer.toString(); } else if (value.matches("\\((.*?)\\)")) { //The brackets where added for better solr results, remove the first & last one value = value.substring(1, value.length() - 1); } return value; }
@Override public void indexContent(Context context, DSpaceObject dso, boolean force, boolean commit) throws SearchServiceException, SQLException { indexContent(context, dso, force); if (commit) { commit(); } }
@Override public DiscoverResult search(Context context, DiscoverQuery discoveryQuery, boolean includeUnDiscoverable) throws SearchServiceException { try { if (getSolr() == null) { return new DiscoverResult(); } SolrQuery solrQuery = resolveToSolrQuery(context, discoveryQuery, includeUnDiscoverable); QueryResponse queryResponse = getSolr().query(solrQuery, SolrRequest.METHOD.POST); return retrieveResult(context, discoveryQuery, queryResponse); } catch (Exception e) { throw new org.dspace.discovery.SearchServiceException(e.getMessage(), e); } }
if (requiresIndexing(handle, ((Item) dso).getLastModified()) || force) { unIndexContent(context, handle); buildDocument(context, (Item) dso); unIndexContent(context, item); log.info("Removed Item: " + handle + " from Index"); buildDocument(context, (Collection) dso); log.info("Wrote Collection: " + handle + " to Index"); break; buildDocument(context, (Community) dso); log.info("Wrote Community: " + handle + " to Index"); break;
DSpaceObject dso = findDSpaceObject(context, doc); String displayedValue = transformDisplayedValue(context, facetField.getName(), facetValue.getName()); String field = transformFacetField(facetFieldConfig, facetField.getName(), true); String authorityValue = transformAuthorityValue(context, facetField.getName(), facetValue.getName()); String sortValue = transformSortValue(context, facetField.getName(), facetValue.getName()); String filterValue = displayedValue; if (StringUtils.isNotBlank(authorityValue)) {
List<String> locations = getCollectionLocations(context, collection); SolrInputDocument doc = buildDocument(Constants.COLLECTION, collection.getID(), collection.getHandle(), locations); addContainerMetadataField(doc, highlightedMetadataFields, toIgnoreMetadataFields, "dc.description", description); addContainerMetadataField(doc, highlightedMetadataFields, toIgnoreMetadataFields, "dc.description.abstract", description_abstract); addContainerMetadataField(doc, highlightedMetadataFields, toIgnoreMetadataFields, "dc.description.tableofcontents", description_table); addContainerMetadataField(doc, highlightedMetadataFields, toIgnoreMetadataFields, "dc.provenance", provenance); addContainerMetadataField(doc, highlightedMetadataFields, toIgnoreMetadataFields, "dc.rights", rights); addContainerMetadataField(doc, highlightedMetadataFields, toIgnoreMetadataFields, "dc.rights.license", rights_license); addContainerMetadataField(doc, highlightedMetadataFields, toIgnoreMetadataFields, "dc.title", title); writeDocument(doc, null);
List<String> locations = getItemLocations(item); SolrInputDocument doc = buildDocument(Constants.ITEM, item.getID(), handle, locations); if(searchFilter.getType().equals(DiscoveryConfigurationParameters.TYPE_DATE)){ Date date = toDate(value); if(date != null){ if(configuration.getType().equals(DiscoveryConfigurationParameters.TYPE_DATE)){ Date date = toDate(value); if(date != null){ String indexField = configuration.getIndexFieldName() + ".year"; Date date = toDate(value); if(date != null){ doc.addField(field + "_dt", date); writeDocument(doc); log.info("Wrote Item: " + handle + " to Index"); } catch (RuntimeException e) {
/** * Build a Lucene document for a DSpace Collection. * * @param collection Collection to be indexed * @throws SQLException sql exception * @throws IOException IO exception */ private void buildDocument(Collection collection) throws SQLException, IOException { List<String> locations = getCollectionLocations(collection); // Create Lucene Document SolrInputDocument doc = buildDocument(Constants.COLLECTION, collection.getID(), collection.getHandle(), locations); // and populate it String name = collection.getMetadata("name"); if (name != null) { doc.addField("name", name); } //Do any additional indexing, depends on the plugins List<SolrServiceIndexPlugin> solrServiceIndexPlugins = new DSpace().getServiceManager().getServicesByType(SolrServiceIndexPlugin.class); for (SolrServiceIndexPlugin solrServiceIndexPlugin : solrServiceIndexPlugins) { solrServiceIndexPlugin.additionalIndex(collection, doc); } writeDocument(doc); }
DSpaceObject dso = findDSpaceObject(context, doc); String displayedValue = transformDisplayedValue(context, facetField.getName(), facetValue.getName()); String field = transformFacetField(facetFieldConfig, facetField.getName(), true);
String field = transformFacetField(facetFieldConfig, facetFieldConfig.getField(), false); solrQuery.addFacetField(field); QueryResponse queryResponse = getSolr().query(solrQuery); return retrieveResult(context, discoveryQuery, queryResponse);
List<String> locations = getItemLocations(context, item); SolrInputDocument doc = buildDocument(Constants.ITEM, item.getID(), handle, locations); writeDocument(doc, new FullTextContentStreams(context, item)); log.info("Wrote Item: " + handle + " to Index"); } catch (RuntimeException e) {
for (items = itemService.findAllUnfiltered(context); items.hasNext(); ) { Item item = items.next(); indexContent(context, item, force); indexContent(context, collection, force); indexContent(context, community, force); if (getSolr() != null) { getSolr().commit();
if (getSolr() == null) { return; getSolr().deleteByQuery(RESOURCE_TYPE_FIELD + ":[2 TO 4]"); } else { SolrQuery query = new SolrQuery(); QueryResponse rsp = getSolr().query(query, SolrRequest.METHOD.POST); SolrDocumentList docs = rsp.getResults(); unIndexContent(context, handle); } else { log.debug("Keeping: " + handle);
throws SQLException, IOException { SolrInputDocument doc = buildDocument(Constants.COMMUNITY, community.getID(), community.getHandle(), null); addContainerMetadataField(doc, highlightedMetadataFields, toIgnoreMetadataFields, "dc.description", description); addContainerMetadataField(doc, highlightedMetadataFields, toIgnoreMetadataFields, "dc.description.abstract", description_abstract); addContainerMetadataField(doc, highlightedMetadataFields, toIgnoreMetadataFields, "dc.description.tableofcontents", description_table); addContainerMetadataField(doc, highlightedMetadataFields, toIgnoreMetadataFields, "dc.rights", rights); addContainerMetadataField(doc, highlightedMetadataFields, toIgnoreMetadataFields, "dc.title", title); writeDocument(doc, null);
/** * unIndex removes an Item, Collection, or Community only works if the * DSpaceObject has a handle (uses the handle for its unique ID) * * @param context * @param dso DSpace Object, can be Community, Item, or Collection * @throws SQLException * @throws IOException */ public void unIndexContent(Context context, DSpaceObject dso) throws SQLException, IOException { try { unIndexContent(context, dso.getHandle()); } catch (Exception exception) { log.error(exception.getMessage(), exception); emailException(exception); } }
/** * unIndex removes an Item, Collection, or Community * * @param context The relevant DSpace Context. * @param dso DSpace Object, can be Community, Item, or Collection * @param commit if <code>true</code> force an immediate commit on SOLR * @throws SQLException if database error * @throws IOException if IO error */ @Override public void unIndexContent(Context context, DSpaceObject dso, boolean commit) throws SQLException, IOException { try { if (dso == null) { return; } String uniqueID = dso.getType() + "-" + dso.getID(); getSolr().deleteById(uniqueID); if (commit) { getSolr().commit(); } } catch (Exception exception) { log.error(exception.getMessage(), exception); emailException(exception); } }
/** * Build a Lucene document for a DSpace Community. * * @param community Community to be indexed * @throws SQLException * @throws IOException */ private void buildDocument(Community community) throws SQLException, IOException { // Create Document SolrInputDocument doc = buildDocument(Constants.COMMUNITY, community.getID(), community.getHandle(), null); // and populate it String name = community.getMetadata("name"); if (name != null) { doc.addField("name", name); } //Do any additional indexing, depends on the plugins List<SolrServiceIndexPlugin> solrServiceIndexPlugins = new DSpace().getServiceManager().getServicesByType(SolrServiceIndexPlugin.class); for (SolrServiceIndexPlugin solrServiceIndexPlugin : solrServiceIndexPlugins) { solrServiceIndexPlugin.additionalIndex(community, doc); } writeDocument(doc); }
solrQuery.setParam(MoreLikeThisParams.MIN_WORD_LEN, String.valueOf(mltConfig.getMinWordLength())); if (getSolr() == null) { return Collections.emptyList(); QueryResponse rsp = getSolr().query(solrQuery, SolrRequest.METHOD.POST); NamedList mltResults = (NamedList) rsp.getResponse().get("moreLikeThis"); if (mltResults != null && mltResults.get(item.getType() + "-" + item.getID()) != null) { for (Object relatedDoc : relatedDocs) { SolrDocument relatedDocument = (SolrDocument) relatedDoc; DSpaceObject relatedItem = findDSpaceObject(context, relatedDocument); if (relatedItem.getType() == Constants.ITEM) { results.add((Item) relatedItem);