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