lucene中FSDirectory对象中为什么没有open类

package com.lucene;

import java.io.File;
import java.io.IOException;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.LongField;
import org.apache.lucene.document.TextField;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.Version;
import org.apache.lucene.document.Field.Store;

public class Lucene {

public void CreateIndex(){
    Document doc=new Document();
    doc.add(new LongField("id", 1, Store.YES));
    doc.add(new TextField("title", "如何学习lucene", Store.YES));
    doc.add(new TextField("content", "掌握原理,熟悉API,多看文档", Store.YES));
    Directory dir=new FSDirectory.**open**(new File("D:\\index"));//open()类没有,写上就会报错

    Analyzer analyzer=new StandardAnalyzer(Version.LUCENE_46);
    IndexWriterConfig config=new IndexWriterConfig(Version.LUCENE_46, analyzer);
    IndexWriter index=new IndexWriter(dir, config);
    index.addDocument(doc);
    index.close();
}

}

2个回答

Directory dir=new FSDirectory.**open**(new File("D:\index"));//open()类没有,写上就会报错

该正,FSDirectory前面为什么要放个new呢,又不是创建对象

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问