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 3279 Fliptile】开关问题,模拟
题目链接:http://poj.org/problem?id=3279 题意:给定一个n*m的坐标方格,每个位置为黑色或白色.现有如下翻转规则:每翻转一个位置的颜色,与其四连通的位置都会被翻转,但注意 ...
- Installing — pylibmc 1.2.3 documentation
Installing - pylibmc 1.2.3 documentation libmemcached
- 【转】nand flash坏块管理OOB,BBT,ECC
0.NAND的操作管理方式 NAND FLASH的管理方式:以三星FLASH为例,一片Nand flash为一个设备(device),1 (Device) = xxxx (Blocks),1 ...
- C#静态构造函数和析构函数片段化认知
一.静态构造函数 一个类可以有静态构造函数,实现如下源代码.静态构造函数有以下特性: 1).静态构造函数不能有修饰符(润饰符) 2).静态构造函数不能有参数 3).不能被调用——在实例化类的时候,静态 ...
- SQL Server 2000 函数使用---CAST 和 CONVERT
本文来自:http://www.cnblogs.com/xh831213/category/47654.html 将某种数据类型的表达式显式转换为另一种数据类型.CAST 和 CONVERT 提供相似 ...
- hive优化之自己主动合并输出的小文件
1.先在hive-site.xml中设置小文件的标准. <property> <name>hive.merge.smallfiles.avgsize</name> ...
- VS2010+ICE3.5运行官方demo报错----std::bad_alloc
纠结了一晚上,在release版本下运行没问题,一到debug就报错,卡在 Ice::ObjectAdapterPtr adapter = ic->createObjectAdapterWith ...
- sql相关操作
1.两个不同数据库对应字段相应操作 //操作模版:insert into data2.table2(字段1,字段2,字段) select 字段j,字段k,字段m from data1.table1举例 ...
- android第一天错误
1.自己写的activity并在AndroidManifest.xml中注册 在模拟机上运行时出现 No Launcher activity found! The launch will only s ...
- Sublime+Emmet
Sublime使用Package Control安装Emmet插件: 按Ctrl+Shift+P命令板 输入install然后选择install Package,然后输入emmet找到 Emmet C ...