public void TestGenerateHtmlPreviewText_ReturnRawContent() { var generator = new QueryGenerator(); var content = "My ABC\r\nIs A ABC CONTENT\r\nIt's abc in lowercase\r\nIt's Abc in mix\r\nNot AB with C"; var result = CodeIndexSearcher.GenerateHtmlPreviewText(generator.GetQueryFromStr("NotExistWord"), content, int.MaxValue, LucenePool.GetAnalyzer()); Assert.IsEmpty(result); result = CodeIndexSearcher.GenerateHtmlPreviewText(generator.GetQueryFromStr("NotExistWord"), content, 10, LucenePool.GetAnalyzer(), returnRawContentWhenResultIsEmpty: true); Assert.AreEqual(HttpUtility.HtmlEncode(content), result); result = CodeIndexSearcher.GenerateHtmlPreviewText(null, content, 10, LucenePool.GetAnalyzer(), returnRawContentWhenResultIsEmpty: true); Assert.AreEqual(HttpUtility.HtmlEncode(content), result); }
public void TestGetQueryParserAndAnalyzer() { Assert.NotNull(LucenePool.GetQueryParser()); Assert.NotNull(LucenePool.GetAnalyzer()); }
public void TestGenerateHtmlPreviewText() { var generator = new QueryGenerator(); var content = "My ABC\r\nIs A ABC CONTENT\r\nIt's abc in lowercase\r\nIt's Abc in mix\r\nNot AB with C"; var result = CodeIndexSearcher.GenerateHtmlPreviewText(generator.GetQueryFromStr("ABC"), content, int.MaxValue, LucenePool.GetAnalyzer()); Assert.AreEqual(@"My <label class='highlight'>ABC</label> Is A <label class='highlight'>ABC</label> CONTENT It's <label class='highlight'>abc</label> in lowercase It's <label class='highlight'>Abc</label> in mix Not AB with C", result); result = CodeIndexSearcher.GenerateHtmlPreviewText(generator.GetQueryFromStr("ABC"), content, 10, LucenePool.GetAnalyzer()); Assert.AreEqual(@"My <label class='highlight'>ABC</label> Is A <label class='highlight'>ABC</label>... It's <label class='highlight'>Abc</label>", result); }
public void TestGenerateHtmlPreviewText_ContentTooLong() { var generator = new QueryGenerator(); var content = "My ABC\r\nIs A ABC CONTENT\r\nIt's abc in lowercase\r\nIt's Abc in mix\r\nNot AB with C"; var result = CodeIndexSearcher.GenerateHtmlPreviewText(generator.GetQueryFromStr("ABC"), content, int.MaxValue, LucenePool.GetAnalyzer(), maxContentHighlightLength: 20); Assert.AreEqual(@"Content is too long to highlight", result); }