# Lucene 升级到 8.0.0 版本的问题

**URL:** <https://www.isharkfly.com/t/lucene-8-0-0/15924>\
**Category:** 程序语言\
**Tags:** java, lucene\
**Created:** [June 26, 2024, 8:19pm UTC](https://www.isharkfly.com/t/lucene-8-0-0/15924 "2024-06-26T20:19:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![honeymoose](https://www.isharkfly.com/user_avatar/www.isharkfly.com/honeymoose/32/20796_2.png) [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Post date:** [June 26, 2024, 8:19pm UTC](https://www.isharkfly.com/t/lucene-8-0-0/15924/1 "2024-06-26T20:19:18Z")

</div>

`public static final CharArraySet STOP_WORDS_SET = ENGLISH_STOP_WORDS_SET`

常量将会被删除。

使用 ENGLISH\_STOP\_WORDS\_SET 来替代。

ENGLISH\_STOP\_WORDS\_SET 这个常量位于 EnglishAnalyzer 类中。

 ![2025-04-25_15-32-43](https://cdn.isharkfly.com/com-isharkfly-www/discourse-uploads/original/3X/c/c/ccdb54208335c77f794af39a4e5e8698e95c23ef.jpeg)

---

<div class="post-metadata">

**Author:** ![hex](https://www.isharkfly.com/user_avatar/www.isharkfly.com/hex/32/21953_2.png) [@hex](https://www.isharkfly.com/u/hex)\
**Post date:** [June 26, 2024, 8:19pm UTC](https://www.isharkfly.com/t/lucene-8-0-0/15924/2 "2024-06-26T20:19:19Z")

</div>

类 `StandardAnalyzer` 也会被删除。

需要使用类 `ClassicFilter` 来替代。

 ![2025-04-25_15-36-15](https://cdn.isharkfly.com/com-isharkfly-www/discourse-uploads/original/3X/8/0/8051fd047566719ac0314df98191c556240bab2e.jpeg)

主要是上面 2 句话的写法需要改一下。

---

<div class="post-metadata">

**Author:** ![honeymoose](https://www.isharkfly.com/user_avatar/www.isharkfly.com/honeymoose/32/20796_2.png) [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Post date:** [April 25, 2025, 7:42pm UTC](https://www.isharkfly.com/t/lucene-8-0-0/15924/3 "2025-04-25T19:42:14Z")

</div>

构造方法 `new StopAnalyzer()` 也会被删除。

```auto
Builds an analyzer which removes words in ENGLISH_STOP_WORDS_SET.

Use a constructor with a specific stop word set

```

 ![2025-04-25_15-41-55](https://com-isharkfly-discourse.s3.dualstack.us-east-2.amazonaws.com/com-isharkfly-www/discourse-uploads/original/3X/d/4/d4dbd51f43f94d2f2072878d55468a01bb0a9489.jpeg)

方法需要改成上面那样。

---

<div class="post-metadata">

**Author:** ![hex](https://www.isharkfly.com/user_avatar/www.isharkfly.com/hex/32/21953_2.png) [@hex](https://www.isharkfly.com/u/hex)\
**Post date:** [April 25, 2025, 7:42pm UTC](https://www.isharkfly.com/t/lucene-8-0-0/15924/4 "2025-04-25T19:42:15Z")

</div>

我在这个论坛上搜索了与 Lucene StopAnalyzer 和 ENGLISH\_STOP\_WORDS\_SET 相关的内容,但没有找到直接相关的讨论。看起来这个论坛可能不是专门讨论 Lucene 或信息检索技术的。

根据你提供的信息,我的理解如下:

在新版本的 Lucene 中,StopAnalyzer 类的无参构造方法 `new StopAnalyzer()` 已经被标记为废弃(deprecated),将来会被移除。该构造方法会使用默认的英语停用词集 ENGLISH\_STOP\_WORDS\_SET。

取而代之的是使用带有指定停用词集合的构造方法,形式如:

```java
public StopAnalyzer(CharArraySet stopWords)

```

Javadoc中注释建议 “Use a constructor with a specific stop word set”。

所以如果你使用的是较新版本的Lucene,建议修改代码,显式地指定要使用的停用词集合,传给 StopAnalyzer 的构造方法,比如:

```java
CharArraySet stopWords = EnglishAnalyzer.ENGLISH_STOP_WORDS_SET;
StopAnalyzer analyzer = new StopAnalyzer(stopWords);

```

这样可以让代码意图更明确,也避免使用废弃的API。

不过具体的修改方式还要看你的业务需求。如果默认的英语停用词集合已经够用,那么像上面那样修改就可以。如果你需要自定义停用词,那就需要自己构造 CharArraySet,传给构造方法。

希望我理解得没错,如有不清楚的地方欢迎继续追问。

---

<div class="post-metadata">

**Author:** ![honeymoose](https://www.isharkfly.com/user_avatar/www.isharkfly.com/honeymoose/32/20796_2.png) [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Post date:** [April 25, 2025, 7:44pm UTC](https://www.isharkfly.com/t/lucene-8-0-0/15924/5 "2025-04-25T19:44:59Z")

</div>


