博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Lucene中的Ram存储
阅读量:5046 次
发布时间:2019-06-12

本文共 2375 字,大约阅读时间需要 7 分钟。

package com.fxr.demo3;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.index.CorruptIndexException;import org.apache.lucene.index.IndexWriter;import org.apache.lucene.index.Term;import org.apache.lucene.search.IndexSearcher;import org.apache.lucene.search.ScoreDoc;import org.apache.lucene.search.TermQuery;import org.apache.lucene.search.TopDocs;import org.apache.lucene.store.Directory;import org.apache.lucene.store.FSDirectory;import org.apache.lucene.store.RAMDirectory;public class TestRamSearcher {    Directory directory=new RAMDirectory();	    public void creatRamIndex() throws IOException{    	String [] ids={"1","2","3","4"};		String [] names={"ZHangsan","lisi","wangwu","zhaoliu"};		String [] addresses={"tianjing","nanjing","beijing","nanning"};		String [] birthdays={"19820720","19840203","19770409","19830130"};		Analyzer analyzer=new StandardAnalyzer();					//true 表示创建或覆盖当前索引;false表示对当前索引进行追加		//Default value is 128		IndexWriter writer=new IndexWriter(directory,analyzer,true,IndexWriter.MaxFieldLength.LIMITED);				for(int i=0;i

  Lucene中的另一种写法:

package com.fxr.demo3;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.index.Term;import org.apache.lucene.search.IndexSearcher;import org.apache.lucene.search.ScoreDoc;import org.apache.lucene.search.TermQuery;import org.apache.lucene.search.TopDocCollector;import org.apache.lucene.store.Directory;import org.apache.lucene.store.FSDirectory;public class TestTopDocCollectller {		public static void main(String[] args) throws IOException {		Analyzer analyzer = new StandardAnalyzer();		String indexDir = "f:/lucenefxrindex";		Directory dir=FSDirectory.getDirectory(indexDir);//索引存放的位置		IndexSearcher indexSearcher = new IndexSearcher(dir);		ScoreDoc[]hits = null;		TopDocCollector topDocCollector = new TopDocCollector(10);		Term term = new Term("address","zhengzhou");		TermQuery query = new TermQuery(term);		indexSearcher.search(query,topDocCollector);		hits = topDocCollector.topDocs().scoreDocs;		for(int i=0;i

  

转载于:https://www.cnblogs.com/aicpcode/p/4301060.html

你可能感兴趣的文章
对Feature的操作插入添加删除
查看>>
javascript String
查看>>
ecshop 系统信息在哪个页面
查看>>
【转】码云source tree 提交超过100m 为什么大文件推不上去
查看>>
Oracle数据库的增、删、改、查
查看>>
MySql执行分析
查看>>
git使用中的问题
查看>>
yaml文件 .yml
查看>>
linux字符集修改
查看>>
phpcms 添加自定义表单 留言
查看>>
mysql 优化
查看>>
读书笔记 ~ Nmap渗透测试指南
查看>>
WCF 配置文件
查看>>
动态调用WCF服务
查看>>
oracle导出/导入 expdp/impdp
查看>>
类指针
查看>>
css修改滚动条样式
查看>>
2018.11.15 Nginx服务器的使用
查看>>
Kinect人机交互开发实践
查看>>
百度编辑器UEditor ASP.NET示例Demo 分类: ASP.NET...
查看>>