本文整理汇总了C#中Lucene.Net.Analysis.PerFieldAnalyzerWrapper.Close方法的典型用法代码示例。如果您正苦于以下问题:C# PerFieldAnalyzerWrapper.Close方法的具体用法?C# PerFieldAnalyzerWrapper.Close怎么用?C# PerFieldAnalyzerWrapper.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.Analysis.PerFieldAnalyzerWrapper
的用法示例。
在下文中一共展示了PerFieldAnalyzerWrapper.Close方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DisposeAnalyzerAndFriends
private static void DisposeAnalyzerAndFriends(List<Action> toDispose, PerFieldAnalyzerWrapper analyzer)
{
if (analyzer != null)
analyzer.Close();
foreach (Action dispose in toDispose)
{
dispose();
}
toDispose.Clear();
}
示例2: Build
//.........这里部分代码省略.........
Document = mergedDoc,
IgnoredVersionComponent = this.IgnoreVersionComponent,
TargetDirectory = htmlDir.FullName
};
this.OnStateChanged(State.Templating);
TemplateOutput templateOutput = this.Template.Generate(templateData);
this.OnStateChanged(State.Indexing);
// one stop-word per line
StringReader stopWordsReader = new StringReader(@"missing");
// index output
using (var directory = FSDirectory.Open(indexDir))
using (stopWordsReader)
{
Analyzer analyzer = new StandardAnalyzer(global::Lucene.Net.Util.Version.LUCENE_29, stopWordsReader);
Analyzer titleAnalyzer = new TitleAnalyzer();
IDictionary fieldAnalyzers = new Dictionary<string, Analyzer>
{
{ "title", titleAnalyzer }
};
PerFieldAnalyzerWrapper analyzerWrapper = new PerFieldAnalyzerWrapper(analyzer, fieldAnalyzers);
using (var writer = new IndexWriter(directory, analyzerWrapper, IndexWriter.MaxFieldLength.UNLIMITED))
{
foreach (WorkUnitResult result in templateOutput.Results)
{
//string absPath = Path.Combine(htmlDir.FullName, result.SavedAs);
//HtmlDocument htmlDoc = new HtmlDocument();
//htmlDoc.Load(absPath);
//string htmlTitle = string.Empty;
//var titleNode = htmlDoc.DocumentNode.SelectSingleNode("/html/head/title");
//if (titleNode != null)
// htmlTitle = HtmlEntity.DeEntitize(titleNode.InnerText);
// //.Replace('.', ' ')
// //.Replace('<', ' ')
// //.Replace('>', ' ')
// //.Replace('[', ' ')
// //.Replace(']', ' ')
// //.Replace('(', ' ')
// //.Replace(')', ' ');
//HtmlNode contentNode = htmlDoc.GetElementbyId("content");
//HtmlNode summaryNode = contentNode.SelectSingleNode(".//p[@class='summary']");
//string summary = string.Empty;
//if (summaryNode != null && summaryNode.SelectSingleNode("span[@class='error']") == null)
// summary = HtmlEntity.DeEntitize(summaryNode.InnerText);
//string body = HtmlEntity.DeEntitize(contentNode.InnerText);
//var doc = new Document();
//doc.Add(new Field("uri", new Uri(result.SavedAs, UriKind.Relative).ToString(), Field.Store.YES, Field.Index.NO));
//doc.Add(new Field("aid", result.Asset, Field.Store.YES, Field.Index.NOT_ANALYZED));
//foreach (AssetIdentifier aid in result.Aliases)
// doc.Add(new Field("alias", aid, Field.Store.NO, Field.Index.NOT_ANALYZED));
//foreach (var section in result.Sections)
//{
// doc.Add(new Field("section", section.AssetIdentifier,
// Field.Store.NO,
// Field.Index.NOT_ANALYZED));
//}
//doc.Add(new Field("title", htmlTitle, Field.Store.YES, Field.Index.ANALYZED));
//doc.Add(new Field("summary", summary, Field.Store.YES, Field.Index.ANALYZED));
//doc.Add(new Field("content", body, Field.Store.YES, Field.Index.ANALYZED));
//TraceSources.ContentBuilderSource.TraceVerbose("Indexing document: {0}", doc.ToString());
//writer.AddDocument(doc);
}
writer.Optimize();
writer.Commit();
writer.Close();
}
analyzerWrapper.Close();
analyzer.Close();
directory.Close();
}
this.OnStateChanged(State.Finalizing);
var infoDoc = new XDocument(
new XElement("content",
new XAttribute("created",
XmlConvert.ToString(DateTime.UtcNow, XmlDateTimeSerializationMode.Utc)),
templateOutput.Results.Select(ConvertToXml)));
infoDoc.Save(Path.Combine(targetDirectory, "info.xml"));
this.OnStateChanged(State.Idle);
}
示例3: Build
//.........这里部分代码省略.........
}
this.OnStateChanged(State.Indexing);
string indexLogFile = Path.Combine(logDir.FullName,
string.Format("index_{0:yyyy'_'MM'_'dd'__'HH'_'mm'_'ss}.log", DateTime.Now));
using (TextWriterTraceListener traceListener = new TextWriterTraceListener(indexLogFile))
{
// log everything
traceListener.Filter = new EventTypeFilter(SourceLevels.All);
TraceSources.ContentBuilderSource.Switch.Level = SourceLevels.All;
TraceSources.ContentBuilderSource.Listeners.Add(traceListener);
// one stop-word per line
StringReader stopWordsReader = new StringReader(@"missing");
// index output
using (var directory = FSDirectory.Open(indexDir))
using (stopWordsReader)
{
Analyzer analyzer = new StandardAnalyzer(global::Lucene.Net.Util.Version.LUCENE_30, stopWordsReader);
Analyzer titleAnalyzer = new TitleAnalyzer();
IDictionary<string, Analyzer> fieldAnalyzers = new Dictionary<string, Analyzer>
{
{ "title", titleAnalyzer }
};
PerFieldAnalyzerWrapper analyzerWrapper = new PerFieldAnalyzerWrapper(analyzer, fieldAnalyzers);
using (
var writer = new IndexWriter(directory, analyzerWrapper, IndexWriter.MaxFieldLength.UNLIMITED))
{
var saResults =
templateOutput.Results.Select(wur => wur.WorkUnit).OfType<StylesheetApplication>();
var saDict = saResults.ToDictionary(sa => sa.Asset);
var indexResults = saDict.Values.Where(sa => sa.SaveAs.EndsWith(".xml"));
foreach (var sa in indexResults)
{
string absPath = Path.Combine(htmlDir.FullName, sa.SaveAs);
XDocument indexDoc = XDocument.Load(absPath);
string assetId = indexDoc.Root.Attribute("assetId").Value;
string title = indexDoc.Root.Element("title").Value.Trim();
string summary = indexDoc.Root.Element("summary").Value.Trim();
string text = indexDoc.Root.Element("text").Value.Trim();
var ssApplication = saDict[AssetIdentifier.Parse(assetId)];
var doc = new Document();
doc.Add(new Field("uri",
new Uri(ssApplication.SaveAs, UriKind.Relative).ToString(),
Field.Store.YES,
Field.Index.NO));
doc.Add(new Field("aid", ssApplication.Asset, Field.Store.YES, Field.Index.NOT_ANALYZED));
foreach (AssetIdentifier aid in ssApplication.Aliases)
doc.Add(new Field("alias", aid, Field.Store.NO, Field.Index.NOT_ANALYZED));
foreach (var section in ssApplication.Sections)
{
doc.Add(new Field("section",
section.AssetIdentifier,
Field.Store.NO,
Field.Index.NOT_ANALYZED));
}
doc.Add(new Field("title", title, Field.Store.YES, Field.Index.ANALYZED));
doc.Add(new Field("summary", summary, Field.Store.YES, Field.Index.ANALYZED));
doc.Add(new Field("content", text, Field.Store.NO, Field.Index.ANALYZED));
TraceSources.ContentBuilderSource.TraceVerbose("Indexing document: {0}", doc.ToString());
writer.AddDocument(doc);
}
writer.Optimize();
writer.Commit();
}
analyzerWrapper.Close();
analyzer.Close();
}
TraceSources.ContentBuilderSource.Listeners.Remove(traceListener);
}
this.OnStateChanged(State.Finalizing);
var infoDoc = new XDocument(
new XElement("content",
new XAttribute("created",
XmlConvert.ToString(DateTime.UtcNow, XmlDateTimeSerializationMode.Utc)),
templateOutput.Results.Select(this.ConvertToXml)));
infoDoc.Save(Path.Combine(targetDirectory, "info.xml"));
this.OnStateChanged(State.Idle);
}