Beispiel #1
0
 public static string GetContentDisplayHtml(this string content, bool isSecureConnection)
 {
     content = HtmlUtil.AposToHtml(HtmlUtil.LineBreaksToHtml(HtmlUtil.StripHtmlComments(content)));
     content = isSecureConnection
         ? ReplaceScheme(content, "http:", "https:")
         : ReplaceScheme(content, "https:", "http:");
     return(content);
 }
Beispiel #2
0
        public void Summarize(string summaryText, IList <string> bulletPointsText, string contentHtml,
                              bool includeContent, out string digestText, out string bodyText)
        {
            var digestBuilder = new StringBuilder(DigestMaxSize);

            // Add summary.

            digestBuilder.Append(summaryText);

            // Add bullet points.

            if (bulletPointsText != null)
            {
                foreach (var bulletPoint in bulletPointsText)
                {
                    if (!string.IsNullOrEmpty(bulletPoint))
                    {
                        digestBuilder.AppendFormat(" \x2022\x00a0{0}", bulletPoint.Trim()); // &bull;&nbsp;text
                    }
                }
            }

            // Check whether we need to go through the content.

            // TODO: consider using MS Search HTML IFilter instead
            var contentText = HttpUtility.HtmlDecode(
                HtmlUtil.StripHtmlTags(
                    HtmlUtil.AposToHtml(contentHtml)));

            contentText = contentText.Replace('\x0095', '\x2022'); // replace Windows Western bullet with Unicode bullet

            if (!includeContent && digestBuilder.Length > 0)
            {
                digestText = digestBuilder.ToString();
                bodyText   = contentText;
                return;
            }

            // Add the content extract (up to DigestMaxSize in total).

            Analyzer   analyzer      = new SimpleAnalyzer();
            var        contentStream = analyzer.tokenStream(Field, new java.io.StringReader(contentText));
            var        offset        = (OffsetAttribute)contentStream.addAttribute(typeof(OffsetAttribute));
            Fragmenter fragmenter    = new SimpleFragmenter(DigestMaxSize - digestBuilder.Length);

            fragmenter.start(contentText, contentStream);

            var endOffset = 0;

            while (contentStream.incrementToken())
            {
                endOffset = offset.endOffset();
                if (fragmenter.isNewFragment())
                {
                    break;
                }
            }

            if (digestBuilder.Length > 0)
            {
                digestBuilder.Append(' ');
            }

            digestBuilder.Append(contentText, 0, endOffset);
            digestBuilder.Append(" ...");
            digestText = digestBuilder.ToString();
            bodyText   = contentText.Substring(endOffset);
        }