Class LuceneUtils


  • public class LuceneUtils
    extends Object
    Utilities for Lucene-related functionality in applications.

    Some logic copied from the DateTools class in Lucene 4.4. Done to maintain Lucene independent assumptions about how dates should be formatted for indexing. This is required as there are many implicit baked in assumptions about date formatting around confluence, we don't want it to be changed in the future.

    Since:
    7.16.0
    • Constructor Detail

      • LuceneUtils

        public LuceneUtils()
    • Method Detail

      • dateToString

        public static String dateToString​(Date date)
        Converts a Date into a String using the Lucene index format, with a millisecond resolution.
        See Also:
        dateToString(java.util.Date)
      • dateToString

        public static String dateToString​(Date date,
                                          LuceneUtils.Resolution resolution)
        Converts a Date to a string suitable for indexing.
        Parameters:
        date - the date to be converted
        resolution - the desired resolution
        Returns:
        a string in format yyyyMMddHHmmssSSS or shorter, depending on resolution; using GMT as timezone
      • stringToDate

        public static Date stringToDate​(String s)
        Converts a String from the Lucene index format into a Date. Attempts conversion using both new and old date formats. If the String is blank or null, returns a new Date object.

        If the string is in the old format, this method will log a warning a limited number of times per application run to recommend that the user upgrades the index format.