lucene 7.2版本(之前用的4.0 的。。发现好多都变了。。)—— 创建索引(内存中)
2018-01-12 16:05
946 查看
package com.shang.lucene.index.create; import com.shang.lucene.index.abstracts.IndexAbstract; import com.shang.lucene.jdbc.DataBase; 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.FieldType; import org.apache.lucene.index.*; import org.apache.lucene.store.RAMDirectory; import java.io.IOException; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class CreateRAMIndex extends IndexAbstract { RAMDirectory dir = new RAMDirectory(); public static IndexReader indexReader; private Connection conn; public void createIndex() { try { System.out.println("========试试水====="); Analyzer analyzer = new StandardAnalyzer(); //分词器(有简体中文分词器) IndexWriter indexWriter = new IndexWriter(dir, new IndexWriterConfig(analyzer)); Document doc = new Document(); Document doc1 = new Document(); Document doc2 = new Document(); Document doc3 = new Document(); FieldType fieldType = new FieldType(); fieldType.setStored(true); // 设置为true,存储此字段 doc.add(new Field("bookName", "白夜行", fieldType)); doc1.add(new Field("bookName", "时间移民", fieldType)); doc2.add(new Field("bookName", "假面饭店", fieldType)); doc3.add(new Field("bookName", "废都", fieldType)); indexWriter.addDocument(doc); indexWriter.addDocument(doc1); indexWriter.addDocument(doc2); indexWriter.addDocument(doc3); indexWriter.close(); } catch (IOException e) { e.printStackTrace(); } } public static void main(String[] args) { CreateRAMIndex s = new CreateRAMIndex(); s.createIndex(); } }
相关文章推荐
- Lucene.Net核心类简介,创建索引,搜索,Lucene高亮组建演示,Rss获得最新帖子,只索引帖子的有意义部分,在AddDocument之前先移除旧有文档.
- lucene3.0+版本中文分词测试+搜索结果+创建索引测试
- lucene4.0与之前版本的一些改变
- lucene_43版本创建索引demo
- Lucene初探之如何创建索引
- 原生Lucene,创建索引
- 使用Lucene对预处理后的文档进行创建索引(可运行)
- Lucene中创建索引的效率和删除索引的实现
- lucene--索引的创建
- Lucene学习4---索引和域以及3.0与4.0的区别--document/NumericFie
- Lucene初探之如何创建索引
- lucene-利用内存中索引和多线程提高索引效率
- Lucene--001创建索引
- Lucene 4.7 教程起步--创建索引
- Lucene教程(一) 创建索引
- 01-lucene简介和索引创建以及搜索
- lucene学习笔记1-创建索引
- lucene读取索引文件到内存
- Lucene创建、查询、删除、更新 索引
- Lucene全文检索技术之如何创建索引