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. actionInvocation

    1.actionInvocation是什么 ActionInvocation就是Action的调用者.ActionInvocation在Action的执行过程中,负责Interceptor.Actio ...

  2. 实现一次请求加载多个js或者css

    http://tengine.taobao.org/   相当牛x

  3. apache 限制指定user_agent

    有些user_agent 不是我们想要的,可以通过rewrite功能针对 %{HTTP_USER_AGENT} 来rewirete到404页,从而达到限制某些user_agent的请求.   配置如下 ...

  4. MVC学习 (二) Razor语法

    MVC的Model层我理解与三层架构的Molde没有区别,都是作为各个层之间的数据沟通桥梁.但是关于Control和View都有一些与传统webform不同的特性. 这里先学习View里所用到的Raz ...

  5. escape和unescape给字符串编码

    var before = "\xxx\xxx" var after = escape(before); var after2 = unescape(after );

  6. 目标管理剖析与实践– 献给追梦的人 (转)

      好久没写日志了. 最近总算在忙碌的日子中小小的松了一口气, 过来补起这几个月的空缺. 上次写的Cover Letter & Resume 重点诠释 - 深度剖析没想到居然超过了一万的阅读量 ...

  7. 关于Oracle中查询结果为未选定行

    今天在做关于Oracle查询语句的练习时,碰到这么一个题目:找出EMP表中姓名(ENAME)第三个字母是A的员工姓名.我的Scott.emp表的现有数据如下: SQL> select * fro ...

  8. html 调用 activeX(c++)

    1.新建MFC ActiveX 2.添加方法 3.找到add函数编写代码 4.在test.idl中找到最后一个uuid 5.编译工程,会自动注册控件 6.html中的代码 <html> & ...

  9. JQuery动态表格

    功能实现:点击添加按钮,表格增加一行并给其name属性赋予的值,方便获取 点击删除,自动删除这一行 JQuery中定义一个count变量 var count = 1; function add() { ...

  10. 层次节点——NODE节点

    1.html <!DOCTYPE html> <html> <head lang="en"> <meta charset="UT ...