val_HH
val_HH
2017-08-06 12:37

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

  • lucene

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条回答