【发布时间】:2016-09-13 10:55:06
【问题描述】:
我在 umbraco 中设置 Lucene 搜索引擎时遇到问题。我正在尝试搜索存储在 Umbraco 创建的默认索引中的数据。搜索方法如下:
private DictionaryResult GetRowContent(
Lucene.Net.Highlight.Highlighter highlighter,
Lucene.Net.Analysis.Standard.StandardAnalyzer analyzer
,Lucene.Net.Documents.Document doc1, string criteria)
{
JavaScriptSerializer jsScriptSerializer = new JavaScriptSerializer();
DictionaryResult controls = new DictionaryResult();
Lucene.Net.Analysis.TokenStream stream = analyzer.TokenStream("", new StringReader(doc1.Get("bodyContent")));
dynamic rowContentHtmlDocument = JObject.Parse(((JValue)doc1.Get("bodyContent")).ToString(CultureInfo.CurrentCulture));
foreach (dynamic section in rowContentHtmlDocument.sections)
{
foreach (var row in section.rows)
{
foreach (var area in row.areas)
{
foreach (var control in area.controls)
{
if (control != null && control.editor != null) // && control.editor.view != null)
{
JObject rowContentHtml = null;
try
{
rowContentHtml = JObject.Parse(((JContainer)control)["value"].ToString());
}
catch (Exception e)
{
}
if (rowContentHtml != null)
{
try
{
var macroParamsDictionary = JObject.Parse(((JContainer)rowContentHtml)["macroParamsDictionary"].ToString());
var documentText = macroParamsDictionary.GetValue("dokument");
if (documentText != null)
{
var document = documentText.ToString().Replace(""", "\"");
dynamic documents = jsScriptSerializer.Deserialize<dynamic>(document);
foreach (Dictionary<string, object> doc in documents)
{
if (doc.ContainsKey("FileName") && doc.ContainsKey("DocumentId"))
{
if (doc["FileName"].ToString().Length > 0 &&
doc["FileName"].ToString().ToLower().Contains(criteria.ToLower()))
{
controls.Add(new RowResult()
{
Type = 0,
Object = new Document()
{
DocumentName = doc["FileName"].ToString(),//highlighter.GetBestFragments(stream, doc["FileName"].ToString(), 1, "..."),
DocId = Guid.Parse(doc["DocumentId"].ToString())
} // StringBuilder(@"<a href=" + Url.Action("DownloadDocument", "Document", new { DocumentId = doc["DocumentId"] }) + "> " + @doc["FileName"] + "</a>").ToString()
}
);
}
}
}
}
}
catch (Exception e)
{
}
}
else
{
var text = HtmlRemoval.StripTagsRegex(((JContainer)control)["value"].ToString()).Replace("ë", "e").Replace("ç", "c");
var textResultFiltered = highlighter.GetBestFragments(stream,doc1.Get("bodyContent"), 5, "...");
controls.Add(new RowResult()
{
Type = 1,
Object = textResultFiltered
});
}
}
}
}
}
}
return controls;
}
在这里,我试图从简单的 html 内容中过滤宏文档并以不同的方式呈现。但在这部分的最后
var text = HtmlRemoval.StripTagsRegex(((JContainer)control)["value"].ToString()).Replace("ë", "e").Replace("ç", "c");
var textResultFiltered = highlighter.GetBestFragments(stream,doc1.Get("bodyContent"), 5, "...");
controls.Add(new RowResult()
{
Type = 1,
Object = textResultFiltered
});
它在搜索中包含宏。结果我得到了文档属性,但突出显示的 html 内容具有如下宏内容:
6th Edition V413HAV.pdf","FileContent"... Framework 6th Edition V413HAV.pdf","... with Java 8 - 1st Edition (2015) - Copy.pdf"... 4.5 Framework 6th Edition V413HAV.pdf","... And The NET 4.5 Framework 6th Edition V413HAV.pdf" which is coming from Json data of the macro. Any idea how to exclude the macros from searching or to customize the hmtl content not to search on specific macro ? Thanks in advance.
我正在参考此链接来创建荧光笔等... Link to Lucene example
知道如何防止搜索宏或将它们从突出显示的内容中排除吗?
【问题讨论】:
标签: lucene macros umbraco7 umbraco6