我需要在StandardAnalyzer上调用.Dispose(),还是在IndexWriter上调用.Dispose()处置其后代? [英] Do I need to call .Dispose() on the StandardAnalyzer, or does .Dispose() on the IndexWriter dispose its descendants?

查看:104
本文介绍了我需要在StandardAnalyzer上调用.Dispose(),还是在IndexWriter上调用.Dispose()处置其后代?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Lucene.Net中初始化IndexWriter看起来像这样:

Initializing an IndexWriter in Lucene.Net looks like this:

var analyzer = new Lucene.Net.Analysis.Standard.StandardAnalyzer(version);
var indexWriterConfig = new Lucene.Net.Index.IndexWriterConfig(version, analyzer);
Index = new Lucene.Net.Index.IndexWriter(luceneDir, indexWriterConfig);

也就是说,没有分析器就无法实例化IndexWriter.因此,我希望在IndexWriter上调用.Dispose()会释放其子级,包括分析器.但是浏览代码,到目前为止,我还没有看到这种情况.我错过了吗?

That is, you can't instantiate an IndexWriter without an Analyzer. So, I would expect that calling .Dispose() on the IndexWriter would dispose its children, including the Analyzer. However browsing the code I don't see that happening - so far. Have I missed it?

所以:在IndexWriter上调用.Dispose()是否会丢弃分析器,如果没有,为什么呢?

So: Does calling .Dispose() on the IndexWriter dispose the Analyzer, and if not, why not?

推荐答案

IndexWriter不会丢弃分析器.

IndexWriter does not dispose of the analyzer.

它不会丢弃分析仪,因为它不能确保您不会在其他地方使用该分析仪.它是通过构造函数获得的引用,它可能会在不知道的情况下被其他IndexWriter实例使用.

It doesn't dispose of the analyzer because it cannot be sure that you will not be using the analyzer elsewhere. It's a reference that it got via the constructor, it could be used by other IndexWriter instances without it knowing.

这与所有权有关;您创建了分析器,并允许编写者使用它.因此,处置分析仪是您的责任.

It's about ownership; you created the analyzer and let the writer use it. It is thus your responsibility to dispose of the analyzer.

这篇关于我需要在StandardAnalyzer上调用.Dispose(),还是在IndexWriter上调用.Dispose()处置其后代?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆