Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
import org.mycore.frontend.classeditor.json.MCRJSONCategoryHelper;
import org.mycore.frontend.classeditor.wrapper.MCRCategoryListWrapper;
import org.mycore.frontend.jersey.filter.access.MCRRestrictedAccess;
import org.mycore.solr.MCRSolrCoreManager;
import org.mycore.solr.MCRSolrIndexManager;
import org.mycore.solr.MCRSolrUtils;
import org.mycore.solr.auth.MCRSolrAuthenticationLevel;
import org.mycore.solr.auth.MCRSolrAuthenticationManager;
Expand Down Expand Up @@ -263,7 +263,7 @@ public Response importClassification(@FormDataParam("classificationFile") InputS
@Path("filter/{text}")
@Produces(MediaType.APPLICATION_JSON)
public Response filter(@PathParam("text") String text) {
SolrClient solrClient = MCRSolrClassificationUtil.getCore().getClient();
SolrClient solrClient = MCRSolrClassificationUtil.getIndexList().getFirst().getClient();
ModifiableSolrParams p = new ModifiableSolrParams();
p.set("q", "allMeta:" + "*" + MCRSolrUtils.escapeSearchValue(text) + "*");
p.set("fl", "id,ancestors");
Expand All @@ -289,7 +289,7 @@ public Response filter(@PathParam("text") String text) {
public Response retrieveLinkedObjects(@PathParam("id") String id, @QueryParam("start") Integer start,
@QueryParam("rows") Integer rows) throws SolrServerException, IOException {
// do solr query
SolrClient solrClient = MCRSolrCoreManager.getMainSolrClient();
SolrClient solrClient = MCRSolrIndexManager.obtainInstance().requireMainIndex().getClient();
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("start", start != null ? start : 0);
params.set("rows", rows != null ? rows : 50);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.solr.client.solrj.SolrClient;
import org.mycore.access.MCRAccessException;
import org.mycore.common.MCRUtils;
import org.mycore.datamodel.classifications2.utils.MCRClassificationUtils;
Expand All @@ -42,8 +43,8 @@
import org.mycore.frontend.cli.annotation.MCRCommand;
import org.mycore.frontend.cli.annotation.MCRCommandGroup;
import org.mycore.services.packaging.MCRPackerManager;
import org.mycore.solr.MCRSolrCoreManager;
import org.mycore.solr.MCRSolrCoreType;
import org.mycore.solr.MCRIndexType;
import org.mycore.solr.MCRSolrIndexManager;
import org.mycore.solr.index.MCRSolrIndexer;
import org.mycore.solr.search.MCRSolrSearchUtils;

Expand All @@ -56,7 +57,8 @@ public class MCRTransferPackageCommands {
@MCRCommand(help = "Creates multiple transfer packages which matches the solr query in {0}.",
syntax = "create transfer package for objects matching {0}")
public static void create(String query) throws MCRAccessException {
List<String> ids = MCRSolrSearchUtils.listIDs(MCRSolrCoreManager.getMainSolrClient(), query);
SolrClient solrClient = MCRSolrIndexManager.obtainInstance().requireMainIndex().getClient();
List<String> ids = MCRSolrSearchUtils.listIDs(solrClient, query);
for (String objectId : ids) {
Map<String, String> parameters = new HashMap<>();
parameters.put("packer", "TransferPackage");
Expand Down Expand Up @@ -190,7 +192,8 @@ public static void cleanUp(String targetDirectoryPath) throws Exception {
markManager.remove(MCRObjectID.getInstance(id));
}
// index all objects
MCRSolrIndexer.rebuildMetadataIndex(mcrObjects, MCRSolrCoreManager.getCoresForType(MCRSolrCoreType.MAIN));
MCRSolrIndexer.rebuildMetadataIndex(mcrObjects, MCRSolrIndexManager.obtainInstance()
.getIndexWithType(MCRIndexType.MAIN));

// deleting expanded directory
LOGGER.info("Deleting expanded tar in {}...", targetDirectoryPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.client.solrj.request.SolrQuery;
Expand All @@ -47,7 +49,7 @@
import org.mycore.common.config.MCRConfiguration2;
import org.mycore.datamodel.common.MCRObjectIDDate;
import org.mycore.datamodel.ifs2.MCRObjectIDDateImpl;
import org.mycore.solr.MCRSolrCoreManager;
import org.mycore.solr.MCRSolrIndexManager;
import org.mycore.solr.auth.MCRSolrAuthenticationLevel;
import org.mycore.solr.auth.MCRSolrAuthenticationManager;

Expand Down Expand Up @@ -182,7 +184,8 @@ public int checkSitemapFile() throws IOException {
QueryRequest queryRequest = new QueryRequest(query);
SOLR_AUTHENTICATION_MANAGER.applyAuthentication(queryRequest,
MCRSolrAuthenticationLevel.SEARCH);
response = queryRequest.process(MCRSolrCoreManager.getMainSolrClient());
SolrClient client = MCRSolrIndexManager.obtainInstance().requireMainIndex().getClient();
response = queryRequest.process(client);
objidlist = response.getResults().stream().map((document) -> {
String id = (String) document.getFieldValue("id");
Date modified = (Date) document.getFieldValue("modified");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.mycore.frontend.jersey.MCRJerseyUtil;
import org.mycore.solr.MCRSolrCoreManager;
import org.mycore.solr.MCRSolrIndexManager;
import org.mycore.solr.auth.MCRSolrAuthenticationLevel;
import org.mycore.solr.auth.MCRSolrAuthenticationManager;

Expand Down Expand Up @@ -118,7 +118,8 @@ public Response query(@PathParam("derivateId") String derivateId, @QueryParam("q
try {
QueryRequest queryRequest = new QueryRequest(p);
SOLR_AUTHENTICATION_MANAGER.applyAuthentication(queryRequest, MCRSolrAuthenticationLevel.SEARCH);
QueryResponse solrResponse = queryRequest.process(MCRSolrCoreManager.getMainSolrClient());
QueryResponse solrResponse =
queryRequest.process(MCRSolrIndexManager.obtainInstance().requireMainIndex().getClient());
JsonArray response = buildQueryResponse(solrResponse.getHighlighting());
return Response.ok().entity(new Gson().toJson(response)).build();
} catch (Exception exc) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@
import org.apache.solr.common.params.ModifiableSolrParams;
import org.jdom2.Element;
import org.mycore.common.MCRSystemUserInformation;
import org.mycore.common.config.MCRConfiguration2;
import org.mycore.datamodel.metadata.MCRMetadataManager;
import org.mycore.datamodel.metadata.MCRObject;
import org.mycore.datamodel.metadata.MCRObjectID;
import org.mycore.mcr.cronjob.MCRCronjob;
import org.mycore.solr.MCRSolrCoreManager;
import org.mycore.solr.MCRSolrIndexManager;
import org.mycore.solr.auth.MCRSolrAuthenticationLevel;
import org.mycore.solr.auth.MCRSolrAuthenticationManager;
import org.mycore.util.concurrent.MCRFixedUserFailableRunnable;
Expand All @@ -58,7 +57,7 @@ public String getDescription() {
@Override
public void runJob() {

if (MCRConfiguration2.getString("MCR.Solr.ServerURL").isEmpty()) {
if(MCRSolrIndexManager.obtainInstance().getMainIndex().isPresent()) {
return;
}

Expand All @@ -81,7 +80,8 @@ public void runJob() {

QueryRequest queryRequest = new QueryRequest(params);
SOLR_AUTHENTICATION_MANAGER.applyAuthentication(queryRequest, MCRSolrAuthenticationLevel.SEARCH);
QueryResponse solrResponse = queryRequest.process(MCRSolrCoreManager.getMainSolrClient());
QueryResponse solrResponse =
queryRequest.process(MCRSolrIndexManager.obtainInstance().requireMainIndex().getClient());
solrResponse
.getResults()
.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
import org.mycore.datamodel.metadata.MCRObject;
import org.mycore.datamodel.metadata.MCRObjectID;
import org.mycore.mods.MCRMODSWrapper;
import org.mycore.solr.MCRSolrCoreManager;
import org.mycore.solr.MCRSolrIndexManager;
import org.mycore.solr.MCRSolrUtils;
import org.mycore.solr.auth.MCRSolrAuthenticationLevel;
import org.mycore.solr.auth.MCRSolrAuthenticationManager;
Expand Down Expand Up @@ -220,7 +220,7 @@ private String getPublicationID(SyndEntry entry) {
}

private boolean isAlreadyStored(String publicationID) {
SolrClient solrClient = MCRSolrCoreManager.getMainSolrClient();
SolrClient solrClient = MCRSolrIndexManager.obtainInstance().requireMainIndex().getClient();
SolrQuery query = new SolrQuery();
query.setQuery(field2queryID + ":" + MCRSolrUtils.escapeSearchValue(publicationID));
query.setRows(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
import org.mycore.oai.set.MCROAISetResolver;
import org.mycore.oai.set.MCROAISolrSetHandler;
import org.mycore.oai.set.MCRSet;
import org.mycore.solr.MCRSolrCoreManager;
import org.mycore.solr.MCRSolrIndexManager;
import org.mycore.solr.MCRSolrUtils;
import org.mycore.solr.auth.MCRSolrAuthenticationLevel;
import org.mycore.solr.auth.MCRSolrAuthenticationManager;
Expand Down Expand Up @@ -87,7 +87,7 @@ public Optional<Header> getHeader(String mcrId) {
query.set(CommonParams.Q, "id:" + MCRSolrUtils.escapeSearchValue(mcrId));
query.setRows(1);
// do the query
SolrClient solrClient = MCRSolrCoreManager.getMainSolrClient();
SolrClient solrClient = MCRSolrIndexManager.obtainInstance().requireMainIndex().getClient();
try {
QueryRequest queryRequest = new QueryRequest(query);
queryRequest.setPath(getRequestHandlerPath());
Expand Down Expand Up @@ -159,7 +159,7 @@ protected MCROAISolrResult solrQuery(Optional<String> cursor) throws SolrServerE
query.set(CommonParams.SORT, "id asc");

// do the query
SolrClient solrClient = MCRSolrCoreManager.getMainSolrClient();
SolrClient solrClient = MCRSolrIndexManager.obtainInstance().requireMainIndex().getClient();
QueryRequest queryRequest = new QueryRequest(query);
queryRequest.setPath(getRequestHandlerPath());
MCRSolrAuthenticationManager.obtainInstance().applyAuthentication(queryRequest,
Expand Down Expand Up @@ -270,7 +270,7 @@ public Optional<Instant> getEarliestTimestamp() {
params.add(CommonParams.FQ, fieldName + ":[* TO *]");
params.add(CommonParams.FL, fieldName);
params.add(CommonParams.ROWS, "1");
SolrClient solrClient = MCRSolrCoreManager.getMainSolrClient();
SolrClient solrClient = MCRSolrIndexManager.obtainInstance().requireMainIndex().getClient();
try {
QueryRequest queryRequest = new QueryRequest(params);
MCRSolrAuthenticationManager.obtainInstance().applyAuthentication(queryRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.mycore.common.config.MCRConfiguration2;
import org.mycore.oai.MCROAIUtils;
import org.mycore.oai.classmapping.MCRClassificationAndSetMapper;
import org.mycore.solr.MCRSolrCoreManager;
import org.mycore.solr.MCRSolrIndexManager;
import org.mycore.solr.MCRSolrUtils;
import org.mycore.solr.auth.MCRSolrAuthenticationLevel;
import org.mycore.solr.auth.MCRSolrAuthenticationManager;
Expand Down Expand Up @@ -70,7 +70,7 @@ public boolean filter(MCRSet set) {
if (!filterEmptySets()) {
return false;
}
SolrClient solrClient = MCRSolrCoreManager.getMainSolrClient();
SolrClient solrClient = MCRSolrIndexManager.obtainInstance().requireMainIndex().getClient();
ModifiableSolrParams p = new ModifiableSolrParams();
String value = set.getSpec();
p.set(CommonParams.Q, MCROAIUtils.getDefaultSetQuery(value, getConfigPrefix()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import org.mycore.common.MCRException;
import org.mycore.common.config.MCRConfiguration2;
import org.mycore.oai.pmh.Set;
import org.mycore.solr.MCRSolrCoreManager;
import org.mycore.solr.MCRSolrIndexManager;
import org.mycore.solr.MCRSolrUtils;
import org.mycore.solr.auth.MCRSolrAuthenticationLevel;
import org.mycore.solr.auth.MCRSolrAuthenticationManager;
Expand Down Expand Up @@ -63,7 +63,7 @@ public void init(String configPrefix, String setId, Map<String, MCRSet> setMap,
idsInSet = Collections.emptySet();
return;
}
SolrClient solrClient = MCRSolrCoreManager.getMainSolrClient();
SolrClient solrClient = MCRSolrIndexManager.obtainInstance().requireMainIndex().getClient();
QueryResponse response;
try {
QueryRequest queryRequest = new QueryRequest(getQuery());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
import org.mycore.frontend.jersey.MCRCacheControl;
import org.mycore.restapi.v1.errors.MCRRestAPIError;
import org.mycore.restapi.v1.errors.MCRRestAPIException;
import org.mycore.solr.MCRSolrCoreManager;
import org.mycore.solr.MCRSolrIndexManager;
import org.mycore.solr.auth.MCRSolrAuthenticationLevel;
import org.mycore.solr.auth.MCRSolrAuthenticationManager;

Expand Down Expand Up @@ -513,7 +513,7 @@ private String writeJSON(Element eRoot, String lang, String style) throws IOExce
}

private void filterNonEmpty(String classId, Element e) {
SolrClient solrClient = MCRSolrCoreManager.getMainSolrClient();
SolrClient solrClient = MCRSolrIndexManager.obtainInstance().requireMainIndex().getClient();
Element[] categories = e.getChildren(ELEMENT_CATEGORY).toArray(Element[]::new);
for (Element cat : categories) {
SolrQuery solrQuery = new SolrQuery();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@
import static org.mycore.frontend.jersey.MCRJerseyUtil.TEXT_XML_UTF_8;

import java.io.IOException;
import java.net.URI;
import java.net.URLEncoder;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.io.InputStream;
import java.util.List;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.mycore.services.http.MCRHttpUtils;
import org.mycore.solr.MCRSolrCoreManager;
import org.mycore.solr.MCRSolrUtils;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.mycore.solr.MCRSolrIndex;
import org.mycore.solr.MCRSolrIndexManager;
import org.mycore.solr.auth.MCRSolrAuthenticationLevel;
import org.mycore.solr.auth.MCRSolrAuthenticationManager;
import org.mycore.solr.search.MCRSolrSearchUtils;

import jakarta.ws.rs.DefaultValue;
import jakarta.ws.rs.GET;
Expand Down Expand Up @@ -83,68 +83,64 @@ public class MCRRestAPISearch {
@SuppressWarnings("PMD.ExcessiveParameterList")
@GET
@Produces({ TEXT_XML_UTF_8, APPLICATION_JSON_UTF_8, TEXT_PLAIN_ISO_8859_1, TEXT_PLAIN_UTF_8 })
public Response search(@QueryParam("q") String query,
@QueryParam("sort") String sort, @QueryParam("wt") @DefaultValue("xml") String wt,
@QueryParam("start") String start, @QueryParam("rows") String rows,
@QueryParam("fq") List<String> fq, @QueryParam("fl") List<String> fl,
public Response search(@QueryParam(CommonParams.Q) String query,
@QueryParam(CommonParams.SORT) String sort, @QueryParam(CommonParams.WT) @DefaultValue("xml") String wt,
@QueryParam(CommonParams.START) String start, @QueryParam(CommonParams.ROWS) String rows,
@QueryParam(CommonParams.FQ) List<String> fq, @QueryParam(CommonParams.FL) List<String> fl,
@QueryParam("facet") String facet, @QueryParam("facet.sort") String facetSort,
@QueryParam("facet.limit") String facetLimit, @QueryParam("facet.field") List<String> facetFields,
@QueryParam("facet.mincount") String facetMinCount,
@QueryParam("json.wrf") String jsonWrf) {
StringBuilder url = new StringBuilder(MCRSolrCoreManager.getMainSolrCore().getV1CoreURL());
url.append("/select?");
ModifiableSolrParams params = new ModifiableSolrParams();


// Append query parameters using helper methods
appendQueryParam(url, "q", query);
appendQueryParam(url, "sort", sort);
appendQueryParam(url, "wt", wt);
appendQueryParam(url, "start", start);
appendQueryParam(url, "rows", rows);

appendListQueryParam(url, "fq", fq);
appendListQueryParam(url, "fl", fl);

appendQueryParam(url, "facet", facet);
appendQueryParam(url, "facet.sort", facetSort);
appendQueryParam(url, "facet.limit", facetLimit);
appendQueryParam(url, "facet.mincount", facetMinCount);
appendListQueryParam(url, "facet.field", facetFields);
appendQueryParam(url, "json.wrf", jsonWrf);

return executeSolrQuery(url.toString(), wt);
appendQueryParam(params, CommonParams.Q, query);
appendQueryParam(params, CommonParams.SORT, sort);
appendQueryParam(params, CommonParams.WT, wt);
appendQueryParam(params, CommonParams.START, start);
appendQueryParam(params, CommonParams.ROWS, rows);

appendListQueryParam(params, CommonParams.FQ, fq);
appendListQueryParam(params, CommonParams.FL, fl);

appendQueryParam(params, "facet", facet);
appendQueryParam(params, "facet.sort", facetSort);
appendQueryParam(params, "facet.limit", facetLimit);
appendQueryParam(params, "facet.mincount", facetMinCount);
appendListQueryParam(params, "facet.field", facetFields);
appendQueryParam(params, "json.wrf", jsonWrf);

return executeSolrQuery(params, wt);
}

// Helper method to append single query parameters
private void appendQueryParam(StringBuilder url, String param, String value) {
private void appendQueryParam(ModifiableSolrParams params, String param, String value) {
if (value != null) {
url.append('&').append(param).append('=')
.append(URLEncoder.encode(value, StandardCharsets.UTF_8));
params.set(param, value);
}
}

// Helper method to append list-based query parameters
private void appendListQueryParam(StringBuilder url, String param, List<String> values) {
if (values != null) {
for (String value : values) {
appendQueryParam(url, param, value);
}
private void appendListQueryParam(ModifiableSolrParams params, String param, List<String> values) {
if (values != null && !values.isEmpty()) {
params.add(param, values.toArray(new String[0]));
}
}

// Method to execute the Solr query and handle response
private Response executeSolrQuery(String url, String wt) {
HttpRequest.Builder reqBuilder = MCRSolrUtils.getRequestBuilder().uri(URI.create(url));
MCRSolrAuthenticationManager.obtainInstance().applyAuthentication(reqBuilder,
private Response executeSolrQuery(ModifiableSolrParams params, String wt) {
MCRSolrIndex solrIndex = MCRSolrIndexManager.obtainInstance().requireMainIndex();
SolrClient client = solrIndex.getClient();
QueryRequest queryRequest = new QueryRequest(params);
MCRSolrAuthenticationManager.obtainInstance().applyAuthentication(queryRequest,
MCRSolrAuthenticationLevel.SEARCH);
HttpRequest request = reqBuilder.build();

try (HttpClient client = MCRHttpUtils.getHttpClient()) {
HttpResponse<String> resp =
client.send(request, HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8));
return Response.ok(resp.body())
try (InputStream is = MCRSolrSearchUtils.streamRequest(client, queryRequest, wt)) {
return Response.ok(is.readAllBytes())
.type(getContentType(wt))
.build();
} catch (InterruptedException | IOException e) {
} catch (IOException | SolrServerException e) {
LOGGER.error("Error while executing Solr query", e);
return Response.status(Response.Status.BAD_REQUEST).build();
}
Expand Down
Loading
Loading