5

さまざまな理由で、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);

簡単な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));
    }
}

実行時:

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

これは私が受け取るエラーメッセージです:

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

4

1 に答える 1

2

これは、ある種の JAR バージョンの不一致が原因です。異なるバージョンの Lucene に依存する contrib JAR に依存している可能性があります。実行時に設定された依存関係を正確に把握し、バージョンの不一致を探します。

于 2012-10-29T16:39:39.637 に答える