class CrescentHighlighter {

	public String getBestFragment(CrescentCollectionField field, String value, Query query, Analyzer analyzer) throws CrescentInvalidRequestException {
		String fragment = "";

		logger.debug("fieldName : {}", field.getName());

		try {
			
			logger.debug("query for highlighter : {}" , query);

			QueryScorer scorer = new QueryScorer(query);

			Highlighter highlighter = new Highlighter(formatter, scorer);
			highlighter.setTextFragmenter(new SimpleFragmenter(50));


			TokenStream stream = analyzer.tokenStream(field.getName(), new StringReader(value));
			fragment = highlighter.getBestFragments(stream, value, 1, "...");

			if(fragment == null || "".equals(fragment)) {
				if(value.length() > 100) {
					fragment = value.substring(0,100);
				} else {
					fragment = value;
				}
			}

			return fragment;
			
		} catch (IOException e) {

			logger.error("error in crescent highlighter", e);

			return value;
			
		} catch (InvalidTokenOffsetsException e) {

			logger.error("error in crescent highlighter", e);

			return value;
		}

	}

}