Class LuceneUtils


  • @ThreadSafe
    public final class LuceneUtils
    extends java.lang.Object

    Lucene utils is a set of utilize written to make constructing Lucene queries simpler.

    Author:
    Jeremy Long
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void appendEscapedLuceneQuery​(java.lang.StringBuilder buf, java.lang.CharSequence text)
      Appends the text to the supplied StringBuilder escaping Lucene control characters in the process.
      static java.lang.String escapeLuceneQuery​(java.lang.CharSequence text)
      Escapes the text passed in so that it is treated as data instead of control characters.
      static boolean isKeyword​(java.lang.String term)
      Determines if the given term is a Lucene keyword (e.g.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • isKeyword

        public static boolean isKeyword​(java.lang.String term)
        Determines if the given term is a Lucene keyword (e.g. AND, OR, NOT).
        Parameters:
        term - the term to test
        Returns:
        trueif the term is a keyword; otherwise false
      • appendEscapedLuceneQuery

        public static void appendEscapedLuceneQuery​(java.lang.StringBuilder buf,
                                                    java.lang.CharSequence text)
        Appends the text to the supplied StringBuilder escaping Lucene control characters in the process.
        Parameters:
        buf - a StringBuilder to append the escaped text to
        text - the data to be escaped
      • escapeLuceneQuery

        public static java.lang.String escapeLuceneQuery​(java.lang.CharSequence text)
        Escapes the text passed in so that it is treated as data instead of control characters.
        Parameters:
        text - data to be escaped
        Returns:
        the escaped text.