Exemplo n.º 1
0
 public static string GetOriginalHighlightedContents(SearchResult sr)
 {
     StringBuilder result = new StringBuilder("<html><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"><style>.highlight{background:yellow;}</style><body><font face=Arial size=5>");
     string contents = sr.GetDocContents();
     SimpleHTMLFormatter formatter = new SimpleHTMLFormatter("<span class=\"highlight\">", "</span>");
     SimpleFragmenter fragmenter = new SimpleFragmenter(sr.FragmentSize);
     Highlighter hiliter = new Highlighter(formatter, new QueryScorer(sr.QueryParser.Parse(sr.Query)));
     hiliter.SetTextFragmenter(fragmenter);
     int numfragments = contents.Length / fragmenter.GetFragmentSize() + 1;
     TokenStream tokenstream = sr.Analyzer.TokenStream("contents", new StringReader(contents));
     result.Append(hiliter.GetBestFragments(tokenstream, contents, numfragments, "..."));
     result.Append("</font></body></html>");
     result.Replace("\n", "<br/>");
     return result.ToString();
 }
Exemplo n.º 2
0
 public static string GetHilitedContentsWithoutHeaders(SearchResult sr)
 {
     StringBuilder result = new StringBuilder("<font face=Arial size=5>");
     string contents = sr.GetDocContents();
     SimpleHTMLFormatter formatter = new SimpleHTMLFormatter("<span class=\"highlight\">", "</span>");
     SimpleFragmenter fragmenter = new SimpleFragmenter(sr.FragmentSize);
     Highlighter hiliter = new Highlighter(formatter, new QueryScorer(sr.QueryParser.Parse(sr.Query)));
     hiliter.SetTextFragmenter(fragmenter);
     int numfragments = contents.Length / fragmenter.GetFragmentSize() + 1;
     TokenStream tokenstream = sr.Analyzer.TokenStream("contents", new StringReader(contents));
     result.Append(hiliter.GetBestFragments(tokenstream, contents, numfragments, "..."));
     result.Append("</font>");
     result.Replace("\n", "<br/>");
     return result.ToString();
 }