lucene5 实时搜索
openIfChanged
public static DirectoryReader openIfChanged(DirectoryReader oldReader)
throws IOExceptionIf the index has changed since the provided reader was opened, open and return a new reader; else, return null. The new reader, if not null, will be the same type of reader as the previous one, ie an NRT reader will open a new NRT reader, a MultiReader will open a new MultiReader, etc.This method is typically far less costly than opening a fully new
DirectoryReaderas it shares resources (for example sub-readers) with the providedDirectoryReader, when possible.The provided reader is not closed (you are responsible for doing so); if a new reader is returned you also must eventually close it. Be sure to never close a reader while other threads are still using it; see
SearcherManagerto simplify managing this.- Returns:
- null if there are no changes; else, a new DirectoryReader instance which you must eventually close
- Throws:
CorruptIndexException- if the index is corruptIOException- if there is a low-level IO error
如果旧reader是一个NRT reader, 使用此方法重新打开reader可以发现writer的修改,而不需要提交。
openIfChanged
public static DirectoryReader openIfChanged(DirectoryReader oldReader,
IndexWriter writer)
throws IOExceptionExpert: If there changes (committed or not) in theIndexWriterVS what the provided reader is searching, then open and return a new IndexReader searching both committed and uncommitted changes from the writer; else, return null (though, the current implementation never returns null).This provides "near real-time" searching, in that changes made during an
IndexWritersession can be quickly made available for searching without closing the writer nor callingIndexWriter.commit().It's near real-time because there is no hard guarantee on how quickly you can get a new reader after making changes with IndexWriter. You'll have to experiment in your situation to determine if it's fast enough. As this is a new and experimental feature, please report back on your findings so we can learn, improve and iterate.
The very first time this method is called, this writer instance will make every effort to pool the readers that it opens for doing merges, applying deletes, etc. This means additional resources (RAM, file descriptors, CPU time) will be consumed.
For lower latency on reopening a reader, you should call
IndexWriterConfig.setMergedSegmentWarmer(org.apache.lucene.index.IndexWriter.IndexReaderWarmer)to pre-warm a newly merged segment before it's committed to the index. This is important for minimizing index-to-search delay after a large merge.If an addIndexes* call is running in another thread, then this reader will only search those segments from the foreign index that have been successfully copied over, so far.
NOTE: Once the writer is closed, any outstanding readers may continue to be used. However, if you attempt to reopen any of those readers, you'll hit an
AlreadyClosedException.- Parameters:
writer- The IndexWriter to open from- Returns:
- DirectoryReader that covers entire index plus all changes made so far by this IndexWriter instance, or null if there are no new changes
- Throws:
IOException- if there is a low-level IO error- WARNING: This API is experimental and might change in incompatible ways in the next release.
openIfChanged
public static DirectoryReader openIfChanged(DirectoryReader oldReader,
IndexWriter writer,
boolean applyAllDeletes)
throws IOExceptionExpert: Opens a new reader, if there are any changes, controlling whether past deletions should be applied.- Parameters:
writer- The IndexWriter to open fromapplyAllDeletes- If true, all buffered deletes will be applied (made visible) in the returned reader. If false, the deletes are not applied but remain buffered (in IndexWriter) so that they will be applied in the future. Applying deletes can be costly, so if your app can tolerate deleted documents being returned you might gain some performance by passing false.- Throws:
IOException- if there is a low-level IO error- See Also:
openIfChanged(DirectoryReader,IndexWriter)- WARNING: This API is experimental and might change in incompatible ways in the next release.
http://my.oschina.net/MrMichael/blog/220723
lucene5 实时搜索的更多相关文章
- Lucene.net 实现近实时搜索(NRT)和增量索引
Lucene做站内搜索的时候经常会遇到实时搜索的应用场景,比如用户搜索的功能.实现实时搜索,最普通的做法是,添加新的document之后,调用 IndexWriter 的 Commit 方法把内存中的 ...
- Lucene系列-近实时搜索(1)
近实时搜索(near-real-time)可以搜索IndexWriter还未commit的内容,介于immediate和eventual之间,在数据比较大.更新较频繁的情况下使用.本文主要来介绍下如何 ...
- Solr -- 实时搜索
在solr中,实时搜索有3种方案 ①soft commit,这其实是近实时搜索,不能完全实时. ②RealTimeGet,这是实时,但只支持根据文档ID的查询. ③和第一种类似,只是触发softcom ...
- Everything文件名实时搜索||解决局域网文件共享问题
内容概要:Everything中文版下载地址及使用.用Everything轻松解决局域网文件共享问题.Everything语言设置问题 另:Everything只支持NTFS格式的磁盘(工作原理的缘故 ...
- jmeter 实时搜索结果
因为JMeter 2.13你可以得到实时搜索结果发送到后端通过 后端侦听器 使用潜在的任何后端(JDBC.JMS网络服务,Š) 通过提供一个实现类 AbstractBackendListenerCl ...
- Elasticsearch是一个分布式可扩展的实时搜索和分析引擎,elasticsearch安装配置及中文分词
http://fuxiaopang.gitbooks.io/learnelasticsearch/content/ (中文) 在Elasticsearch中,文档术语一种类型(type),各种各样的 ...
- lucene4.5近实时搜索
近实时搜索就是他能打开一个IndexWriter快速搜索索引变更的内容,而不必关闭writer,或者向writer提交,这个功能是在2.9版本以后引入的,在以前没有这个功能时,必须调用writer的c ...
- 关于lucene的IndexSearcher单实例,对于索引的实时搜索
Lucene版本:3.0 一般情况下,lucene的IndexSearcher都要写成单实例,因为每次创建IndexSearcher对象的时候,它都需要把索引文件加载进来,如果访问量比较大,而索引也比 ...
- 【Lucene】近实时搜索
近实时搜索:可以使用一个打开的IndexWriter快速搜索索引的变更内容,而不必首先关闭writer,或者向该writer提交:这是2.9版本之后推出的新功能. 代码示例(本例参考<Lucen ...
随机推荐
- HDU 4717 The Moving Points(三分法)(2013 ACM/ICPC Asia Regional Online ―― Warmup2)
Description There are N points in total. Every point moves in certain direction and certain speed. W ...
- 软件工程项目组Z.XML会议记录 2013/09/14
软件工程项目组Z.XML会议记录 [例会时间]2013年9月14日星期六21:00-22:30 [例会形式]小组讨论 [例会地点]新主楼A1025 [例会主持]李孟 [会议记录]李孟 会议整体流程 一 ...
- python学习笔记-list的用法
1.list的定义 list = [] list = [1,2,'a','b'](list中的元素不一定是一个类型) 2.list的操作 1)list.append(value) 2)list.ins ...
- Linux的常用目录学习笔记
首先,先查看一下Linuxi的一级目录结构: ls: /:表示根目录,文件系统的入口,最高一级目录. bin和sbin:命令保存目录,bin是普通用户能,sbin是root用户用的:/bin存放着系统 ...
- Java面试题(下)
这部分主要是开源Java EE框架方面的内容,包括hibernate.MyBatis.spring.Spring MVC等,由于Struts 2已经是明日黄花,在这里就不讨论Struts 2的面试题, ...
- Python创建目录文件夹
Python对文件的操作还算是方便的,只需要包含os模块进来,使用相关函数即可实现目录的创建. 主要涉及到三个函数 1.os.path.exists(path) 判断一个目录是否存在 2.os.mak ...
- 段寻址*****************************TBD
fffff880`01b05be1 ff9708020000 call qword ptr [rdi+208h] ds:002b:fffff980`0554ae88=fffffa8004b ...
- [剑指Offer] 38.二叉树的深度
题目描述 输入一棵二叉树,求该树的深度.从根结点到叶结点依次经过的结点(含根.叶结点)形成树的一条路径,最长路径的长度为树的深度. [思路1]递归 /* struct TreeNode { int v ...
- 批处理之SET命令
除了 下面分别介绍: 表示第二个字符到倒数第三个字符的值
- 【题解】ZJOI2008骑士
树型打牌:洛谷P2607 这道题目一开始没有想到解法,只是想到没有上司的舞会,觉得十分的类似呀. 之后发现:n个点,n条边,只要删去一条边,就变成了和上题一模一样的做法. 那么考虑删去的这条边,实际上 ...