zoukankan
html css js c++ java
lucene索引库优化二
其实提高索引查询的速度最简洁的方法技术将索引放到内存当中,减少IO,从而提高查询速度:
public class MergePolicies { public static void main(String[] args) throws Exception { long start=new Date().getTime(); IOContext context=new IOContext(); Directory dir=FSDirectory.open(new File("E:/docData/indexDir")); /** * 把索引存储到内存中 */ Directory directory=new RAMDirectory(dir,context); IndexReader reader=DirectoryReader.open(directory); IndexSearcher searcher=new IndexSearcher(reader); /** * 多条件查询 */ String[] fields={"content"}; QueryParser parser=new MultiFieldQueryParser(Version.LUCENE_44, fields,new StandardAnalyzer(Version.LUCENE_44)); Query query = parser.parse("源码"); TopScoreDocCollector results=TopScoreDocCollector.create(10, false); searcher.search(query, results); ScoreDoc[] scoreDocs = results.topDocs().scoreDocs; System.out.println(scoreDocs.length); /** * 可以在此分页 * start 起始位置 * length 记录数 */ for(int i=0;i<scoreDocs.length;i++){ Document doc= searcher.doc(scoreDocs[i].doc); System.out.println(doc.getField("filename")+" "+scoreDocs[i].toString()); } long end=new Date().getTime(); System.out.println("took time:"+(end-start)); } }
用放荡不羁的心态过随遇而安的生活
查看全文
相关阅读:
python-函数进阶
SHELL wordpress.sh
XFS: possible memory allocation deadlock in kmem_alloc (mode:0x2d0)
Puppet install with nginx unicorn
CentOS 6内核编译问题整理
Openstack 本地yum源配置
Openstack 本地yum源配置
hpsa 0000:0a:00.0: out of memory
openstack VNC安全问题
CentOS下crash分析内核kdump文件方法
原文地址:https://www.cnblogs.com/re-myself/p/5532499.html
最新文章
HTTP基础知识(四)
HTTP基础知识(三)
高性能javascript笔记
JavaScript instanceof 运算符深入剖析
正则表达式(?=a)是什么意思
原生ajax
深度比较isEqual
深拷贝
React Iframe 使用探索
create-react-app 工程,如何修改react端口号
热门文章
深入React事件系统(React点击空白部分隐藏弹出层;React阻止事件冒泡失效)
2018年最值得关注的30个Vue开源项目
python-数据库开发
pycharm 爬取校花网
python-并发编程
网络编程-Socket
网络编程-基础
python-面向对象进阶
python-面向对象
python-模块分类与导入
Copyright © 2011-2022 走看看