lucene 4.x API的改动

来源:转载


一、关于IndexWriter的改动(Directory增量模式设置)改动前:Directory dir=FSDirectory.open(new File("E://lucene_index")); 
Analyzer analyzer=new StandardAnalyzer(Version.LUCENE_42); IndexWriter indexWriter=new IndexWriter(dir,analyzer,false);改动后(使用IndexWriterConfig):Directory dir=FSDirectory.open(new File("E://lucene_index")); 
Analyzer analyzer=new StandardAnalyzer(Version.LUCENE_42); 
IndexWriterConfig iwc=new IndexWriterConfig(Version.LUCENE_42, analyzer); 
iwc.setOpenMode(OpenMode.CREATE_OR_APPEND); 
iwc.setInfoStream(System.out); 
IndexWriter writer=new IndexWriter(dir,iwc); 
二、IndexSearcher的改动改动前:Directory dir=FSDirectory.open(new File("path"));IndexSearcher indexSearcher=new IndexSearcher(dir);改动后:Directory dir=FSDirectory.open(new File("path"));IndexReader reader=DirectoryReader.open(dir);IndexSearcher indexSearcher=new IndexSearcher(reader);
三、Field的改动旧的API:Field f=new Field(key,value,Field.Store.YES,Field.Index.NOT_ANALYSIS);新API:filed改为抽象类,有若干实现(StringField/LongField/TextField等),舍弃最后一个参数Field f=new StringField(key,value,Field.Store.YES);StringField 存储字符类型数据,对于value不进行分词索引TextField   存储字符类型,对value分词索引LongField 存储长整型数据,不分词



分享给朋友:
您可能感兴趣的文章:
随机阅读: