简体   繁体   English

为什么lucene 4.0为IndexWriter类删除了两个构造函数?

[英]why lucene 4.0 delete two constructor for IndexWriter class?

there used to be three constructors, such as 曾经有过三个构造函数,比如

IndexWriter(String, Analyzer, boolean)
IndexWriter(String, Analyzer, boolean)
IndexWriter(Directory,Analyzer, boolean)

but there is only one constructor now, which brings some inconvinence, so why the other two constructors are deleted? 但是现在只有一个构造函数,这会带来一些不确定性,那么为什么要删除其他两个构造函数呢?

is this kind of bad api design to delete the two constructors? 删除这两个构造函数是不是这种糟糕的api设计?

Short answer: The overall change in IndexWriter constructor strategy over time has largely been to deal with reducing the proliferation of constructor options and to better encapsulate the options being used so they could be shared & reused. 简短回答:IndexWriter构造函数策略随时间的整体变化主要是为了减少构造函数选项的扩散,并更好地封装所使用的选项,以便共享和重用它们。

Longer Answer: The three arg constructors you are referring to (Directory/String/File, Analyzer, boolean) were deprecated in Lucene 2.4 which was released 2008-Oct-11 and then removed in Lucene 3.0 (2009-Nov-26) 更长的答案:你所指的三个arg构造函数(目录/字符串/文件,分析器,布尔值)在2008年10月11日发布的Lucene 2.4中被弃用,然后在Lucene 3.0中删除(2009年11月26日)

Bottom Line: There was a full years notice that those constructors were eventually going away, and they were removed in a release that came out almost 3 years ago. 一句话:有一整年的通知,这些建设者最终会离开,他们在大约3年前发布的版本中被删除。

If you are interested in upgrading to a non-ancient version of Lucene, and your biggest complaint is that your three arg IndexWriter constructor no longer exists, then just change your code that looks like this... 如果您有兴趣升级到非古代版本的Lucene,并且您最大的抱怨是您的三个arg IndexWriter构造函数不再存在,那么只需更改看起来像这样的代码......

IndexWriter w = new IndexWriter(dir, analyzer, true);

...so that it looks like this... ......所以它看起来像......

IndexWriterConfig c = new IndexWriterConfig(Version.LUCENE_36,analyzer).setOpenMode(CREATE_OR_APPEND)
IndexWriter w = new IndexWriter(dir, config);

...but i would suggest that instead of just blindly making that change, you actually look at the docs for the IndexWriterConfig and consider some of the various options that are now available. ...但我建议您不要盲目地进行更改,而是实际查看IndexWriterConfig的文档并考虑现在可用的各种选项。

Actually, there were 5 constructors (not 3) for IndexWriter in Lucene 3.0.3, the last GA release version before IndexWriterConfig came out. 实际上,在Lucene 3.0.3中有5个构造函数(不是3个)用于IndexWriter ,这是在IndexWriterConfig出现之前的最后一个GA版本。 Here is the original ticket about the change (ie IndexWriterConfig and the deprecation for removal of the other constructors). 这是关于更改原始票证 (即IndexWriterConfig和删除其他构造函数的弃用)。 The link to the discussion near the top of the ticket no longer works, but Nabble has a copy of it . 票证顶部附近讨论的链接不再有效,但Nabble有一份副本

"Is this kind of bad api design to delete the two constructors?" “这种糟糕的api设计是否会删除这两个构造函数?” That is an open-ended question that the SO FAQ says should not be asked on SO . 这是一个开放式的问题, SO常见问题解答说不应该问SO In any case, if you want to know the Lucene developers' intentions in making a particular decision, there is no better way to find out than asking the Lucene developers directly, ie on the official Lucene mailing lists , or opening a ticket on the Lucene issue-tracking system . 无论如何,如果你想知道Lucene开发人员做出特定决定的意图,没有比直接询问Lucene开发人员更好的方法,即在Lucene官方邮件列表上 ,或在Lucene上开票问题跟踪系统

If I am to speculate, here are some possibilities: 如果我推测,这里有一些可能性:

  • They might have overlooked the matter or underestimated (relative to users like you because the importance is subjective) the importance of keeping the constructors. 他们可能忽略了这个问题或者低估了(相对于像你这样的用户,因为重要性是主观的)保持构造者的重要性。
  • Keeping the constructors would have maintenance overhead. 保持构造函数会有维护开销。 Besides making things not as "clean" (again this is subjective), the developers would have needed to maintain default settings in both IndexWriter (eg deletion policy) and IndexWriterConfig. 除了使事情不那么“干净”(这也是主观的)之外,开发人员还需要在IndexWriter(例如删除策略)和IndexWriterConfig中维护默认设置。
  • Maintaining the constructor just so that users don't have to change their code has limited usefulness for the 3.0/4.0 transition. 仅维护构造函数以便用户不必更改其代码对3.0 / 4.0转换的有用性有限。 Because there are so many changes in 4.0, people cannot expect to just drop in the Lucene Core 4.0 code and expect their applications to still work. 因为4.0中有如此多的变化,人们不能指望只是放入Lucene Core 4.0代码并期望它们的应用程序仍能正常工作。

And if you ask me, then no, I don't think it's "bad API design". 如果你问我,那么不,我不认为这是“糟糕的API设计”。 It's unreasonable to expect them to keep every method call intact forever. 期望他们永远保持每个方法调用完整是不合理的。 They do have a backward compatibility policy, part of which I understand as they can deprecate whatever then want, but they won't remove or break things until the next major release. 他们确实有一个向后兼容性策略,我理解其中的一部分,因为他们可以弃用任何想要的东西,但是在下一个主要版本发布之前它们不会删除或破坏。 One of the worst? 最糟糕的一个? I think it's way better than some other popular projects that have no comparable policy and/or change behaviors (even when not fixing bugs) between point releases. 我认为它比一些其他流行项目更好,这些项目在点发布之间没有可比较的策略和/或更改行为(即使没有修复错误)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM