Package io.goobi.viewer.solr
Class SolrTools
java.lang.Object
io.goobi.viewer.solr.SolrTools
Static utility methods for Solr.
-
Method Summary
Modifier and TypeMethodDescriptionstatic String[]
checkSolrSchemaName.static String
cleanUpQuery
(String query) static String
escapeSpecialCharacters
(String string) Escapes all special characters used by SOLR.static String
extractExceptionMessageHtmlTitle
(String exceptionMessage) static String
Solr supports dynamic random_* sorting fields.getAllUsedLocales
(StructElement structElement) Deprecated.No longer in use, as it can produce a list of only irrelevant localesstatic Boolean
getAsBoolean
(Object fieldValue) static Integer
getAsInt.static Long
getAsLong.static String
getAsString
(Object fieldValue) Parses a Solr-Field value in order to return it as String.static String
getAsString
(Object fieldValue, String separator) getAvailableValuesForField
(String field, String filterQuery) getAvailableValuesForField.getAvailableValuesForField
(String field, String filterQuery, boolean useFacetField) getAvailableValuesForField.static String
getBaseFieldName
(String fieldName) getFieldValueMap
(org.apache.solr.common.SolrDocument doc) Converts the given SolrDocument to a value map.static String
getLanguage
(String fieldName) static Locale
getMetadataValues
(org.apache.solr.common.SolrDocument doc, String fieldName) Returns a list with all (string) values for the given field name in the given SolrDocument.getMetadataValuesForLanguage
(StructElement doc, String key) getMetadataValuesForLanguage.getMetadataValuesForLanguage
(org.apache.solr.common.SolrDocument doc, String key) getMetadataValuesForLanguage.getMultiLanguageFieldValueMap
(org.apache.solr.common.SolrDocument doc) Converts the given SolrDocument to a value map.static List<de.intranda.metadata.multilanguage.IMetadataValue>
getMultiLanguageMetadata
(Map<String, List<String>> mdValues) getMultiLanguageMetadata.static String
getProcessedConditions
(String conditions) static final String
getReferenceId
(org.apache.solr.common.SolrDocument doc) static boolean
getSingleFieldBooleanValue
(org.apache.solr.common.SolrDocument doc, String field) getSingleFieldBooleanValue.static Integer
getSingleFieldIntegerValue
(org.apache.solr.common.SolrDocument doc, String field) getSingleFieldIntegerValue.static Long
getSingleFieldLongValue
(org.apache.solr.common.SolrDocument doc, String field) getSingleFieldLongValue.static String
getSingleFieldStringValue
(org.apache.solr.common.SolrDocument doc, String field) getSingleFieldStringValue.static Object
getSingleFieldValue
(org.apache.solr.common.SolrDocument doc, String field) getSingleFieldValue.static List<StringPair>
getSolrSortFieldsAsList
(String solrSortFields, String splitFieldsBy, String splitNameOrderBy) Returns the comma-separated sorting fields insolrSortFields
as a List. getTranslatedMetadata
(org.apache.solr.common.SolrDocument doc, Function<String, Boolean> fieldNameFilter) getTranslatedMetadata
(org.apache.solr.common.SolrDocument doc, Map<String, List<de.intranda.metadata.multilanguage.IMetadataValue>> metadata, Locale documentLocale, Function<String, Boolean> fieldNameFilter) static Optional<de.intranda.metadata.multilanguage.IMetadataValue>
getTranslations
(String fieldName, StructElement doc, BinaryOperator<String> combiner) getTranslations.static Optional<de.intranda.metadata.multilanguage.IMetadataValue>
getTranslations
(String fieldName, StructElement doc, List<Locale> translationLocales, BinaryOperator<String> combiner) getTranslations.static Optional<de.intranda.metadata.multilanguage.IMetadataValue>
getTranslations
(String fieldName, org.apache.solr.common.SolrDocument doc) getTranslations.static Optional<de.intranda.metadata.multilanguage.IMetadataValue>
getTranslations
(String fieldName, org.apache.solr.common.SolrDocument doc, BinaryOperator<String> combiner) getTranslations.static boolean
isAnchor
(org.apache.solr.common.SolrDocument doc) static boolean
isGroup
(org.apache.solr.common.SolrDocument doc) static boolean
isHasImages
(org.apache.solr.common.SolrDocument doc) isHasImages.static boolean
isHasWrongLanguageCode
(String field, String language) static boolean
isLanguageCodedField
(String fieldName) static boolean
isQuerySyntaxError.static boolean
isWork
(org.apache.solr.common.SolrDocument doc) static String
unescapeSpecialCharacters
(String string) reverts the operation ofescapeSpecialCharacters(String)
.
-
Method Details
-
getSolrSortFieldsAsList
public static List<StringPair> getSolrSortFieldsAsList(String solrSortFields, String splitFieldsBy, String splitNameOrderBy) Returns the comma-separated sorting fields insolrSortFields
as a List. -
getAsString
Parses a Solr-Field value in order to return it as String. -
getAsBoolean
- Parameters:
fieldValue
-- Returns:
- Boolean
-
getAsString
- Parameters:
fieldValue
-separator
-- Returns:
- String
-
getAsInt
getAsInt.
-
getAsLong
getAsLong.
-
getSingleFieldValue
getSingleFieldValue.
-
getSingleFieldStringValue
public static String getSingleFieldStringValue(org.apache.solr.common.SolrDocument doc, String field) getSingleFieldStringValue.
-
getSingleFieldIntegerValue
public static Integer getSingleFieldIntegerValue(org.apache.solr.common.SolrDocument doc, String field) getSingleFieldIntegerValue.
-
getSingleFieldLongValue
getSingleFieldLongValue.
-
getSingleFieldBooleanValue
public static boolean getSingleFieldBooleanValue(org.apache.solr.common.SolrDocument doc, String field) getSingleFieldBooleanValue.
-
getMetadataValues
public static List<String> getMetadataValues(org.apache.solr.common.SolrDocument doc, String fieldName) Returns a list with all (string) values for the given field name in the given SolrDocument. -
getFieldValueMap
Converts the given SolrDocument to a value map. IMAGEURN_OAI and PAGEURNS are not returned because they have no relevance in this application and can get quite large.- Parameters:
doc
- aSolrDocument
object.- Returns:
- a
Map
object.
-
getMultiLanguageFieldValueMap
public static Map<String,List<de.intranda.metadata.multilanguage.IMetadataValue>> getMultiLanguageFieldValueMap(org.apache.solr.common.SolrDocument doc) Converts the given SolrDocument to a value map. IMAGEURN_OAI and PAGEURNS are not returned because they have no relevance in this application and can get quite large.- Parameters:
doc
- aSolrDocument
object.- Returns:
- a
Map
object.
-
getMultiLanguageMetadata
public static List<de.intranda.metadata.multilanguage.IMetadataValue> getMultiLanguageMetadata(Map<String, List<String>> mdValues) getMultiLanguageMetadata.
-
getMetadataValuesForLanguage
public static Map<String,List<String>> getMetadataValuesForLanguage(org.apache.solr.common.SolrDocument doc, String key) getMetadataValuesForLanguage.
- Parameters:
doc
- The document containing the metadatakey
- the metadata key without the '_LANG_...' suffix- Returns:
- A map with keys for each language and lists of all found metadata values for this language. Metadata that match the given key but have
no language information are listed as language
_DEFAULT
-
getMetadataValuesForLanguage
getMetadataValuesForLanguage.
- Parameters:
doc
- The document containing the metadatakey
- the metadata key without the '_LANG_...' suffix- Returns:
- A map with keys for each language and lists of all found metadata values for this language. Metadata that match the given key but have
no language information are listed as language
_DEFAULT
-
isGroup
public static boolean isGroup(org.apache.solr.common.SolrDocument doc) - Parameters:
doc
-- Returns:
- true if doc contains DOCTYPE:GROUP; false otherwise
-
isAnchor
public static boolean isAnchor(org.apache.solr.common.SolrDocument doc) - Parameters:
doc
-- Returns:
- true if doc contains ISANCHOR:true; false otherwise
-
isWork
public static boolean isWork(org.apache.solr.common.SolrDocument doc) - Parameters:
doc
-- Returns:
- true if doc contains ISWORK:true; false otherwise
-
isLanguageCodedField
- Parameters:
fieldName
-- Returns:
- true if fieldName contains _LANG_; false otherwise
-
isHasWrongLanguageCode
- Parameters:
field
-language
-- Returns:
- true if language code different
-
isQuerySyntaxError
isQuerySyntaxError.
- Parameters:
e
- aException
object.- Returns:
- a boolean.
-
extractExceptionMessageHtmlTitle
- Parameters:
exceptionMessage
-- Returns:
- Extracted message
-
getTranslations
public static Optional<de.intranda.metadata.multilanguage.IMetadataValue> getTranslations(String fieldName, org.apache.solr.common.SolrDocument doc) getTranslations.
-
getTranslations
public static Optional<de.intranda.metadata.multilanguage.IMetadataValue> getTranslations(String fieldName, org.apache.solr.common.SolrDocument doc, BinaryOperator<String> combiner) getTranslations.
- Parameters:
fieldName
- aString
object.doc
- aSolrDocument
object.combiner
- aBinaryOperator
object.- Returns:
- a
Optional
object.
-
getTranslations
public static Optional<de.intranda.metadata.multilanguage.IMetadataValue> getTranslations(String fieldName, StructElement doc, BinaryOperator<String> combiner) getTranslations.
- Parameters:
fieldName
- aString
object.doc
- aStructElement
object.combiner
- aBinaryOperator
object.- Returns:
- a
Optional
object.
-
getTranslations
public static Optional<de.intranda.metadata.multilanguage.IMetadataValue> getTranslations(String fieldName, StructElement doc, List<Locale> translationLocales, BinaryOperator<String> combiner) getTranslations.
- Parameters:
fieldName
- aString
object.doc
- aStructElement
object.translationLocales
-combiner
- aBinaryOperator
object.- Returns:
- a
Optional
object.
-
isHasImages
public static boolean isHasImages(org.apache.solr.common.SolrDocument doc) throws IndexUnreachableException isHasImages.
- Parameters:
doc
- aSolrDocument
object. Needs to contain metadata fieldsSolrConstants.FILENAME
andSolrConstants.THUMBNAIL
- Returns:
- true if record described by doc has images; false otherwise
- Throws:
IndexUnreachableException
- if any.
-
getProcessedConditions
- Parameters:
conditions
-- Returns:
- conditions with NOW/YEAR replaced by current year
-
getAvailableValuesForField
public static List<String> getAvailableValuesForField(String field, String filterQuery) throws PresentationException, IndexUnreachableException getAvailableValuesForField.
- Parameters:
field
- aString
object.filterQuery
- aString
object.- Returns:
- List of facet values for the given field and query
- Throws:
PresentationException
- if any.IndexUnreachableException
- if any.
-
getAvailableValuesForField
public static List<String> getAvailableValuesForField(String field, String filterQuery, boolean useFacetField) throws PresentationException, IndexUnreachableException getAvailableValuesForField.
- Parameters:
field
- aString
object.filterQuery
- aString
object.useFacetField
- If true, "FACET_" field variant is used for the actual search; Only use false for single-token values- Returns:
- List of facet values for the given field and query
- Throws:
PresentationException
- if any.IndexUnreachableException
- if any.
-
getExistingSubthemes
public static List<String> getExistingSubthemes() throws PresentationException, IndexUnreachableException- Returns:
- List of existing values for the configured subtheme discriminator field
- Throws:
PresentationException
IndexUnreachableException
-
generateRandomSortField
Solr supports dynamic random_* sorting fields. Each value represents one particular order, so a random number is required.- Returns:
- Randomized sorting field
-
checkSolrSchemaName
checkSolrSchemaName.
- Returns:
- an array of
String
objects.
-
escapeSpecialCharacters
Escapes all special characters used by SOLR. Details here: https://solr.apache.org/guide/7_3/the-standard-query-parser.html#escaping-special-characters as well as the characters '<' and '>' by adding a '\' before them. Special characters which already are escaped by '\' are not escaped any further making this method idempotent.- Parameters:
string
- the string to escape- Returns:
- the escaped string. if the original string is null, null is also returned
-
unescapeSpecialCharacters
reverts the operation ofescapeSpecialCharacters(String)
.- Parameters:
string
- the string to unescape- Returns:
- the unescaped string
-
cleanUpQuery
- Parameters:
query
-- Returns:
- cleaned up query
-
getBaseFieldName
- Parameters:
fieldName
-- Returns:
- fieldName without language suffix
-
getLanguage
- Parameters:
fieldName
-- Returns:
- language part of fieldName
-
getLocale
- Parameters:
fieldName
-- Returns:
- Locale based on the language part of fieldName
-
getTranslatedMetadata
public static Map<String,List<de.intranda.metadata.multilanguage.IMetadataValue>> getTranslatedMetadata(org.apache.solr.common.SolrDocument doc, Function<String, Boolean> fieldNameFilter) - Parameters:
doc
-fieldNameFilter
-- Returns:
- Map
-
getTranslatedMetadata
public static Map<String,List<de.intranda.metadata.multilanguage.IMetadataValue>> getTranslatedMetadata(org.apache.solr.common.SolrDocument doc, Map<String, List<de.intranda.metadata.multilanguage.IMetadataValue>> metadata, Locale documentLocale, Function<String, Boolean> fieldNameFilter) - Parameters:
doc
-metadata
-documentLocale
-fieldNameFilter
-- Returns:
- Map
-
getReferenceId
- Parameters:
doc
-- Returns:
- Value of MD_REFID in doc, if available
-
getAllUsedLocales
@Deprecated(since="24.09") public static List<Locale> getAllUsedLocales(StructElement structElement) Deprecated.No longer in use, as it can produce a list of only irrelevant localesExtract locales from language-specific metadata fields on the givenStructElement
.- Parameters:
structElement
-- Returns:
- List
-