lucene配置动态域_*lucene索引_创建_域选项

1 packagecn.hk.index;2

3 importjava.io.File;4 importjava.io.IOException;5

6 importorg.apache.lucene.analysis.standard.StandardAnalyzer;7 importorg.apache.lucene.document.Document;8 importorg.apache.lucene.document.Field;9 importorg.apache.lucene.index.CorruptIndexException;10 importorg.apache.lucene.index.IndexReader;11 importorg.apache.lucene.index.IndexWriter;12 importorg.apache.lucene.index.IndexWriterConfig;13 importorg.apache.lucene.store.Directory;14 importorg.apache.lucene.store.FSDirectory;15 importorg.apache.lucene.store.LockObtainFailedException;16 importorg.apache.lucene.util.Version;17

18 public classIndexUtil {19 private String[] ids = {"1","2","3","4","5","6"};20 private String[] emails = {"aa@hk.arg","bb@hk.org","cc@hk.arg",21 "dd@hk.org","ee@hk.org","ff@hk.org"};22 private String[] content ={23 "welcome to visited the space","hello boy","my name is aa","i like football",24 "I like football and I like Basketball too","I like movie and swim"

25 };26 private int[] attachs = {2,3,1,4,5,5};27 private String[] names = {"zhangsan","lisi","john","mike","jetty","jake"};28

29 private Directory directory = null;30

31 publicIndexUtil(){32 try{33 directory = FSDirectory.open(new File("d://lucene/index02"));34 } catch(IOException e) {35 e.printStackTrace();36 }37 }38

39 public voidquery(){40 try{41 IndexReader reader =IndexReader.open(directory);42 //通过reader可以获取文档的数量

43 System.out.println("numDocs:" +reader.numDocs());44 System.out.println("maxDocs" +reader.maxDoc());45 } catch(CorruptIndexException e) {46

47 e.printStackTrace();48 } catch(IOException e) {49

50 e.printStackTrace();51 }52 }53

54

55 public voidindex(){56 IndexWriter writer = null;57 try{58 writer = new IndexWriter(directory,new IndexWriterConfig(Version.LUCENE_35, newStandardAnalyzer(Version.LUCENE_35)));59 Document doc = null;60 for(int i=0;i

80 e.printStackTrace();81 } catch(IOException e) {82

83 e.printStackTrace();84 }85

86 }87 }88

89 }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值