简体   繁体   English

Lucene 4.0覆盖最终方法tokenStream

[英]Lucene 4.0 overrides final method tokenStream

For different reasons I have to work with the latest release of Lucene's API. 由于不同的原因,我必须使用最新版本的Lucene API。

The API isn't well documented yet so I find myself not able to perform a simple addDocument() 该API的文档尚不完善,因此我发现自己无法执行简单的addDocument()

Here is the Writer initialization: 这是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);

The simple toDocument method: 简单的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));
    }
}

When running: 运行时:

Document userDoc = DocumentManager.getDocument(userWrap);
IndexAccess.getWriter().addDocument(userDoc);

This is the error message I get: 这是我收到的错误消息:

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

It may be a simple matter but I cannot find any reference to help with this problem. 这可能很简单,但是我找不到任何参考资料可以帮助解决此问题。 I'm using a default analyzer and I followed a tutorial in order to avoid the deprecated Field.Index.ANALYZED 我使用的是默认analyzer并且按照教程进行操作,以避免过时的Field.Index.ANALYZED

This is due to some kind of JAR version mismatch. 这是由于某种JAR版本不匹配所致。 You may be depending on a contrib JAR that in turn depends on different version of Lucene. 您可能依赖于contrib JAR,而后者又依赖于不同版本的Lucene。 Try to get a hold of the exact dependency set at runtime and look for any version mismatches. 尝试在运行时保留确切的依赖关系集,并查找任何版本不匹配的情况。

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

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