1
我想從索引中讀取一些文件已經創建,然後把它們放在另一個索引中。但我無法檢索到這些文件中的「另一個索引」 哦,文檔只是有StringField .. ..someboy可以幫我困惑Lucene StringField
代碼:
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);
}
如果你根本就沒有得到任何文件從您的查詢回到它可能取決於您所使用的分析儀。 「MapbarAnalyzer」究竟做了什麼?請記住,術語查詢不會被分析,因此您必須搜索與您的索引中的標記完全相同的標記才能找到結果。 – javanna 2013-05-09 20:07:41
嗨,javana .For'StringField'lucene直接調用'StringTokenStream',所以我認爲MapbarAnalyzer做什麼是無關緊要的。我試過'KeywordAnalyzer StopAnalyzer',它的問題是一樣的。我很困惑的是原始文檔可以搜索結果但是將這個文檔重新編譯爲索引是不可能的 – user2364811 2013-05-10 03:45:22