From 12c31ef28e1396f652f6f80f84480c0833182150 Mon Sep 17 00:00:00 2001 From: James Moger Date: Wed, 21 Mar 2012 20:01:30 -0400 Subject: [PATCH] Restore the leading hunk of the first line of a fragment Also correctly determine the line number of a fragment. --- src/com/gitblit/LuceneExecutor.java | 95 +++++++++++++++----------- src/com/gitblit/utils/StringUtils.java | 26 +++++++ 2 files changed, 81 insertions(+), 40 deletions(-) diff --git a/src/com/gitblit/LuceneExecutor.java b/src/com/gitblit/LuceneExecutor.java index 65e1b2be..12f23050 100644 --- a/src/com/gitblit/LuceneExecutor.java +++ b/src/com/gitblit/LuceneExecutor.java @@ -1114,17 +1114,14 @@ public class LuceneExecutor implements Runnable { */ private String getHighlightedFragment(Analyzer analyzer, Query query, String content, SearchResult result) throws IOException, InvalidTokenOffsetsException { - content = content == null ? "":StringUtils.escapeForHtml(content, false); - + if (content == null) { + content = ""; + } + + int fragmentLength = SearchObjectType.commit == result.type ? 512 : 150; + QueryScorer scorer = new QueryScorer(query, "content"); - Fragmenter fragmenter; - - // TODO improve the fragmenter - hopefully on line breaks - if (SearchObjectType.commit == result.type) { - fragmenter = new SimpleSpanFragmenter(scorer, 1024); - } else { - fragmenter = new SimpleSpanFragmenter(scorer, 150); - } + Fragmenter fragmenter = new SimpleSpanFragmenter(scorer, fragmentLength); // use an artificial delimiter for the token String termTag = "