lucene3.0范围查找TermRangeQuery

news/2025/2/27 6:26:31
在lucene3.0中,范围查询也有很大的变化,RangeQuery已经不推荐使用,使用TermRangeQuery和NumericRangeQuery两个替代。
TermRangeQuery:主要用于文本范围查找;
IndexReader reader = IndexReader

       .open(FSDirectory.open(INDEX_DIR), true); // only searching,

Searcher searcher = new IndexSearcher(reader);

String field = "starttime";

TermRangeQuery query = new TermRangeQuery(field,

       "2009年01月01日","2009年01月05日",true,true);

ScoreDoc[] hits = searcher.search(query, null, topnum).scoreDocs;

NumericRangeQuery:要使用它,首先要使用NumericField 给数字建索引(当然这个的term就是数字的了)。如果你的term是文本,那就是使用TermRangeQuery 。
英文原文:
public TermRangeQuery(String field,

                      String lowerTerm,

                      String upperTerm,

                      boolean includeLower,

                      boolean includeUpper)

Constructs a query selecting all terms greater/equal than lowerTerm but less/equal than upperTerm.

If an endpoint is null, it is said to be "open". Either or both endpoints may be open. Open endpoints may not be exclusive (you can’t select all but the first or last term without explicitly specifying the term to exclude.)

Parameters:

field – The field that holds both lower and upper terms.

lowerTerm – The term text at the lower end of the range

upperTerm – The term text at the upper end of the range

includeLower – If true, the lowerTerm is included in the range.

includeUpper – If true, the upperTerm is included in the range.

 

http://www.niftyadmin.cn/n/4235205.html

相关文章

子查询 和 连接查询谁快

子查询 和 连接查询 可以达到同样的效果 即 相同的结果集,但是谁快谁慢?一般连接查询如果后期添加条件 需要改原来SQL,为了不改原来SQL,我一般会用子查询来做,这样意思比较明确且不动原来sql,但是心里有个疑…

Postgresql优化器如何使用列统计信息?

对pg_statistic表的查询都是走syscache的,要找到所有使用列统计信息地方,遍历系统表索引即可 enum SysCacheIdentifier {...STATEXTDATASTXOID,STATEXTNAMENSP,STATEXTOID,STATRELATTINH,... }下面是最常用的STATRELATTINH索引场景,即 Sear…

多个left join 执行流程

select a.cName from table1 a LEFT JOIN table2 b ON a.codeb.code LEFT JOIN table3 c ON a.codec.code过程是这样的:1, 首先table1左链接table2,得到一个中间结果,该中间结果包括table1的所有行以及table2中与table1匹配条件(a.codeb.code)的行2, 该中间结果左链接table3,得…

FGMap API 帮助文档

FGMap API 帮助文档,如果需要用FGMap API进行地图开发的朋友,可以参考这个文档。 内容就不发到这里了,因为放上来格式会有点乱,所以放在别处了。 帮助地址是:http://fgmap-webgis.googlecode.com/svn/trunk/help/help.…

oracle非空闲的等待事件-direct path read

direct path read(USER I/0类) 与直接读取相关联的等待事件。当ORACLE将数据块直接读入会话的PGA(进程全局区)中,同时绕过SGA(系统全局区)。PGA中的数据并不和其他的会话共享。即表明,读入的这部分数据该会…

(转) 索引

复合索引的优点和注意事项 概念: 单一索引是指索引列为一列的情况,即新建索引的语句只实施在一列上; 用户可以在多个列上建立索引,这种索引叫做复合索引(组合索引); 复合索引在数据库操作期间所需的开销更小,可以代替多个单一索引; 同时有两个概念叫做窄索引和…

Nagios服务器架设之一

Nagios服务器架设之一 实验环境:RHEL 5.4一、Nagios服务器安装过程1)配置服务器端IP地址[rootlocalhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]DEVICEeth0BOOTPROTOnoneHWADDR00:0c:2…

sql疑问记录

1、查询最大begindate的记录(一个clerkcode有多个begindate值的记录) ,相关子查询?in?: select * from hi_psnjob a where a.begindate in ( select max(b.begindate) from hi_psnjob b where b.clerkcode a.clerk…