Skip to content

Commit

Permalink
adds a simple api for clearing a single dataset from Solr.
Browse files Browse the repository at this point in the history
I want to have it in order to be able to create an api test for
for a specific OAI set export case. But I figure it could be useful
otherwise. #3437
  • Loading branch information
landreev committed Jan 9, 2024
1 parent 1ab441c commit b8a79a1
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/main/java/edu/harvard/iq/dataverse/api/Index.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public Response clearSolrIndex() {
return error(Status.INTERNAL_SERVER_ERROR, ex.getLocalizedMessage());
}
}

@GET
@Path("{type}/{id}")
public Response indexTypeById(@PathParam("type") String type, @PathParam("id") Long id) {
Expand Down Expand Up @@ -326,6 +326,29 @@ public Response indexDatasetByPersistentId(@QueryParam("persistentId") String pe
}
}

/**
* Clears the entry for a dataset from Solr
*
* @param id numer id of the dataset
* @return response;
* will return 404 if no such dataset in the database; but will attempt to
* clear the entry from Solr regardless.
*/
@DELETE
@Path("datasets/clear/{id}")
public Response clearDatasetFromIndex(@PathParam("id") Long id) {
Dataset dataset = datasetService.find(id);
// We'll attempt to delete the Solr document regardless of whether the
// dataset exists in the database:
String response = indexService.removeSolrDocFromIndex(IndexServiceBean.solrDocIdentifierDataset + id);
if (dataset != null) {
return ok("Sent request to clear Solr document for dataset " + id + ": " + response);
} else {
return notFound("Could not find dataset " + id + " in the database. Requested to clear from Solr anyway: " + response);
}
}


/**
* This is just a demo of the modular math logic we use for indexAll.
*/
Expand Down

0 comments on commit b8a79a1

Please sign in to comment.