code: private static int startFragment(StringBuilder sb, String text, int offset, int limit)
     {
        if (limit == 0)
        {
           // append all
           sb.append(text.substring(0, offset));
           return offset;
        }
        String intro = "... ";
        int start = offset;
        for (int i = offset - 1; i >= limit; i--)
        {
           if (Character.isWhitespace(text.charAt(i)))
           {
              // potential start
              start = i + 1;
              if (i - 1 >= limit && PUNCTUATION.get(text.charAt(i - 1)))
              {
                 // start of sentence found
                 intro = "";
                 break;
              }
           }
        }
        sb.append(intro).append(text.substring(start, offset));
        return offset - start;
     }
docs: Writes the start of a fragment to the string buffer <code>sb</code>. The
  first occurrence of a matching term is indicated by the
  <code>offset</code> into the <code>text</code>.
  
  @param sb     where to append the start of the fragment.
  @param text   the original text.
  @param offset the start offset of the first matching term in the
  fragment.
  @param limit  do not go back further than <code>limit</code>.
  @return the length of the start fragment that was appended to
  <code>sb</code>.