Package org.tailormap.api.solr
Class SolrHelper
java.lang.Object
org.tailormap.api.solr.SolrHelper
- All Implemented Interfaces:
AutoCloseable
,Constants
Solr utility/wrapper class. This class provides methods to add or update a full-text feature type
index for a layer, find in the index for a layer, and clear the index for a layer. It also
provides a method to close the Solr client as well as automatically closing the client when used
in a try-with-resources.
-
Field Summary
Fields inherited from interface org.tailormap.api.util.Constants
FID, ID, INDEX_DISPLAY_FIELD, INDEX_GEOM_FIELD, INDEX_SEARCH_FIELD, NAME_REGEX, NAME_REGEX_INVALID_MESSAGE, SEARCH_ID_FIELD, SEARCH_LAYER, TEST_TASK_TYPE, UUID_REGEX
-
Constructor Summary
ConstructorDescriptionSolrHelper
(@NotNull org.apache.solr.client.solrj.SolrClient solrClient) Create a configuredSolrHelper
object. -
Method Summary
Modifier and TypeMethodDescriptionaddFeatureTypeIndex
(@NotNull SearchIndex searchIndex, @NotNull TMFeatureType tmFeatureType, @NotNull FeatureSourceFactoryHelper featureSourceFactoryHelper, @NotNull SearchIndexRepository searchIndexRepository) Add or update a feature type index for a layer.addFeatureTypeIndex
(@NotNull SearchIndex searchIndex, @NotNull TMFeatureType tmFeatureType, @NotNull FeatureSourceFactoryHelper featureSourceFactoryHelper, @NotNull SearchIndexRepository searchIndexRepository, @NotNull Consumer<TaskProgressEvent> progressListener, UUID taskUuid) Add or update a feature type index for a layer.void
clearIndexForLayer
(@NotNull Long searchLayerId) Clear the index for a layer.void
close()
Close the wrapped Solr client.findInIndex
(@NotNull SearchIndex searchIndex, String solrQuery, String solrFilterQuery, String solrPoint, Double solrDistance, int start, int numResultsToReturn) Search in the index for a layer.withBatchSize
(@jakarta.validation.constraints.Positive(message="Must use a positive integer for batching") int solrBatchSize) Configure thisSolrHelper
with a batch size for submitting documents to the Solr instance.withGeometryValidationRule
(String solrGeometryValidationRule) Configure thisSolrHelper
to create a geometry field in Solr using the specified validation rule.withQueryTimeout
(@jakarta.validation.constraints.Positive(message="Must use a positive integer for query timeout") int solrQueryTimeout) Configure thisSolrHelper
with a query timeout .
-
Constructor Details
-
SolrHelper
public SolrHelper(@NotNull @NotNull org.apache.solr.client.solrj.SolrClient solrClient) Create a configuredSolrHelper
object.- Parameters:
solrClient
- the Solr client, this will be closed when this class is closed
-
-
Method Details
-
withQueryTimeout
public SolrHelper withQueryTimeout(@Positive(message="Must use a positive integer for query timeout") @jakarta.validation.constraints.Positive(message="Must use a positive integer for query timeout") int solrQueryTimeout) Configure thisSolrHelper
with a query timeout .- Parameters:
solrQueryTimeout
- the query timeout in seconds
-
withBatchSize
public SolrHelper withBatchSize(@Positive(message="Must use a positive integer for batching") @jakarta.validation.constraints.Positive(message="Must use a positive integer for batching") int solrBatchSize) Configure thisSolrHelper
with a batch size for submitting documents to the Solr instance.- Parameters:
solrBatchSize
- the batch size for indexing, must be greater than 0
-
withGeometryValidationRule
Configure thisSolrHelper
to create a geometry field in Solr using the specified validation rule.- Parameters:
solrGeometryValidationRule
- any of"error", "none", "repairBuffer0", "repairConvexHull"
- See Also:
-
addFeatureTypeIndex
public SearchIndex addFeatureTypeIndex(@NotNull @NotNull SearchIndex searchIndex, @NotNull @NotNull TMFeatureType tmFeatureType, @NotNull @NotNull FeatureSourceFactoryHelper featureSourceFactoryHelper, @NotNull @NotNull SearchIndexRepository searchIndexRepository) throws IOException, org.apache.solr.client.solrj.SolrServerException Add or update a feature type index for a layer.- Parameters:
searchIndex
- the search index configtmFeatureType
- the feature typefeatureSourceFactoryHelper
- the feature source factory helpersearchIndexRepository
- the search index repository, so we can save thesearchIndex
- Returns:
- the possibly updated
searchIndex
object - Throws:
IOException
- if an I/O error occursorg.apache.solr.client.solrj.SolrServerException
- if a Solr error occurs
-
addFeatureTypeIndex
public SearchIndex addFeatureTypeIndex(@NotNull @NotNull SearchIndex searchIndex, @NotNull @NotNull TMFeatureType tmFeatureType, @NotNull @NotNull FeatureSourceFactoryHelper featureSourceFactoryHelper, @NotNull @NotNull SearchIndexRepository searchIndexRepository, @NotNull @NotNull Consumer<TaskProgressEvent> progressListener, @Nullable UUID taskUuid) throws IOException, org.apache.solr.client.solrj.SolrServerException Add or update a feature type index for a layer.- Parameters:
searchIndex
- the search index configtmFeatureType
- the feature typefeatureSourceFactoryHelper
- the feature source factory helpersearchIndexRepository
- the search index repository, so we can save thesearchIndex
progressListener
- the progress listener callbacktaskUuid
- the task UUID, whennull
we will attempt to use the UUID from thesearchIndex#getSchedule()
- Returns:
- the possibly updated
searchIndex
object - Throws:
IOException
- if an I/O error occursorg.apache.solr.client.solrj.SolrServerException
- if a Solr error occurs
-
clearIndexForLayer
public void clearIndexForLayer(@NotNull @NotNull Long searchLayerId) throws IOException, org.apache.solr.client.solrj.SolrServerException Clear the index for a layer.- Parameters:
searchLayerId
- the layer id- Throws:
IOException
- if an I/O error occursorg.apache.solr.client.solrj.SolrServerException
- if a Solr error occurs
-
findInIndex
public SearchResponse findInIndex(@NotNull @NotNull SearchIndex searchIndex, String solrQuery, String solrFilterQuery, String solrPoint, Double solrDistance, int start, int numResultsToReturn) throws IOException, org.apache.solr.client.solrj.SolrServerException, org.apache.solr.common.SolrException Search in the index for a layer. The given query is augmented to filter on thesolrLayerId
.- Parameters:
searchIndex
- the search indexsolrQuery
- the query, whennull
or empty, the query is set to*
(match all)solrPoint
- the point to search around, in (x y) formatsolrDistance
- the distance to search around the point in Solr distance units (kilometers)start
- the start index, starting at 0numResultsToReturn
- the number of results to return- Returns:
- the documents
- Throws:
IOException
- if an I/O error occursorg.apache.solr.client.solrj.SolrServerException
- if a Solr error occursorg.apache.solr.common.SolrException
-
close
Close the wrapped Solr client.- Specified by:
close
in interfaceAutoCloseable
- Throws:
IOException
- if an I/O error occurs
-