Skip to content

Commit

Permalink
WIP [HTM-1076][HTM-1077] TMFeatureType event handler to propagate cha…
Browse files Browse the repository at this point in the history
…nges to solr indexes
  • Loading branch information
mprins committed Jun 13, 2024
1 parent 6cc4386 commit 06a2695
Show file tree
Hide file tree
Showing 7 changed files with 260 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.io.IOException;
import java.io.Serializable;
import java.lang.invoke.MethodHandles;
import java.util.concurrent.TimeUnit;
import nl.b3p.tailormap.api.annotation.AppRestController;
import nl.b3p.tailormap.api.persistence.Application;
import nl.b3p.tailormap.api.persistence.GeoService;
Expand All @@ -21,10 +20,10 @@
import nl.b3p.tailormap.api.persistence.json.GeoServiceLayer;
import nl.b3p.tailormap.api.repository.SearchIndexRepository;
import nl.b3p.tailormap.api.solr.SolrHelper;
import nl.b3p.tailormap.api.solr.SolrService;
import nl.b3p.tailormap.api.viewer.model.SearchResponse;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.Http2SolrClient;
import org.apache.solr.common.SolrException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -50,17 +49,14 @@ public class SearchController {

private final SearchIndexRepository searchIndexRepository;

@Value("${tailormap-api.solr-url}")
private String solrUrl;

@Value("${tailormap-api.solr-core-name:tailormap}")
private String solrCoreName;

@Value("${tailormap-api.pageSize:100}")
private int numResultsToReturn;

public SearchController(SearchIndexRepository searchIndexRepository) {
private final SolrService solrService;

public SearchController(SearchIndexRepository searchIndexRepository, SolrService solrService) {

Check warning on line 57 in src/main/java/nl/b3p/tailormap/api/controller/SearchController.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/nl/b3p/tailormap/api/controller/SearchController.java#L57

Added line #L57 was not covered by tests
this.searchIndexRepository = searchIndexRepository;
this.solrService = solrService;

Check warning on line 59 in src/main/java/nl/b3p/tailormap/api/controller/SearchController.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/nl/b3p/tailormap/api/controller/SearchController.java#L59

Added line #L59 was not covered by tests
}

@Transactional(readOnly = true)
Expand Down Expand Up @@ -90,7 +86,7 @@ public ResponseEntity<Serializable> search(
"Layer '%s' does not have a search index"
.formatted(appTreeLayerNode.getLayerName())));

try (SolrClient solrClient = getSolrClient();
try (SolrClient solrClient = solrService.getSolrClientForSearching();

Check warning on line 89 in src/main/java/nl/b3p/tailormap/api/controller/SearchController.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/nl/b3p/tailormap/api/controller/SearchController.java#L89

Added line #L89 was not covered by tests
SolrHelper solrHelper = new SolrHelper(solrClient)) {
final SearchResponse searchResponse =
solrHelper.findInIndex(searchIndex, solrQuery, start, numResultsToReturn);
Expand All @@ -107,11 +103,4 @@ public ResponseEntity<Serializable> search(
HttpStatus.BAD_REQUEST, "Error while searching with given query", e);
}
}

private SolrClient getSolrClient() {
return new Http2SolrClient.Builder(solrUrl + solrCoreName)
.withConnectionTimeout(10, TimeUnit.SECONDS)
.withFollowRedirects(true)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.NoSuchElementException;
import java.util.concurrent.TimeUnit;
import nl.b3p.tailormap.api.geotools.featuresources.FeatureSourceFactoryHelper;
import nl.b3p.tailormap.api.persistence.SearchIndex;
import nl.b3p.tailormap.api.persistence.TMFeatureType;
Expand All @@ -23,11 +22,10 @@
import nl.b3p.tailormap.api.repository.GeoServiceRepository;
import nl.b3p.tailormap.api.repository.SearchIndexRepository;
import nl.b3p.tailormap.api.solr.SolrHelper;
import nl.b3p.tailormap.api.solr.SolrService;
import nl.b3p.tailormap.api.viewer.model.ErrorResponse;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.ConcurrentUpdateHttp2SolrClient;
import org.apache.solr.client.solrj.impl.Http2SolrClient;
import org.apache.solr.client.solrj.response.SolrPingResponse;
import org.apache.solr.common.SolrException;
import org.slf4j.Logger;
Expand Down Expand Up @@ -61,18 +59,21 @@ public class SolrAdminController {
private final FeatureTypeRepository featureTypeRepository;
private final GeoServiceRepository geoServiceRepository;
private final SearchIndexRepository searchIndexRepository;
private final SolrService solrService;

public SolrAdminController(
FeatureSourceFactoryHelper featureSourceFactoryHelper,
FeatureSourceRepository featureSourceRepository,
FeatureTypeRepository featureTypeRepository,
GeoServiceRepository geoServiceRepository,
SearchIndexRepository searchIndexRepository) {
SearchIndexRepository searchIndexRepository,
SolrService solrService) {

Check warning on line 70 in src/main/java/nl/b3p/tailormap/api/controller/admin/SolrAdminController.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/nl/b3p/tailormap/api/controller/admin/SolrAdminController.java#L70

Added line #L70 was not covered by tests
this.featureSourceFactoryHelper = featureSourceFactoryHelper;
this.featureSourceRepository = featureSourceRepository;
this.featureTypeRepository = featureTypeRepository;
this.geoServiceRepository = geoServiceRepository;
this.searchIndexRepository = searchIndexRepository;
this.solrService = solrService;

Check warning on line 76 in src/main/java/nl/b3p/tailormap/api/controller/admin/SolrAdminController.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/nl/b3p/tailormap/api/controller/admin/SolrAdminController.java#L76

Added line #L76 was not covered by tests
}

/**
Expand All @@ -99,7 +100,7 @@ public SolrAdminController(
path = "${tailormap-api.admin.base-path}/index/ping",
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> pingSolr() {
try (SolrClient solrClient = getSolrClient()) {
try (SolrClient solrClient = solrService.getSolrClientForIndexing()) {

Check warning on line 103 in src/main/java/nl/b3p/tailormap/api/controller/admin/SolrAdminController.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/nl/b3p/tailormap/api/controller/admin/SolrAdminController.java#L103

Added line #L103 was not covered by tests
final SolrPingResponse ping = solrClient.ping();
logger.info("Solr ping status {}", ping.getResponse().get("status"));
return ResponseEntity.ok(
Expand All @@ -118,24 +119,6 @@ public ResponseEntity<?> pingSolr() {
}
}

/**
* Get a concurrent update Solr client for bulk operations.
*
* @return the Solr client
*/
private SolrClient getSolrClient() {
return new ConcurrentUpdateHttp2SolrClient.Builder(
solrUrl + solrCoreName,
new Http2SolrClient.Builder()
.withFollowRedirects(true)
.withConnectionTimeout(10000, TimeUnit.MILLISECONDS)
.withRequestTimeout(60000, TimeUnit.MILLISECONDS)
.build())
.withQueueSize(SolrHelper.SOLR_BATCH_SIZE * 2)
.withThreadCount(10)
.build();
}

/**
* (re-) Index a layer.
*
Expand Down Expand Up @@ -185,7 +168,7 @@ public ResponseEntity<?> index(@PathVariable Long searchIndexId) {
boolean createNewIndex =
(null == searchIndex.getLastIndexed()
|| searchIndex.getStatus() == SearchIndex.Status.INITIAL);
try (SolrClient solrClient = getSolrClient();
try (SolrClient solrClient = solrService.getSolrClientForIndexing();

Check warning on line 171 in src/main/java/nl/b3p/tailormap/api/controller/admin/SolrAdminController.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/nl/b3p/tailormap/api/controller/admin/SolrAdminController.java#L171

Added line #L171 was not covered by tests
SolrHelper solrHelper = new SolrHelper(solrClient)) {
solrHelper.addFeatureTypeIndex(searchIndex, indexingFT, featureSourceFactoryHelper);
searchIndexRepository.save(searchIndex);
Expand Down Expand Up @@ -234,7 +217,7 @@ public ResponseEntity<?> index(@PathVariable Long searchIndexId) {
produces = MediaType.APPLICATION_JSON_VALUE)
@Transactional
public ResponseEntity<?> clearIndex(@PathVariable Long searchIndexId) {
try (SolrClient solrClient = getSolrClient();
try (SolrClient solrClient = solrService.getSolrClientForIndexing();

Check warning on line 220 in src/main/java/nl/b3p/tailormap/api/controller/admin/SolrAdminController.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/nl/b3p/tailormap/api/controller/admin/SolrAdminController.java#L220

Added line #L220 was not covered by tests
SolrHelper solrHelper = new SolrHelper(solrClient)) {
solrHelper.clearIndexForLayer(searchIndexId);
// do not delete the SearchIndex metadata object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,17 @@ public interface GeoServiceRepository extends JpaRepository<GeoService, String>
@PreAuthorize("permitAll()")
@Query("from GeoService s where id not in :ids")
List<GeoService> getAllExcludingIds(@Param("ids") List<String> ids);

/**
* Find all geo-services that have a layer that is linked to a specific (Solr) index.
*
* @param indexId The index id to search for
*/
@NonNull
@PreAuthorize("permitAll()")
@Query(
value =
"select * from geo_service gs, lateral jsonb_path_query(gs.settings, ('$.layerSettings.**{1}.searchIndex.searchIndexId ? (@ == '||:indexId||')')::jsonpath)",
nativeQuery = true)
List<GeoService> findByIndexId(@Param("indexId") @NonNull Long indexId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/*
* Copyright (C) 2024 B3Partners B.V.
*
* SPDX-License-Identifier: MIT
*/
package nl.b3p.tailormap.api.repository.events;

import java.io.IOException;
import java.lang.invoke.MethodHandles;
import nl.b3p.tailormap.api.geotools.featuresources.FeatureSourceFactoryHelper;
import nl.b3p.tailormap.api.persistence.SearchIndex;
import nl.b3p.tailormap.api.persistence.TMFeatureType;
import nl.b3p.tailormap.api.repository.GeoServiceRepository;
import nl.b3p.tailormap.api.repository.SearchIndexRepository;
import nl.b3p.tailormap.api.solr.SolrHelper;
import nl.b3p.tailormap.api.solr.SolrService;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.common.SolrException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.rest.core.annotation.HandleAfterDelete;
import org.springframework.data.rest.core.annotation.HandleBeforeSave;
import org.springframework.data.rest.core.annotation.RepositoryEventHandler;

/** Event handler for Solr indexes when a {@code TMFeatureType} is updated or deleted. */
@RepositoryEventHandler
public class SolrTMFeatureTypeEventHandler {

private static final Logger logger =
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

Check warning on line 30 in src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java#L29-L30

Added lines #L29 - L30 were not covered by tests

private final SearchIndexRepository searchIndexRepository;
private final SolrService solrService;
private final FeatureSourceFactoryHelper featureSourceFactoryHelper;
private final GeoServiceRepository geoServiceRepository;

public SolrTMFeatureTypeEventHandler(
SearchIndexRepository searchIndexRepository,
SolrService solrService,
FeatureSourceFactoryHelper featureSourceFactoryHelper,
GeoServiceRepository geoServiceRepository) {
this.searchIndexRepository = searchIndexRepository;
this.solrService = solrService;
this.featureSourceFactoryHelper = featureSourceFactoryHelper;
this.geoServiceRepository = geoServiceRepository;
}

Check warning on line 46 in src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java#L41-L46

Added lines #L41 - L46 were not covered by tests

/**
* Handle the update of a TMFeatureType.
*
* @param tmFeatureType the TMFeatureType to handle
*/
@HandleBeforeSave
public void handleTMFeatureTypeUpdate(TMFeatureType tmFeatureType) {
logger.debug("Handling TMFeatureType save event for: {}", tmFeatureType);

Check warning on line 55 in src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java#L55

Added line #L55 was not covered by tests
// determine if it is a new FT or an update
if (null == tmFeatureType.getId()) {
// do nothing as there is no index defined for a new feature type
logger.debug("New TMFeatureType: {}", tmFeatureType);

Check warning on line 59 in src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java#L59

Added line #L59 was not covered by tests
} else {
logger.debug("Updated TMFeatureType: {}", tmFeatureType);
searchIndexRepository.findByFeatureTypeId(tmFeatureType.getId()).stream()
.findAny()
.ifPresent(

Check warning on line 64 in src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java#L61-L64

Added lines #L61 - L64 were not covered by tests
searchIndex -> {
logger.debug(

Check warning on line 66 in src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java#L66

Added line #L66 was not covered by tests
"Updating search index {} for feature type: {}",
searchIndex.getName(),

Check warning on line 68 in src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java#L68

Added line #L68 was not covered by tests
searchIndex);

try (SolrHelper solrHelper =
new SolrHelper(solrService.getSolrClientForIndexing())) {
solrHelper.addFeatureTypeIndex(

Check warning on line 73 in src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java#L71-L73

Added lines #L71 - L73 were not covered by tests
searchIndex, tmFeatureType, featureSourceFactoryHelper);
} catch (UnsupportedOperationException

Check warning on line 75 in src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java#L75

Added line #L75 was not covered by tests
| IOException
| SolrServerException
| SolrException e) {
logger.error("Error re-indexing", e);
searchIndex.setStatus(SearchIndex.Status.ERROR);
searchIndexRepository.save(searchIndex);
}
});

Check warning on line 83 in src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java#L79-L83

Added lines #L79 - L83 were not covered by tests
}
}

Check warning on line 85 in src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java#L85

Added line #L85 was not covered by tests

/**
* Handle the deletion of a TMFeatureType.
*
* @param tmFeatureType the TMFeatureType to handle
*/
@HandleAfterDelete
public void handleTMFeatureTypeDeleteForSolr(TMFeatureType tmFeatureType) {
logger.debug("Handling TMFeatureType delete event for: {}", tmFeatureType);
searchIndexRepository.findByFeatureTypeId(tmFeatureType.getId()).stream()
.findAny()
.ifPresent(

Check warning on line 97 in src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java#L94-L97

Added lines #L94 - L97 were not covered by tests
searchIndex -> {
logger.info(

Check warning on line 99 in src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java#L99

Added line #L99 was not covered by tests
"Deleting search index {} for feature type: {}",
searchIndex.getName(),

Check warning on line 101 in src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java#L101

Added line #L101 was not covered by tests
searchIndex);

try (SolrHelper solrHelper = new SolrHelper(solrService.getSolrClientForIndexing())) {
solrHelper.clearIndexForLayer(searchIndex.getId());
searchIndexRepository.delete(searchIndex);

Check warning on line 106 in src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java#L104-L106

Added lines #L104 - L106 were not covered by tests
// find layers that use this index in the layer settings and clear them
geoServiceRepository
.findByIndexId(searchIndex.getId())
.forEach(

Check warning on line 110 in src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java#L108-L110

Added lines #L108 - L110 were not covered by tests
geoService ->
geoService
.getLayers()
.forEach(

Check warning on line 114 in src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java#L112-L114

Added lines #L112 - L114 were not covered by tests
layer -> {
logger.debug(

Check warning on line 116 in src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java#L116

Added line #L116 was not covered by tests
"Checking layer {} for search index {}",
layer.getName(),
searchIndex.getName());
geoService
.findSearchIndexForLayer(layer, searchIndexRepository)
.ifPresent(

Check warning on line 122 in src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java#L118-L122

Added lines #L118 - L122 were not covered by tests
searchIndex1 -> {
if (searchIndex1
.getId()

Check warning on line 125 in src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java#L124-L125

Added lines #L124 - L125 were not covered by tests
.equals(searchIndex.getId())) {
logger.debug(

Check warning on line 127 in src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java#L127

Added line #L127 was not covered by tests
"Clearing search index for layer {}",
layer.getName());
geoService
.getLayerSettings(layer.getName())
.setSearchIndex(null);
geoServiceRepository.save(geoService);

Check warning on line 133 in src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java#L129-L133

Added lines #L129 - L133 were not covered by tests
}
});
}));
} catch (UnsupportedOperationException

Check warning on line 137 in src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java#L135-L137

Added lines #L135 - L137 were not covered by tests
| IOException
| SolrServerException
| SolrException e) {
logger.error("Error deleting index for {}", searchIndex, e);
}
});
}

Check warning on line 144 in src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/nl/b3p/tailormap/api/repository/events/SolrTMFeatureTypeEventHandler.java#L141-L144

Added lines #L141 - L144 were not covered by tests
}
2 changes: 1 addition & 1 deletion src/main/java/nl/b3p/tailormap/api/solr/SolrHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class SolrHelper implements AutoCloseable, Constants {
/**
* Constructor
*
* @param solrClient the Solr client, this will be closed when this class is closed
* @param solrClient the Solr client, this client will be closed when this class is closed.
*/
public SolrHelper(@NotNull SolrClient solrClient) {
this.solrClient = solrClient;
Expand Down
52 changes: 52 additions & 0 deletions src/main/java/nl/b3p/tailormap/api/solr/SolrService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (C) 2024 B3Partners B.V.
*
* SPDX-License-Identifier: MIT
*/
package nl.b3p.tailormap.api.solr;

import java.util.concurrent.TimeUnit;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.impl.ConcurrentUpdateHttp2SolrClient;
import org.apache.solr.client.solrj.impl.Http2SolrClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
public class SolrService {

Check warning on line 16 in src/main/java/nl/b3p/tailormap/api/solr/SolrService.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/nl/b3p/tailormap/api/solr/SolrService.java#L16

Added line #L16 was not covered by tests
@Value("${tailormap-api.solr-url}")
private String solrUrl;

@Value("${tailormap-api.solr-core-name:tailormap}")
private String solrCoreName;

/**
* Get a concurrent update Solr client for bulk operations.
*
* @return the Solr client
*/
public SolrClient getSolrClientForIndexing() {
return new ConcurrentUpdateHttp2SolrClient.Builder(

Check warning on line 29 in src/main/java/nl/b3p/tailormap/api/solr/SolrService.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/nl/b3p/tailormap/api/solr/SolrService.java#L29

Added line #L29 was not covered by tests
solrUrl + solrCoreName,
new Http2SolrClient.Builder()
.withFollowRedirects(true)
.withConnectionTimeout(10000, TimeUnit.MILLISECONDS)
.withRequestTimeout(60000, TimeUnit.MILLISECONDS)
.build())
.withQueueSize(SolrHelper.SOLR_BATCH_SIZE * 2)
.withThreadCount(10)
.build();

Check warning on line 38 in src/main/java/nl/b3p/tailormap/api/solr/SolrService.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/nl/b3p/tailormap/api/solr/SolrService.java#L32-L38

Added lines #L32 - L38 were not covered by tests
}

/**
* Get a Solr client for searching.
*
* @return the Solr client
*/
public SolrClient getSolrClientForSearching() {
return new Http2SolrClient.Builder(solrUrl + solrCoreName)
.withConnectionTimeout(10, TimeUnit.SECONDS)
.withFollowRedirects(true)
.build();

Check warning on line 50 in src/main/java/nl/b3p/tailormap/api/solr/SolrService.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/nl/b3p/tailormap/api/solr/SolrService.java#L47-L50

Added lines #L47 - L50 were not covered by tests
}
}
Loading

0 comments on commit 06a2695

Please sign in to comment.