Lucene 4.0 覆盖最终方法 tokenStream

Ion*_*nut 5 java lucene

由于不同的原因,我必须使用最新版本的 Lucene 的 API。

API 还没有很好的文档记录,所以我发现自己无法执行一个简单的 addDocument()

下面是Writer初始化:

analyzer = new StopAnalyzer(Version.LUCENE_40);
config = new IndexWriterConfig(Version.LUCENE_40, analyzer);
writer = new IndexWriter(FSDirectory.open(new File(ConfigUtil.getProperty("lucene.directory"))), config);
Run Code Online (Sandbox Code Playgroud)

简单的toDocument方法:

public static Document getDocument(User user) {
    Document doc = new Document();
    FieldType storedType = new FieldType();
    storedType.setStored(true);
    storedType.setTokenized(false);

    // Store user data
    doc.add(new Field(USER_ID, user.getId().toString(), storedType));
    doc.add(new Field(USER_NAME, user.getFirstName() + user.getLastName(), storedType));

    FieldType unstoredType = new FieldType();
    unstoredType.setStored(false);
    unstoredType.setTokenized(true);

    // Analyze Location
    String tokens = "";
    if (user.getLocation() != null && ! user.getLocation().isEmpty()){
        for (Tag location : user.getLocation()) tokens += location.getName() + " ";
        doc.add(new Field(USER_LOCATION, tokens, unstoredType));
    }
}
Run Code Online (Sandbox Code Playgroud)

运行时:

Document userDoc = DocumentManager.getDocument(userWrap);
IndexAccess.getWriter().addDocument(userDoc);
Run Code Online (Sandbox Code Playgroud)

这是我收到的错误消息:

class org.apache.lucene.analysis.util.ReusableAnalyzerBase overrides final method tokenStream.(Ljava/lang/String;Ljava/io/Reader;)Lorg/apache/lucene/analysis/TokenStream;

这可能是一件简单的事情,但我找不到任何参考资料来帮助解决这个问题。我正在使用默认值,analyzer并且我遵循了教程以避免不推荐使用Field.Index.ANALYZED

Mar*_*nik 2

这是由于某种 JAR 版本不匹配造成的。您可能依赖于一个 contrib JAR,而该 JAR 又依赖于不同版本的 Lucene。尝试获取运行时设置的确切依赖项并查找任何版本不匹配的情况。