mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-15 14:03:17 +00:00
Merge pull request #9690 from uniba-ub/issue-9660
exclude submitter information in solr indexing
This commit is contained in:
@@ -154,9 +154,11 @@ public class ItemIndexFactoryImpl extends DSpaceObjectIndexFactoryImpl<Indexable
|
|||||||
doc.addField("latestVersion", isLatestVersion(context, item));
|
doc.addField("latestVersion", isLatestVersion(context, item));
|
||||||
|
|
||||||
EPerson submitter = item.getSubmitter();
|
EPerson submitter = item.getSubmitter();
|
||||||
if (submitter != null) {
|
if (submitter != null && !(DSpaceServicesFactory.getInstance().getConfigurationService().getBooleanProperty(
|
||||||
addFacetIndex(doc, "submitter", submitter.getID().toString(),
|
"discovery.index.item.submitter.enabled", false))) {
|
||||||
submitter.getFullName());
|
doc.addField("submitter_authority", submitter.getID().toString());
|
||||||
|
} else if (submitter != null) {
|
||||||
|
addFacetIndex(doc, "submitter", submitter.getID().toString(), submitter.getFullName());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the item metadata
|
// Add the item metadata
|
||||||
|
@@ -8,6 +8,10 @@
|
|||||||
package org.dspace.discovery;
|
package org.dspace.discovery;
|
||||||
|
|
||||||
import static org.dspace.discovery.SolrServiceWorkspaceWorkflowRestrictionPlugin.DISCOVER_WORKSPACE_CONFIGURATION_NAME;
|
import static org.dspace.discovery.SolrServiceWorkspaceWorkflowRestrictionPlugin.DISCOVER_WORKSPACE_CONFIGURATION_NAME;
|
||||||
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
import static org.hamcrest.Matchers.hasItem;
|
||||||
|
import static org.hamcrest.Matchers.hasItems;
|
||||||
|
import static org.hamcrest.Matchers.not;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
@@ -21,6 +25,10 @@ import java.util.List;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import org.apache.solr.client.solrj.SolrQuery;
|
||||||
|
import org.apache.solr.client.solrj.SolrServerException;
|
||||||
|
import org.apache.solr.client.solrj.response.QueryResponse;
|
||||||
|
import org.apache.solr.common.SolrDocument;
|
||||||
import org.dspace.AbstractIntegrationTestWithDatabase;
|
import org.dspace.AbstractIntegrationTestWithDatabase;
|
||||||
import org.dspace.app.launcher.ScriptLauncher;
|
import org.dspace.app.launcher.ScriptLauncher;
|
||||||
import org.dspace.app.scripts.handler.impl.TestDSpaceRunnableHandler;
|
import org.dspace.app.scripts.handler.impl.TestDSpaceRunnableHandler;
|
||||||
@@ -99,6 +107,9 @@ public class DiscoveryIT extends AbstractIntegrationTestWithDatabase {
|
|||||||
MetadataAuthorityService metadataAuthorityService = ContentAuthorityServiceFactory.getInstance()
|
MetadataAuthorityService metadataAuthorityService = ContentAuthorityServiceFactory.getInstance()
|
||||||
.getMetadataAuthorityService();
|
.getMetadataAuthorityService();
|
||||||
|
|
||||||
|
MockSolrSearchCore solrSearchCore = DSpaceServicesFactory.getInstance().getServiceManager()
|
||||||
|
.getServiceByName(null, MockSolrSearchCore.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
@@ -796,6 +807,104 @@ public class DiscoveryIT extends AbstractIntegrationTestWithDatabase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test designed to check if the submitter is not indexed in all in solr documents for items
|
||||||
|
* and the submitter authority is still indexed
|
||||||
|
* @throws SearchServiceException
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void searchWithNoSubmitterTest() throws SearchServiceException {
|
||||||
|
|
||||||
|
configurationService.setProperty("discovery.index.item.submitter.enabled", false);
|
||||||
|
DiscoveryConfiguration defaultConf = SearchUtils.getDiscoveryConfiguration(context, "default", null);
|
||||||
|
|
||||||
|
// Populate the testing objects: create items in eperson's workspace and perform search in it
|
||||||
|
int numberItems = 10;
|
||||||
|
context.turnOffAuthorisationSystem();
|
||||||
|
EPerson submitter = null;
|
||||||
|
try {
|
||||||
|
submitter = EPersonBuilder.createEPerson(context).withEmail("submitter@example.org")
|
||||||
|
.withNameInMetadata("Peter", "Funny").build();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
context.setCurrentUser(submitter);
|
||||||
|
Community community = CommunityBuilder.createCommunity(context).build();
|
||||||
|
Collection collection = CollectionBuilder.createCollection(context, community).build();
|
||||||
|
for (int i = 0; i < numberItems; i++) {
|
||||||
|
ItemBuilder.createItem(context, collection)
|
||||||
|
.withTitle("item " + i)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
context.restoreAuthSystemState();
|
||||||
|
|
||||||
|
// Build query with default parameters (except for workspaceConf)
|
||||||
|
QueryResponse result = null;
|
||||||
|
try {
|
||||||
|
result = solrSearchCore.getSolr().query(new SolrQuery(String.format(
|
||||||
|
"search.resourcetype:\"Item\"")));
|
||||||
|
} catch (SolrServerException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
assertEquals(result.getResults().size(), numberItems);
|
||||||
|
for (SolrDocument doc : result.getResults()) {
|
||||||
|
assertThat(doc.getFieldNames(),
|
||||||
|
not(hasItems("submitter_keyword", "submitter_ac", "submitter_acid", "submitter_filter")));
|
||||||
|
assertThat(doc.getFieldNames(), hasItem("submitter_authority"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test designed to check if the submitter is indexed in all in solr documents for items
|
||||||
|
* @throws SearchServiceException
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void searchWithSubmitterTest() throws SearchServiceException {
|
||||||
|
|
||||||
|
configurationService.setProperty("discovery.index.item.submitter.enabled", true);
|
||||||
|
DiscoveryConfiguration defaultConf = SearchUtils.getDiscoveryConfiguration(context, "default", null);
|
||||||
|
|
||||||
|
// Populate the testing objects: create items in eperson's workspace and perform search in it
|
||||||
|
int numberItems = 10;
|
||||||
|
context.turnOffAuthorisationSystem();
|
||||||
|
EPerson submitter = null;
|
||||||
|
try {
|
||||||
|
submitter = EPersonBuilder.createEPerson(context).withEmail("submitter@example.org")
|
||||||
|
.withNameInMetadata("Peter", "Funny").build();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
context.setCurrentUser(submitter);
|
||||||
|
Community community = CommunityBuilder.createCommunity(context).build();
|
||||||
|
Collection collection = CollectionBuilder.createCollection(context, community).build();
|
||||||
|
for (int i = 0; i < numberItems; i++) {
|
||||||
|
ItemBuilder.createItem(context, collection)
|
||||||
|
.withTitle("item " + i)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
context.restoreAuthSystemState();
|
||||||
|
|
||||||
|
// Build query with default parameters (except for workspaceConf)
|
||||||
|
QueryResponse result = null;
|
||||||
|
try {
|
||||||
|
result = solrSearchCore.getSolr().query(new SolrQuery(String.format(
|
||||||
|
"search.resourcetype:\"Item\"")));
|
||||||
|
} catch (SolrServerException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
assertEquals(result.getResults().size(), numberItems);
|
||||||
|
for (SolrDocument doc : result.getResults()) {
|
||||||
|
for (String fieldname : doc.getFieldNames()) {
|
||||||
|
assertThat(doc.getFieldNames(), hasItems("submitter_keyword","submitter_ac", "submitter_filter",
|
||||||
|
"submitter_authority"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void assertSearchQuery(String resourceType, int size) throws SearchServiceException {
|
private void assertSearchQuery(String resourceType, int size) throws SearchServiceException {
|
||||||
assertSearchQuery(resourceType, size, size, 0, -1);
|
assertSearchQuery(resourceType, size, size, 0, -1);
|
||||||
}
|
}
|
||||||
|
@@ -24,6 +24,11 @@ discovery.search.server = ${solr.server}/${solr.multicorePrefix}search
|
|||||||
# discovery.index.ignore-authority = false
|
# discovery.index.ignore-authority = false
|
||||||
discovery.index.projection=dc.title,dc.contributor.*,dc.date.issued
|
discovery.index.projection=dc.title,dc.contributor.*,dc.date.issued
|
||||||
|
|
||||||
|
# Restricts the indexing of the submitter for archived items
|
||||||
|
# By default the submitter information from the corresponding eperson is not indexed.
|
||||||
|
# If you set this value to true, than the submitter information is indexed and you will need to reindex search core
|
||||||
|
# discovery.index.item.submitter.enabled = false
|
||||||
|
|
||||||
# Allow auto-reindexing.
|
# Allow auto-reindexing.
|
||||||
# If any database migrations are applied to your database (via Flyway), then a
|
# If any database migrations are applied to your database (via Flyway), then a
|
||||||
# reindex flag is always written to '[dspace]/solr/search/conf/reindex.flag'.
|
# reindex flag is always written to '[dspace]/solr/search/conf/reindex.flag'.
|
||||||
@@ -48,4 +53,4 @@ discovery.facet.namedtype.workflow.pooled = 004workflow\n|||\nWaiting for Contro
|
|||||||
# Set the number of retry of a query when stale objects are found.
|
# Set the number of retry of a query when stale objects are found.
|
||||||
# Set to -1 if stale objects should be ignored. Set to 0 if you want to avoid extra query but take the chance to cleanup
|
# Set to -1 if stale objects should be ignored. Set to 0 if you want to avoid extra query but take the chance to cleanup
|
||||||
# the index each time that stale objects are found. Default 3
|
# the index each time that stale objects are found. Default 3
|
||||||
discovery.removestale.attempts = 3
|
discovery.removestale.attempts = 3
|
||||||
|
Reference in New Issue
Block a user