Class SolrHelper

java.lang.Object
org.tailormap.api.solr.SolrHelper
All Implemented Interfaces:
AutoCloseable, Constants

public class SolrHelper extends Object implements 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.
  • Constructor Details

    • SolrHelper

      public SolrHelper(@NotNull @NotNull org.apache.solr.client.solrj.SolrClient solrClient)
      Create a configured SolrHelper 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 this SolrHelper 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 this SolrHelper with a batch size for submitting documents to the Solr instance.
      Parameters:
      solrBatchSize - the batch size for indexing, must be greater than 0
    • withGeometryValidationRule

      public SolrHelper withGeometryValidationRule(@NonNull String solrGeometryValidationRule)
      Configure this SolrHelper 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 config
      tmFeatureType - the feature type
      featureSourceFactoryHelper - the feature source factory helper
      searchIndexRepository - the search index repository, so we can save the searchIndex
      Returns:
      the possibly updated searchIndex object
      Throws:
      IOException - if an I/O error occurs
      org.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 config
      tmFeatureType - the feature type
      featureSourceFactoryHelper - the feature source factory helper
      searchIndexRepository - the search index repository, so we can save the searchIndex
      progressListener - the progress listener callback
      taskUuid - the task UUID, when null we will attempt to use the UUID from the searchIndex#getSchedule()
      Returns:
      the possibly updated searchIndex object
      Throws:
      IOException - if an I/O error occurs
      org.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 occurs
      org.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 the solrLayerId.
      Parameters:
      searchIndex - the search index
      solrQuery - the query, when null or empty, the query is set to * (match all)
      solrPoint - the point to search around, in (x y) format
      solrDistance - the distance to search around the point in Solr distance units (kilometers)
      start - the start index, starting at 0
      numResultsToReturn - the number of results to return
      Returns:
      the documents
      Throws:
      IOException - if an I/O error occurs
      org.apache.solr.client.solrj.SolrServerException - if a Solr error occurs
      org.apache.solr.common.SolrException
    • close

      public void close() throws IOException
      Close the wrapped Solr client.
      Specified by:
      close in interface AutoCloseable
      Throws:
      IOException - if an I/O error occurs