我想从已创建的索引中读取一些文档,然后将它们放在另一个索引中。但是我无法在“另一个索引”中检索这些文档哦,文档只有 StringField .. ..someboy 可以帮助我
编码:
public static void test() throws IOException{
IndexWriterConfig conf=new IndexWriterConfig(Version.LUCENE_43, new MapbarAnalyzer(TokenizerModle.COMMON));
conf.setOpenMode(OpenMode.CREATE);
conf.setMaxBufferedDocs(10000);
LogByteSizeMergePolicy policy=new LogByteSizeMergePolicy();
policy.setNoCFSRatio(1.0);
policy.setUseCompoundFile(true);
conf.setMergePolicy(policy);
Directory d=new RAMDirectory();
IndexWriter iw=new IndexWriter(d, conf);
Document doc=new Document();
doc.add(new StringField("type", "5B0", Store.YES));
iw.addDocument(doc);
iw.close();
IndexReader r=DirectoryReader.open(d);
IndexSearcher is=new IndexSearcher(r);
Query q=new TermQuery(new Term("type","5B0"));
TopDocs docs=is.search(q, 10);
System.out.println(docs.totalHits);
Directory d1=new RAMDirectory();
IndexWriter iw1=new IndexWriter(d1, conf);
int maxdoc=r.maxDoc();
for(int i=0;i<maxdoc;i++){
Document doc0=r.document(i);
iw1.addDocument(doc0);
}
iw1.close();
IndexReader r1=DirectoryReader.open(d1);
IndexSearcher is1=new IndexSearcher(r1);
Query q1=new TermQuery(new Term("type","5B0"));
TopDocs docs1=is1.search(q1, 10);
System.out.println(docs1.totalHits);
}