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 StringcleanUpQuery(String query) static StringescapeSpecialCharacters(String string) Escapes all special characters used by SOLR.static StringextractExceptionMessageHtmlTitle(String exceptionMessage) static StringSolr supports dynamic random_* sorting fields.getAllUsedLocales(StructElement structElement) Deprecated.No longer in use, as it can produce a list of only irrelevant localesstatic BooleangetAsBoolean(Object fieldValue) static IntegergetAsInt.static LonggetAsLong.static StringgetAsString(Object fieldValue) Parses a Solr-Field value in order to return it as String.static StringgetAsString(Object fieldValue, String separator) getAvailableValuesForField(String field, String filterQuery) getAvailableValuesForField.getAvailableValuesForField(String field, String filterQuery, boolean useFacetField) getAvailableValuesForField.static StringgetBaseFieldName(String fieldName) getFieldValueMap(org.apache.solr.common.SolrDocument doc) Converts the given SolrDocument to a value map.static StringgetLanguage(String fieldName) static LocalegetMetadataValues(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 StringgetProcessedConditions(String conditions) static final StringgetReferenceId(org.apache.solr.common.SolrDocument doc) static booleangetSingleFieldBooleanValue(org.apache.solr.common.SolrDocument doc, String field) getSingleFieldBooleanValue.static IntegergetSingleFieldIntegerValue(org.apache.solr.common.SolrDocument doc, String field) getSingleFieldIntegerValue.static LonggetSingleFieldLongValue(org.apache.solr.common.SolrDocument doc, String field) getSingleFieldLongValue.static StringgetSingleFieldStringValue(org.apache.solr.common.SolrDocument doc, String field) getSingleFieldStringValue.static ObjectgetSingleFieldValue(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 insolrSortFieldsas 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 booleanstatic booleanisAnchor(org.apache.solr.common.SolrDocument doc) static booleanisGroup(MetadataContainer doc) static booleanisGroup(org.apache.solr.common.SolrDocument doc) static booleanisHasImages(org.apache.solr.common.SolrDocument doc) isHasImages.static booleanisHasWrongLanguageCode(String field, String language) static booleanisLanguageCodedField(String fieldName) static booleanisQuerySyntaxError.static booleanisWork(MetadataContainer doc) static booleanisWork(org.apache.solr.common.SolrDocument doc) static StringunescapeSpecialCharacters(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 insolrSortFieldsas 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- aSolrDocumentobject.- Returns:
- a
Mapobject.
-
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- aSolrDocumentobject.- Returns:
- a
Mapobject.
-
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
-
isGroup
- 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
-
isAnchor
- 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
-
isWork
- 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- aExceptionobject.- 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- aStringobject.doc- aSolrDocumentobject.combiner- aBinaryOperatorobject.- Returns:
- a
Optionalobject.
-
getTranslations
public static Optional<de.intranda.metadata.multilanguage.IMetadataValue> getTranslations(String fieldName, StructElement doc, BinaryOperator<String> combiner) getTranslations.
- Parameters:
fieldName- aStringobject.doc- aStructElementobject.combiner- aBinaryOperatorobject.- Returns:
- a
Optionalobject.
-
getTranslations
public static Optional<de.intranda.metadata.multilanguage.IMetadataValue> getTranslations(String fieldName, StructElement doc, List<Locale> translationLocales, BinaryOperator<String> combiner) getTranslations.
- Parameters:
fieldName- aStringobject.doc- aStructElementobject.translationLocales-combiner- aBinaryOperatorobject.- Returns:
- a
Optionalobject.
-
isHasImages
public static boolean isHasImages(org.apache.solr.common.SolrDocument doc) throws IndexUnreachableException isHasImages.
- Parameters:
doc- aSolrDocumentobject. Needs to contain metadata fieldsSolrConstants.FILENAMEandSolrConstants.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- aStringobject.filterQuery- aStringobject.- 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- aStringobject.filterQuery- aStringobject.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:
PresentationExceptionIndexUnreachableException
-
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
Stringobjects.
-
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
-