luncese

1.创建索引

public class Number001 {

	public static void main(String[] args) throws IOException {
		num001();
	}

	public static void num001() throws IOException{
		FSDirectory directory = FSDirectory.open(new File("indexDIR/"));
		//年分词器 对文本进行分切
		Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_44);
		
		//建立索引配置对象
		IndexWriterConfig config = new	IndexWriterConfig(Version.LUCENE_44,analyzer);
		
		//构造创建索引
		IndexWriter indexWriter = new IndexWriter(directory, config); 
		
		
		//IndexableField intfield = new IntField("title", "王乾坤", Stored.);
		
		IndexableField intfield=new IntField("title",1,Store.YES);
		
		StringField StringField = new StringField("title", "王乾坤教授", Store.YES);
		TextField textField = new TextField("count", "一九五二年生。一九八二年大学毕业后被分配在湖北省政府机关工作",Store.YES);
		Document document = new Document();
		document.add(intfield);
		document.add(textField);
		document.add(StringField);
		indexWriter.addDocument(document);
		indexWriter.close();
		 
	}
}解析


2.解析索引

/**
	 * 通过索引查询内容
	 * @throws IOException 
	 */
	public static void getIndex() throws IOException{
		FSDirectory directory =FSDirectory.open(new File("indexDIR/"));
		DirectoryReader indexReader = DirectoryReader.open(directory);
		IndexSearcher indexSearcher = new IndexSearcher(indexReader);
		Query query=new TermQuery(new Term("count","651518854"));
		TopDocs topDocs = indexSearcher.search(query, 10);
		System.out.println("记录总数->"+topDocs.totalHits);
	}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值