Class SolrTools

java.lang.Object
io.goobi.viewer.solr.SolrTools

public final class SolrTools extends Object
Static utility methods for Solr.
  • Method Details

    • getSolrSortFieldsAsList

      public static List<StringPair> getSolrSortFieldsAsList(String solrSortFields, String splitFieldsBy, String splitNameOrderBy)
      Returns the comma-separated sorting fields in solrSortFields as a List.
      Parameters:
      solrSortFields - a String object.
      splitFieldsBy - String by which the individual field configurations are split
      splitNameOrderBy - String by which the field name and sorting order are split
      Returns:
      a List object.
    • getAsString

      public static String getAsString(Object fieldValue)
      Parses a Solr-Field value in order to return it as String.
      Parameters:
      fieldValue - a Object object.
      Returns:
      a String object.
    • getAsBoolean

      public static Boolean getAsBoolean(Object fieldValue)
      Parameters:
      fieldValue -
      Returns:
      Boolean
    • getAsString

      public static String getAsString(Object fieldValue, String separator)
      Parameters:
      fieldValue -
      separator -
      Returns:
      String
    • getAsInt

      public static Integer getAsInt(Object fieldValue)

      getAsInt.

      Parameters:
      fieldValue - a Object object.
      Returns:
      a Integer object.
    • getAsLong

      public static Long getAsLong(Object fieldValue)

      getAsLong.

      Parameters:
      fieldValue - a Object object.
      Returns:
      a Long object.
    • getSingleFieldValue

      public static Object getSingleFieldValue(org.apache.solr.common.SolrDocument doc, String field)

      getSingleFieldValue.

      Parameters:
      doc - a SolrDocument object.
      field - a String object.
      Returns:
      a Object object.
    • getSingleFieldStringValue

      public static String getSingleFieldStringValue(org.apache.solr.common.SolrDocument doc, String field)

      getSingleFieldStringValue.

      Parameters:
      doc - a SolrDocument object.
      field - a String object.
      Returns:
      a String object.
    • getSingleFieldIntegerValue

      public static Integer getSingleFieldIntegerValue(org.apache.solr.common.SolrDocument doc, String field)

      getSingleFieldIntegerValue.

      Parameters:
      doc - a SolrDocument object.
      field - a String object.
      Returns:
      a Integer object.
    • getSingleFieldLongValue

      public static Long getSingleFieldLongValue(org.apache.solr.common.SolrDocument doc, String field)

      getSingleFieldLongValue.

      Parameters:
      doc - a SolrDocument object.
      field - a String object.
      Returns:
      a Long object.
    • getSingleFieldBooleanValue

      public static boolean getSingleFieldBooleanValue(org.apache.solr.common.SolrDocument doc, String field)

      getSingleFieldBooleanValue.

      Parameters:
      doc - a SolrDocument object.
      field - a String object.
      Returns:
      a Boolean object.
    • 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.
      Parameters:
      doc - a SolrDocument object.
      fieldName - a String object.
      Returns:
      a List object.
    • getFieldValueMap

      public static Map<String,List<String>> getFieldValueMap(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 - a SolrDocument 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 - a SolrDocument object.
      Returns:
      a Map object.
    • getMultiLanguageMetadata

      public static List<de.intranda.metadata.multilanguage.IMetadataValue> getMultiLanguageMetadata(Map<String,List<String>> mdValues)

      getMultiLanguageMetadata.

      Parameters:
      mdValues - a Map object.
      Returns:
      a List object.
    • getMetadataValuesForLanguage

      public static Map<String,List<String>> getMetadataValuesForLanguage(org.apache.solr.common.SolrDocument doc, String key)

      getMetadataValuesForLanguage.

      Parameters:
      doc - The document containing the metadata
      key - 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

      public static Map<String,List<String>> getMetadataValuesForLanguage(StructElement doc, String key)

      getMetadataValuesForLanguage.

      Parameters:
      doc - The document containing the metadata
      key - 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

      public static boolean isLanguageCodedField(String fieldName)
      Parameters:
      fieldName -
      Returns:
      true if fieldName contains _LANG_; false otherwise
    • isHasWrongLanguageCode

      public static boolean isHasWrongLanguageCode(String field, String language)
      Parameters:
      field -
      language -
      Returns:
      true if language code different
    • isQuerySyntaxError

      public static boolean isQuerySyntaxError(Exception e)

      isQuerySyntaxError.

      Parameters:
      e - a Exception object.
      Returns:
      a boolean.
    • extractExceptionMessageHtmlTitle

      public static String extractExceptionMessageHtmlTitle(String exceptionMessage)
      Parameters:
      exceptionMessage -
      Returns:
      Extracted message
    • getTranslations

      public static Optional<de.intranda.metadata.multilanguage.IMetadataValue> getTranslations(String fieldName, org.apache.solr.common.SolrDocument doc)

      getTranslations.

      Parameters:
      fieldName - a String object.
      doc - a SolrDocument object.
      Returns:
      a Optional object.
    • getTranslations

      public static Optional<de.intranda.metadata.multilanguage.IMetadataValue> getTranslations(String fieldName, org.apache.solr.common.SolrDocument doc, BinaryOperator<String> combiner)

      getTranslations.

      Parameters:
      fieldName - a String object.
      doc - a SolrDocument object.
      combiner - a BinaryOperator 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 - a String object.
      doc - a StructElement object.
      combiner - a BinaryOperator 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 - a String object.
      doc - a StructElement object.
      translationLocales -
      combiner - a BinaryOperator object.
      Returns:
      a Optional object.
    • isHasImages

      public static boolean isHasImages(org.apache.solr.common.SolrDocument doc) throws IndexUnreachableException

      isHasImages.

      Parameters:
      doc - a SolrDocument object. Needs to contain metadata fields SolrConstants.FILENAME and SolrConstants.THUMBNAIL
      Returns:
      true if record described by doc has images; false otherwise
      Throws:
      IndexUnreachableException - if any.
    • getProcessedConditions

      public static String getProcessedConditions(String conditions)
      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 - a String object.
      filterQuery - a String 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 - a String object.
      filterQuery - a String 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

      public static String generateRandomSortField()
      Solr supports dynamic random_* sorting fields. Each value represents one particular order, so a random number is required.
      Returns:
      Randomized sorting field
    • checkSolrSchemaName

      public static String[] checkSolrSchemaName()

      checkSolrSchemaName.

      Returns:
      an array of String objects.
    • escapeSpecialCharacters

      public static String escapeSpecialCharacters(String string)
      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

      public static String unescapeSpecialCharacters(String string)
      reverts the operation of escapeSpecialCharacters(String).
      Parameters:
      string - the string to unescape
      Returns:
      the unescaped string
    • cleanUpQuery

      public static String cleanUpQuery(String query)
      Parameters:
      query -
      Returns:
      cleaned up query
    • getBaseFieldName

      public static String getBaseFieldName(String fieldName)
      Parameters:
      fieldName -
      Returns:
      fieldName without language suffix
    • getLanguage

      public static String getLanguage(String fieldName)
      Parameters:
      fieldName -
      Returns:
      language part of fieldName
    • getLocale

      public static Locale getLocale(String fieldName)
      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

      public static final String getReferenceId(org.apache.solr.common.SolrDocument doc)
      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 locales
      Extract locales from language-specific metadata fields on the given StructElement.
      Parameters:
      structElement -
      Returns:
      List