Lucene 4.4 依据Int类型字段删除索引
1、方法一,通过Term删除
Term构造中没有。Int类型须要转换成Lucene自带的类BytesRef 。 /**
* 依据商品ID删除索引文件
* @param id
*/
public void deleteDocument(int id)
{;
File file = new File("E://index");
IKAnalyzer analyzer = new IKAnalyzer();
IndexWriterConfig indexWriterConfig = new IndexWriterConfig(Version.LUCENE_44, analyzer);
IndexWriter indexWriter = null;
Directory directory;
try {
directory = FSDirectory.open(file);
// 创建 IndexWriter
indexWriter = new IndexWriter(directory, indexWriterConfig);
BytesRef bytes = new BytesRef(NumericUtils.BUF_SIZE_INT);
NumericUtils.intToPrefixCoded(id, 0, bytes);
Term term = new Term(field, bytes); indexWriter.deleteDocuments(term);
indexWriter.close(); } catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} } 2.方法二,使用NumericRangeQuery /**
* 依据商品ID删除索引文件
* @param id
*/
public void deleteDocument(int id)
{;
File file = new File("E://index"); IKAnalyzer analyzer = new IKAnalyzer();
IndexWriterConfig indexWriterConfig = new IndexWriterConfig(Version.LUCENE_44, analyzer); IndexWriter indexWriter = null; Directory directory;
try {
directory = FSDirectory.open(file);
// 创建 IndexWriter
indexWriter = new IndexWriter(directory, indexWriterConfig);
Query numbericRangeQuery = NumericRangeQuery.newIntRange("ID",id-1, id+1, false, false);
indexWriter.deleteDocuments(numbericRangeQuery);
indexWriter.close(); } catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} }
Lucene 4.4 依据Int类型字段删除索引的更多相关文章
- mysql int类型字段插入空字符串时自动转为0
mysql int类型字段插入空字符串时自动转为0 如果不想转的话可以修改配置文件 修改 my.ini 文件. # Set the SQL mode to strictsql-mode=”STRICT ...
- Linq to Sql 左连接 , 取右表可能为 null的 int类型字段
linq to sql , linq to entity 遇到一个问题, 主表, 从表 一对一 关系, 主表有记录, 从表 可能没有记录. 现在要查询 主表+从表 的某几个字段. 从表字段 有的是 ...
- 使用MyBatis查询int类型字段,返回NULL值时报异常的解决方法
当配置mybatis返回int类型时 select id="getUserIdByName" parameterType="string" resultType ...
- 站内搜索(ELK)之数据表字典类型字段的索引思路
数据表字典类型的字段,如人员表中的“性别”.流程表中的“处理状态”,此类字段中的值高度重复,不建议放到可检索的索引字段中,原因如下: 若数据表字典类型字段的值索引到单独的索引字段中,因字典数据字符数一 ...
- 【转】mysql 中int类型字段unsigned和signed的区别
转自https://www.cnblogs.com/wangzhongqiu/p/6424827.html 用法: mysql> CREATE TABLE t ( a INT UNSIGNED, ...
- mysql 中int类型字段unsigned和signed的探索
转自:http://www.0791quanquan.com/news_keji/topic_816453/ 探索一:正负数问题 拿tinyint字段来举例,unsigned后,字段的取值范围是0-2 ...
- 字符串md5之后转成int类型, 方便数据库索引
function hashStringToInt($string){ $stringHash = substr(md5($string), 0, 8); return base_convert($st ...
- 原子类型字段更新器AtomicXxxxFieldUpdater
本博客系列是学习并发编程过程中的记录总结.由于文章比较多,写的时间也比较散,所以我整理了个目录贴(传送门),方便查阅. 并发编程系列博客传送门 原子类型字段更新器 在java.util.concurr ...
- MySQL中int类型的字段使用like查询方法
方法参考自: http://stackoverflow.com/questions/8422455/performing-a-like-comparison-on-an-int-field 也就是使用 ...
随机推荐
- poj 3216 (最小路径覆盖)
题意:有n个地方,m个任务,每个任务给出地点,开始的时间和完成需要的时间,问最少派多少工人去可以完成所有的任务.给出任意两点直接到达需要的时间,-1代表不能到达. 思路:很明显的最小路径覆盖问题,刚开 ...
- Android系统Surface机制的SurfaceFlinger服务的启动过程分析
文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/8022957 在前面一篇文章中,我们简要介绍了A ...
- LDAP实例异常停止日志提示虚拟内存virtual memory不足
[05/Oct/2014:20:50:37 +0800] - ERROR<5135> - Resource Limit - conn=-1 op=-1 msgId=-1 - Memory ...
- angular在ie8下的一个bug
昨天拿项目在ie8下测试,发现不少bug,其中有一个bug让我很不解,报了一个thead开头的bug,因为已经切回到linux下了,我就不报具体是什么bug了,鼓捣了半天,发现引用angular的应用 ...
- Ext布局
Ext主要包括11种标准布局方式:Auto(自动布局).CheckboxGroup(复选框组布局).Fit(自适应布局).Column(列布局).Accordion(折叠布局).Table(表格布局) ...
- JS局部打印两种方法
所有浏览器都可以 <html> <head title=""> <title>测试打印</title> <style medi ...
- Identity 验证,Authorize 特性
多类型角色访问 //[Authorize] //[Authorize(Roles = "User")] //[Authorize(Roles="Administrator ...
- 在IIS上Office Word下载失败,检索 COM 类工厂中 CLSID 为000209FF的组件失败,80070005 拒绝访问。
最近在做一个网站时,有一个下载word文档功能,在本地直接调试是可以下载的,但部署到IIS上就出现问题了. 出现问题如下:Error:下载简历方法出错:检索 COM 类工厂中 CLSID 为 {000 ...
- 如何写一个数据库How do you build a database?(转载)
转载自:http://www.reddit.com/r/Database/comments/27u6dy/how_do_you_build_a_database/ciggal8 Its a great ...
- iOS 后台播放音乐
在info.plist文件中添加 下面是后台播放音频的完整测试代码: 引入文件<AVFoundation/AVFoundation.h> //后台播放音频设置 AVAudioSession ...