Package io.goobi.viewer.solr
Class SolrSearchIndex
java.lang.Object
io.goobi.viewer.solr.SolrSearchIndex
- All Implemented Interfaces:
Closeable,AutoCloseable
Provides all Solr query operations for the viewer, wrapping the SolrJ client with viewer-specific convenience methods.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intConstantMAX_HITS=1000000.static final int -
Constructor Summary
ConstructorsConstructorDescriptionSolrSearchIndex(org.apache.solr.client.solrj.SolrClient client) Creates a new SolrSearchIndex instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidChecks whether the server's configured URL matches that in the config file.voidclose()Retrieves the repository name for the record with the given PI and persists it in a map.generateFilteredTagCloud(String fieldName, String querySuffix) Returns a list of Tags created from the terms for the given field name.getAllFieldNames.getAllSortFieldNames.getDisplayUserGeneratedContentsForPage.org.apache.solr.common.SolrDocumentListReturns all SolrDocuments matching the given query.org.apache.solr.common.SolrDocumentgetDocumentByIddoc(String iddoc) getDocumentByIddoc.org.apache.solr.common.SolrDocumentgetDocumentByPI.org.apache.solr.common.SolrDocumentgetDocumentByPIAndLogId(String pi, String divId) getFilename(String pi, int order) Catches the filename of the page with the given order under the given ip.getFilename(String pi, String basename) Catches the filename of the page with the given basename under the given ip.org.apache.solr.common.SolrDocumentgetFirstDoc(String query, List<String> fieldList) Retrieves the first document found by the given query.org.apache.solr.common.SolrDocumentgetFirstDoc(String query, List<String> fieldList, List<StringPair> sortFields) Retrieves the first document found by the given query.longgetHitCount(String query) Returns the number of hits for the given query without actually returning any documents.longgetHitCount(String query, List<String> filterQueries) Returns the number of hits for the given query and filter queries without actually returning any documents.getIddocByLogid(String pi, String logId) Returns the IDDOC of the logical document to which the given LOGID belongs.getIddocFromIdentifier(String identifier) Returns the value of the IDDOC field for the document with the given PI (or 0 if none found).getIdentifierFromIddoc(String iddoc) getIdentifierFromIddoc.getImageOwnerIddoc(String pi, int pageNo) Returns the IDDOC of the logical document to which the given page belongs.getLabelValuesForFacetField(String field, String labelField, Set<String> values) static org.apache.solr.client.solrj.SolrClientstatic org.apache.solr.client.solrj.SolrClientgetNewSolrClient(String solrUrl) getPage(StructElement struct, int order) getPage.getPage.booleanvoidbooleanorg.apache.solr.common.SolrDocumentListDiese Methode führt eine Suche im Lucene durch.org.apache.solr.client.solrj.response.QueryResponsesearch(String query, int first, int rows, List<StringPair> sortFields, List<String> facetFields, String facetSort, List<String> fieldList, List<String> filterQueries, Map<String, String> params) Main Solr search method.org.apache.solr.client.solrj.response.QueryResponsesearch(String query, int first, int rows, List<StringPair> sortFields, List<String> facetFields, String facetSort, List<String> fieldList, List<String> filterQueries, Map<String, String> params, org.apache.solr.client.solrj.SolrRequest.METHOD queryMethod) org.apache.solr.client.solrj.response.QueryResponsesearch(String query, int first, int rows, List<StringPair> sortFields, List<String> facetFields, List<String> fieldList) search.org.apache.solr.client.solrj.response.QueryResponsesearch(String query, int first, int rows, List<StringPair> sortFields, List<String> facetFields, List<String> fieldList, List<String> filterQueries, Map<String, String> params) search.org.apache.solr.common.SolrDocumentListsearch.org.apache.solr.common.SolrDocumentListorg.apache.solr.client.solrj.response.QueryResponsesearchFacetsAndStatistics(String query, List<String> filterQueries, List<String> facetFields, int facetMinCount, boolean getFieldStatistics) Returns facets for the given facet field list.org.apache.solr.client.solrj.response.QueryResponsesearchFacetsAndStatistics(String query, List<String> filterQueries, List<String> facetFields, int facetMinCount, String facetPrefix, Map<String, String> params, boolean getFieldStatistics) Returns facets for the given facet field list.org.apache.solr.client.solrj.response.QueryResponsesearchFacetsAndStatistics(String query, List<String> filterQueries, List<String> facetFields, int facetMinCount, Map<String, String> params, boolean getFieldStatistics) Returns facets for the given facet field list.org.apache.solr.client.solrj.response.QueryResponsetestQuery.voidupdateDataRepositoryNames(String pi, String dataRepositoryName)
-
Field Details
-
MAX_HITS
public static final int MAX_HITSConstantMAX_HITS=1000000.- See Also:
-
MAX_HITS_EXPANDED
public static final int MAX_HITS_EXPANDED- See Also:
-
-
Constructor Details
-
SolrSearchIndex
public SolrSearchIndex(org.apache.solr.client.solrj.SolrClient client) Creates a new SolrSearchIndex instance.- Parameters:
client- Solr client to use; a new default client is created if null
-
-
Method Details
-
checkReloadNeeded
public void checkReloadNeeded()Checks whether the server's configured URL matches that in the config file. If not, a new server instance is created. -
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
getNewSolrClient
public static org.apache.solr.client.solrj.SolrClient getNewSolrClient()- Returns:
- New
SolrClient
-
getNewSolrClient
-
isSolrIndexOnline
public boolean isSolrIndexOnline()- Returns:
- true if test query executes without errors; false otherwise
-
testQuery
public org.apache.solr.client.solrj.response.QueryResponse testQuery(String query) throws org.apache.solr.client.solrj.SolrServerException, IOException testQuery.- Parameters:
query- Solr query string to execute as a test- Returns:
- the QueryResponse from the test query
- Throws:
org.apache.solr.client.solrj.SolrServerException- if any.IOException
-
search
public org.apache.solr.client.solrj.response.QueryResponse search(String query, int first, int rows, List<StringPair> sortFields, List<String> facetFields, String facetSort, List<String> fieldList, List<String> filterQueries, Map<String, String> params) throws PresentationException, IndexUnreachableExceptionMain Solr search method.- Parameters:
query- Solr query string to executefirst- zero-based offset of the first result to returnrows- maximum number of documents to returnsortFields- Optional field/order pairs for sortingfacetFields- list of Solr facet field names to compute facets forfacetSort- sort order for facet values ("count" or field name)fieldList- If not null, only the fields in the list will be returned.filterQueries- list of Solr filter query strings to applyparams- Additional query parameters.- Returns:
QueryResponse- Throws:
PresentationException- if any.IndexUnreachableException- if any.
-
search
public org.apache.solr.client.solrj.response.QueryResponse search(String query, int first, int rows, List<StringPair> sortFields, List<String> facetFields, String facetSort, List<String> fieldList, List<String> filterQueries, Map<String, String> params, org.apache.solr.client.solrj.SolrRequest.METHOD queryMethod) throws PresentationException, IndexUnreachableException -
search
public org.apache.solr.client.solrj.response.QueryResponse search(String query, int first, int rows, List<StringPair> sortFields, List<String> facetFields, List<String> fieldList, List<String> filterQueries, Map<String, String> params) throws PresentationException, IndexUnreachableExceptionsearch.- Parameters:
query- Solr query string to executefirst- zero-based offset of the first result to returnrows- maximum number of documents to returnsortFields- Optional field/order pairs for sortingfacetFields- list of Solr facet field names to compute facets forfieldList- If not null, only the fields in the list will be returned.filterQueries- list of Solr filter query strings to applyparams- additional Solr query parameters- Returns:
QueryResponse- Throws:
PresentationException- if any.IndexUnreachableException- if any.
-
search
public org.apache.solr.client.solrj.response.QueryResponse search(String query, int first, int rows, List<StringPair> sortFields, List<String> facetFields, List<String> fieldList) throws PresentationException, IndexUnreachableException search.- Parameters:
query- Solr query string to executefirst- zero-based offset of the first result to returnrows- maximum number of documents to returnsortFields- Optional field/order pairs for sortingfacetFields- list of Solr facet field names to compute facets forfieldList- If not null, only the fields in the list will be returned.- Returns:
QueryResponse- Throws:
PresentationException- if any.IndexUnreachableException- if any.
-
search
public org.apache.solr.common.SolrDocumentList search(String query, int rows, List<StringPair> sortFields, List<String> fieldList) throws PresentationException, IndexUnreachableException search.- Parameters:
query- Solr query string to executerows- maximum number of documents to returnsortFields- Optional field/order pairs for sortingfieldList- If not null, only the fields in the list will be returned.- Returns:
- the list of matching Solr documents
- Throws:
PresentationException- if any.IndexUnreachableException- if any.
-
search
public org.apache.solr.common.SolrDocumentList search(String query, List<String> fieldList) throws PresentationException, IndexUnreachableException - Parameters:
query- Solr query string to executefieldList- list of Solr field names to include in returned documents- Returns:
SolrDocumentList- Throws:
PresentationException- if any.IndexUnreachableException- if any.
-
search
public org.apache.solr.common.SolrDocumentList search(String query) throws PresentationException, IndexUnreachableException Diese Methode führt eine Suche im Lucene durch.- Parameters:
query- Solr query string to execute- Returns:
SolrDocumentList- Throws:
PresentationException- if any.IndexUnreachableException- if any.
-
getFirstDoc
public org.apache.solr.common.SolrDocument getFirstDoc(String query, List<String> fieldList) throws PresentationException, IndexUnreachableException Retrieves the first document found by the given query.- Parameters:
query- Solr query string to executefieldList- list of Solr field names to include in returned document- Returns:
- The first hit returned by the query
- Throws:
PresentationException- if any.IndexUnreachableException- if any.
-
getFirstDoc
public org.apache.solr.common.SolrDocument getFirstDoc(String query, List<String> fieldList, List<StringPair> sortFields) throws PresentationException, IndexUnreachableException Retrieves the first document found by the given query.- Parameters:
query- The query to searchfieldList- The fields retrievedsortFields- Sorting - the first volume according to this sorting is returned- Returns:
- The first hit returned by the query
- Throws:
PresentationException- if any.IndexUnreachableException- if any.
-
getDocs
public org.apache.solr.common.SolrDocumentList getDocs(String query, List<String> fieldList) throws PresentationException, IndexUnreachableException Returns all SolrDocuments matching the given query. If no documents were found, null is returned- Parameters:
query- Solr query string to executefieldList- list of Solr field names to include in returned documents- Returns:
- the list of matching Solr documents, or null if no documents are found
- Throws:
PresentationException- if any.IndexUnreachableException- if any.
-
getDocumentByIddoc
public org.apache.solr.common.SolrDocument getDocumentByIddoc(String iddoc) throws IndexUnreachableException, PresentationException getDocumentByIddoc.- Parameters:
iddoc- internal Solr document identifier to look up- Returns:
- the Solr document matching the given IDDOC, or null if not found
- Throws:
IndexUnreachableException- if any.PresentationException- if any.
-
getDocumentByPI
public org.apache.solr.common.SolrDocument getDocumentByPI(String pi) throws IndexUnreachableException, PresentationException getDocumentByPI.- Parameters:
pi- persistent identifier of the record to look up- Returns:
- the Solr document matching the given PI, or null if not found
- Throws:
IndexUnreachableException- if any.PresentationException- if any.
-
getDocumentByPIAndLogId
public org.apache.solr.common.SolrDocument getDocumentByPIAndLogId(String pi, String divId) throws IndexUnreachableException, PresentationException -
generateFilteredTagCloud
public List<Tag> generateFilteredTagCloud(String fieldName, String querySuffix) throws IndexUnreachableException Returns a list of Tags created from the terms for the given field name. This method uses the slower doc search instead of term search, but can be filtered with a query.- Parameters:
fieldName- Solr field name whose terms to aggregate into tagsquerySuffix- additional query suffix appended to filter the tag cloud results- Returns:
- a list of Tag objects generated from the terms of the given Solr field, optionally filtered by the query suffix
- Throws:
IndexUnreachableException- if any.
-
getIddocFromIdentifier
public String getIddocFromIdentifier(String identifier) throws PresentationException, IndexUnreachableException Returns the value of the IDDOC field for the document with the given PI (or 0 if none found).- Parameters:
identifier- persistent identifier of the record to look up- Returns:
- String value; null if none found
- Throws:
PresentationException- if any.IndexUnreachableException- if any.
-
getIdentifierFromIddoc
public String getIdentifierFromIddoc(String iddoc) throws PresentationException, IndexUnreachableException getIdentifierFromIddoc.- Parameters:
iddoc- internal Solr document identifier to resolve- Returns:
- the record identifier (PI) for the given IDDOC, or null if not found
- Throws:
PresentationException- if any.IndexUnreachableException- if any.
-
getImageOwnerIddoc
public String getImageOwnerIddoc(String pi, int pageNo) throws IndexUnreachableException, PresentationException Returns the IDDOC of the logical document to which the given page belongs.- Parameters:
pi- persistent identifier of the top-level recordpageNo- page order number (1-based) to look up- Returns:
- String value; null if none found
- Throws:
IndexUnreachableException- if any.PresentationException- if any.
-
getIddocByLogid
public String getIddocByLogid(String pi, String logId) throws IndexUnreachableException, PresentationException Returns the IDDOC of the logical document to which the given LOGID belongs.- Parameters:
pi- persistent identifier of the top-level recordlogId- logical structure identifier within the record- Returns:
- String value; null if none found
- Throws:
IndexUnreachableException- if any.PresentationException- if any.
-
getHitCount
Returns the number of hits for the given query without actually returning any documents.- Parameters:
query- Solr query string to count hits for- Returns:
- a long.
- Throws:
IndexUnreachableException- if any.PresentationException- if any.
-
getHitCount
public long getHitCount(String query, List<String> filterQueries) throws IndexUnreachableException, PresentationException Returns the number of hits for the given query and filter queries without actually returning any documents.- Parameters:
query- Solr query string to count hits forfilterQueries- Solr filter query list to apply alongside the main query- Returns:
- Number of hits for the given queries
- Throws:
IndexUnreachableExceptionPresentationException
-
findDataRepositoryName
public String findDataRepositoryName(String pi) throws PresentationException, IndexUnreachableException Retrieves the repository name for the record with the given PI and persists it in a map. This method is package private to discourage clients from constructing data file paths manually instead of using Helper methods.- Parameters:
pi- persistent identifier of the record to look up- Returns:
- Data repository name for the record with the given identifier; null if not in a repository
- Throws:
PresentationExceptionIndexUnreachableException
-
updateDataRepositoryNames
- Parameters:
pi- persistent identifier of the recorddataRepositoryName- name of the data repository to associate with the record
-
searchFacetsAndStatistics
public org.apache.solr.client.solrj.response.QueryResponse searchFacetsAndStatistics(String query, List<String> filterQueries, List<String> facetFields, int facetMinCount, boolean getFieldStatistics) throws PresentationException, IndexUnreachableException Returns facets for the given facet field list. No actual docs are returned since they aren't necessary.- Parameters:
query- Solr query string to executefilterQueries- list of Solr filter query strings to applyfacetFields- list of Solr facet field names to compute facets forfacetMinCount- minimum count a facet value must have to be includedgetFieldStatistics- if true, field statistics are generated for every facet field- Returns:
- the QueryResponse containing facets (and optional field statistics) without document results
- Throws:
PresentationException- if any.IndexUnreachableException- if any.
-
searchFacetsAndStatistics
public org.apache.solr.client.solrj.response.QueryResponse searchFacetsAndStatistics(String query, List<String> filterQueries, List<String> facetFields, int facetMinCount, Map<String, String> params, boolean getFieldStatistics) throws PresentationException, IndexUnreachableExceptionReturns facets for the given facet field list. No actual docs are returned since they aren't necessary.- Parameters:
query- Solr query string to executefilterQueries- list of Solr filter query strings to applyfacetFields- list of Solr facet field names to compute facets forfacetMinCount- minimum count a facet value must have to be includedparams- additional Solr query parametersgetFieldStatistics- if true, field statistics are generated for every facet field- Returns:
- the QueryResponse containing facets (and optional field statistics) without document results
- Throws:
PresentationException- if any.IndexUnreachableException- if any.
-
searchFacetsAndStatistics
public org.apache.solr.client.solrj.response.QueryResponse searchFacetsAndStatistics(String query, List<String> filterQueries, List<String> facetFields, int facetMinCount, String facetPrefix, Map<String, String> params, boolean getFieldStatistics) throws PresentationException, IndexUnreachableExceptionReturns facets for the given facet field list. No actual docs are returned since they aren't necessary.- Parameters:
query- Solr query string to executefilterQueries- list of Solr filter query strings to applyfacetFields- list of Solr facet field names to compute facets forfacetMinCount- minimum count a facet value must have to be includedfacetPrefix- prefix that facet values must start with; ignored if null or blankparams- additional Solr query parametersgetFieldStatistics- if true, field statistics are generated for every facet field- Returns:
- the QueryResponse containing facets (and optional field statistics) without document results
- Throws:
PresentationException- if any.IndexUnreachableException- if any.
-
getAllFieldNames
getAllFieldNames.- Returns:
- a list of all field names defined in the Solr schema
- Throws:
DAOExceptionorg.apache.solr.client.solrj.SolrServerException- if any.IOException- if any.IndexUnreachableException
-
getAllBooleanFieldNames
- Throws:
IndexUnreachableException
-
loadSolrFields
- Throws:
org.apache.solr.client.solrj.SolrServerExceptionIOException
-
getAllSortFieldNames
public List<String> getAllSortFieldNames() throws org.apache.solr.client.solrj.SolrServerException, IOExceptiongetAllSortFieldNames.- Returns:
- a list of all SOLR fields starting with "SORT_".
- Throws:
org.apache.solr.client.solrj.SolrServerException- if any.IOException- if any.
-
getAllGroupFieldNames
public List<String> getAllGroupFieldNames() throws org.apache.solr.client.solrj.SolrServerException, IOException- Returns:
- A list of all SOLR fields without the multivalues flag
- Throws:
org.apache.solr.client.solrj.SolrServerExceptionIOException
-
getDisplayUserGeneratedContentsForRecord
public List<DisplayUserGeneratedContent> getDisplayUserGeneratedContentsForRecord(String pi) throws PresentationException, IndexUnreachableException getDisplayUserGeneratedContentsForPage.- Parameters:
pi- persistent identifier of the record to load UGC for- Returns:
- contents for the given page
- Throws:
PresentationException- if any.IndexUnreachableException- if any.
-
getFilename
public Optional<String> getFilename(String pi, int order) throws PresentationException, IndexUnreachableException Catches the filename of the page with the given order under the given ip.- Parameters:
pi- The topstruct piorder- The page order (1-based- Returns:
- An optíonal containing the filename of the page with the given order under the given ip. Or an empty optional if no matching page was found.
- Throws:
PresentationException- if any.IndexUnreachableException- if any.
-
getFilename
public Optional<String> getFilename(String pi, String basename) throws PresentationException, IndexUnreachableException Catches the filename of the page with the given basename under the given ip. Used in case a filename is requested without the file extension- Parameters:
pi- The topstruct pibasename- The filename of the image without the extension (everything before the last dot)- Returns:
- An optíonal containing the filename of the page with the given order under the given ip. Or an empty optional if no matching page was found.
- Throws:
PresentationException- if any.IndexUnreachableException- if any.
-
getLabelValuesForFacetField
public Map<String,String> getLabelValuesForFacetField(String field, String labelField, Set<String> values) throws PresentationException, IndexUnreachableException - Parameters:
field- Solr field name whose values are to be looked uplabelField- Solr field name that contains the human-readable labelvalues- set of field values for which labels are requested- Returns:
- Map
- Throws:
PresentationExceptionIndexUnreachableException
-
getSolrServerUrl
- Returns:
- Base URL of the active Solr server
-
pingSolrIndex
public boolean pingSolrIndex()- Returns:
- true if ping successful; false otherwise
-
getHeatMap
public String getHeatMap(String solrField, String wktRegion, String query, String filterQuery, Integer gridLevel) throws IndexUnreachableException - Parameters:
solrField- Solr field name containing the geospatial coordinateswktRegion- WKT string defining the spatial region to compute the heatmap forquery- Solr query string to filter documentsfilterQuery- additional Solr filter query stringgridLevel- heatmap grid level controlling resolution- Returns:
- String
- Throws:
IndexUnreachableException
-
getPage
public PhysicalElement getPage(String pi, int order) throws IndexUnreachableException, PresentationException, DAOException getPage.- Parameters:
pi- persistent identifier of the record to load the page fromorder- page order number (1-based) to retrieve- Returns:
- the PhysicalElement at the given order position within the record, or null if not found
- Throws:
IndexUnreachableException- if any.PresentationException- if any.DAOException- if any.
-
getPage
public PhysicalElement getPage(StructElement struct, int order) throws IndexUnreachableException, PresentationException, DAOException getPage.- Parameters:
struct- struct element representing the record to load the page fromorder- page order number (1-based) to retrieve- Returns:
- the PhysicalElement at the given order position within the struct element
- Throws:
IndexUnreachableException- if any.PresentationException- if any.DAOException- if any.
-
getDataRepositoryNames
-