Search 混乱的卢西恩·斯特林菲尔德

Search 混乱的卢西恩·斯特林菲尔德,search,lucene,document,Search,Lucene,Document,我想从已创建的索引中读取一些文档,然后将它们放在另一个索引中。但我无法在“另一个索引”中检索这些文档 哦,文件上只有StringField 有个男孩能帮我 守则: public static void test() throws IOException{ IndexWriterConfig conf=new IndexWriterConfig(Version.LUCENE_43, new MapbarAnalyzer(TokenizerModle.COMMON)); conf.s

我想从已创建的索引中读取一些文档,然后将它们放在另一个索引中。但我无法在“另一个索引”中检索这些文档 哦,文件上只有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);


}
public static void test()引发IOException{
IndexWriterConfig conf=newindexwriterconfig(Version.LUCENE_43,newmapbaranalyzer(TokenizerModle.COMMON));
conf.setOpenMode(OpenMode.CREATE);
conf.setMaxBufferedDocs(10000);
LogByteSizeMergePolicy=新的LogByteSizeMergePolicy();
政策.固定资产比率(1.0);;
policy.setUseComoundFile(true);
conf.setMergePolicy(policy);
目录d=新的RAMDirectory();
IndexWriter iw=新的IndexWriter(d,conf);
单据单据=新单据();
文件添加(新字符串字段(“类型”,“5B0”,Store.YES));
iw.addDocument(doc);
iw.close();
IndexReader r=DirectoryReader.open(d);
IndexSearcher is=新的IndexSearcher(r);
查询q=新术语查询(新术语(“类型”,“5B0”));
TopDocs=is.search(q,10);
System.out.println(docs.totalHits);
目录d1=新的RAMDirectory();
IndexWriter iw1=新的IndexWriter(d1,形态);
int maxdoc=r.maxdoc();

对于(inti=0;i您可以尝试比较这两个索引/文档/查询之间的差异 事实证明,doc0的字段设置了一个“标记化”属性

如下更改代码:

for(int i=0;i<maxdoc;i++){
    Document doc0=r.document(i);
    Field f1 = (Field) doc0.getField("type");
    f1.fieldType().setTokenized(false);
    iw1.addDocument(doc0);
}

用于(int i=0;ii如果您的查询没有返回任何文档,这可能取决于您使用的分析器。
MapbarAnalyzer
到底做什么?请记住,术语查询没有经过分析,因此您必须搜索与索引中的标记完全相同的标记才能找到结果。您好,javana.for'StringField'lucene直接调用“StringTokenStream”,所以我认为MapbarAnalyzer所做的是不相关的。我尝试了“KeywordAnalyzer StopAnalyzer”,这是相同的问题。我困惑的是原始文档可以搜索结果,但将此文档重写为索引是不可能的