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类型字段删除索引的更多相关文章

  1. mysql int类型字段插入空字符串时自动转为0

    mysql int类型字段插入空字符串时自动转为0 如果不想转的话可以修改配置文件 修改 my.ini 文件. # Set the SQL mode to strictsql-mode=”STRICT ...

  2. Linq to Sql 左连接 , 取右表可能为 null的 int类型字段

    linq to sql , linq to entity 遇到一个问题, 主表, 从表 一对一 关系,  主表有记录, 从表 可能没有记录. 现在要查询 主表+从表 的某几个字段. 从表字段 有的是 ...

  3. 使用MyBatis查询int类型字段,返回NULL值时报异常的解决方法

    当配置mybatis返回int类型时 select id="getUserIdByName" parameterType="string" resultType ...

  4. 站内搜索(ELK)之数据表字典类型字段的索引思路

    数据表字典类型的字段,如人员表中的“性别”.流程表中的“处理状态”,此类字段中的值高度重复,不建议放到可检索的索引字段中,原因如下: 若数据表字典类型字段的值索引到单独的索引字段中,因字典数据字符数一 ...

  5. 【转】mysql 中int类型字段unsigned和signed的区别

    转自https://www.cnblogs.com/wangzhongqiu/p/6424827.html 用法: mysql> CREATE TABLE t ( a INT UNSIGNED, ...

  6. mysql 中int类型字段unsigned和signed的探索

    转自:http://www.0791quanquan.com/news_keji/topic_816453/ 探索一:正负数问题 拿tinyint字段来举例,unsigned后,字段的取值范围是0-2 ...

  7. 字符串md5之后转成int类型, 方便数据库索引

    function hashStringToInt($string){ $stringHash = substr(md5($string), 0, 8); return base_convert($st ...

  8. 原子类型字段更新器AtomicXxxxFieldUpdater

    本博客系列是学习并发编程过程中的记录总结.由于文章比较多,写的时间也比较散,所以我整理了个目录贴(传送门),方便查阅. 并发编程系列博客传送门 原子类型字段更新器 在java.util.concurr ...

  9. MySQL中int类型的字段使用like查询方法

    方法参考自: http://stackoverflow.com/questions/8422455/performing-a-like-comparison-on-an-int-field 也就是使用 ...

随机推荐

  1. 【POJ 3279 Fliptile】开关问题,模拟

    题目链接:http://poj.org/problem?id=3279 题意:给定一个n*m的坐标方格,每个位置为黑色或白色.现有如下翻转规则:每翻转一个位置的颜色,与其四连通的位置都会被翻转,但注意 ...

  2. Android学习总结——系统提示对话框(AlertDialog)

    new AlertDialog.Builder(MainActivity.this).setTitle("退出")//设置对话框标题 .setMessage("官人可是要 ...

  3. MVC实用架构设计:总体设计

    http://developer.51cto.com/art/201309/410166.htm

  4. 字符串和数字的全排列问题、前i位被i整除问题

    // 全排列问题.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> using names ...

  5. 使用disqus搭建comment时一件非常二的事

    近期在github 上面搭建自己的博客,搭建comment部分的时候出现了一个问题:配置都配置好了,可是comment就是不成功.昨天为这个问题折腾了了半晚上没找出原因,今天晚上我突然发现一个地方设置 ...

  6. static_cast

    C 风格(C-style)强制转型例如以下: (T) exdivssion // cast exdivssion to be of type T 函数风格(Function-style)强制转型使用这 ...

  7. js页面换行与空格

    1.换行 +'<br/>\n': 2.空格 1#JS——输出内容document.write#用于直接向 HTML 输出流写内容.简单的说就是直接在网页中输出内容.1.输出内容用“”括起, ...

  8. 什么时候会刷新备库控制文件refresh the standby database control file?

    通过合理的设置,对于Primary的绝大数操作,都是可以传递到Physical Standby,datafile的操作是通过STANDBY_FILE_MANAGEMENT参数来控制的,但是即使STAN ...

  9. mac版gif格式录屏工具下载和使用

    下载链接: http://pan.baidu.com/s/1geeRmtd 密码: rstv ps:如果失效可以联系发邮件至chenruichn@163.com联系我 [以下教程为转载]本帖最后由 S ...

  10. OA、CRM、ERP之间的区别和联系是什么?

    我们假设你是某机械行业的销售,一切从今天你收到公司的邮件,去上海参加展会开始 因为 去展会 所有 首先 你打开 OA 登陆 填写出差申请表 送交主管审批 填表--审批--行政订票酒店 然后呢 你飞去上 ...