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) Constructor -
Method Summary
Modifier and TypeMethodDescriptionvoid
addFeatureTypeIndex
(@NotNull SearchIndex searchIndex, @NotNull TMFeatureType tmFeatureType, @NotNull FeatureSourceFactoryHelper featureSourceFactoryHelper) 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, int start, int numResultsToReturn) Search in the index for a layer.
-
Field Details
-
SOLR_BATCH_SIZE
public static final int SOLR_BATCH_SIZE- See Also:
-
-
Constructor Details
-
SolrHelper
public SolrHelper(@NotNull @NotNull org.apache.solr.client.solrj.SolrClient solrClient) Constructor- Parameters:
solrClient
- the Solr client, this will be closed when this class is closed
-
-
Method Details
-
addFeatureTypeIndex
public void addFeatureTypeIndex(@NotNull @NotNull SearchIndex searchIndex, @NotNull @NotNull TMFeatureType tmFeatureType, @NotNull @NotNull FeatureSourceFactoryHelper featureSourceFactoryHelper) throws UnsupportedOperationException, 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 type- Throws:
UnsupportedOperationException
- if the operation is not supported, possibly because not search field shave been definedIOException
- 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, 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)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
-