在文本搜索中,有时也需要一次搜索多个id,这里id类似数据库里面的主键。

这个id在索引里面的倒排列表长度往往等于1.

例如:根据id=[1,2,4,6,7]查询索引

最最一般的思路是构造一个booleanQuery,然后add 5个TermQuery,用should逻辑。

但是这个检索效率肯定不行。

可行的一个办法是:

TermDocs td = null;//

int[] docIds = new int[ids.length];//存放结果

int count = 0 ;

td = search.getIndexReader().termDocs();

for(id : ids){

td.seek(new Term("id", id));//NumericUtils

if(td.next())

docIds[count++] = td.doc();

}//伪代码

docIds收集了ids对应索引中的docId,下一步直接从search中获取document即可。

//

数据库做这事一般使用in,貌似效率也很一般,有什么好办法么?

lucene 一次查询多个id的更多相关文章

  1. SQL 查询某字段id为空(不为空)

    1 sql 查询某字段id为空 select *  from  表名 where  id  is   null  ; 2 sql 查询某字段id不为空 select * from   表名  wher ...

  2. lucene 转义含有查询关键词的字符的

    http://www.oschina.net/question/1092_560 Escaping Special Characters Lucene支持转义查询中的特殊字符,以下是Lucene的特殊 ...

  3. angular6 路由拼接查询参数如 ?id=1 并获取url参数

    angular6 路由拼接查询参数如 ?id=1 并获取url参数 路由拼接参数: <div class="category-border" [routerLink]=&qu ...

  4. lucene复合条件查询案例——查询name域 或 description域 包含lucene关键字的两种方式

    方式一:使用语法表达式查询 //查询name域 或 description域包含lucene关键字 QueryParser queryParser = new QueryParser("na ...

  5. lucene 7.x 查询

    @Test public void indexSearch() throws IOException, ParseException { //Termquery:精确string查询 // Query ...

  6. (六)lucene之其他查询方式(组合查询,制定数字范围、指定字符串开头)

    本章使用的是lucene5.3.0 指定数字范围查询 package com.shyroke.test; import java.io.IOException; import java.nio.fil ...

  7. lucene的索引查询

    package com.hope.lucene;import org.apache.lucene.document.Document;import org.apache.lucene.document ...

  8. 数据库查询返回Resource id #9后的处理方式

    如果在调用PHP查询数据库,在echo后返回的是Resource id #9,可能你的输出方式是: $sql="SELECT * FROM dbname WHERE id='1'" ...

  9. 查询数据库最大id加1

    SELECT ISNULL(MAX(id),0)+1 AS MaxId FROM TABLE ISNULL(MAX(id),0) 就是如果id为空 就返回0,然后再加1

随机推荐

  1. 打印GBK、GB2312字符集全字符

    根据编码表填充数据就可以了~~~~(>_<)~~~~~\(≧▽≦)/~啦啦啦 #include <stdio.h> #include <stdlib.h> #inc ...

  2. Unity 3D光源-Spot Light聚光灯用法详解、模拟手电筒、台灯等线性教程

    Unity4大光源之聚光灯 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Chinar -- 心分享. ...

  3. eclipse 大小写转换

    大写:Ctrl+Shift+X 小写:Ctrl+Shift+Y

  4. css完成下图

    <div></div> div{ height: 48px; width: 80px; padding: 0 16px 0 32px; background: rgba(0,0 ...

  5. 洛谷P1070 道路游戏(dp+优先队列优化)

    题目链接:传送门 题目大意: 有N条相连的环形道路.在1-M的时间内每条路上都会出现不同数量的金币(j时刻i工厂出现的金币数量为val[i][j]).每条路的起点处都有一个工厂,总共N个. 可以从任意 ...

  6. Uva 816 Abbott's Revenge(BFS)

    #include<cstdio> #include<cstring> #include<vector> #include<queue> using na ...

  7. getpwnam,getgrnam,getpwent,crypt等函数

    [root@bogon code]# cat a.c #include<stdio.h> #include<pwd.h> int main() { struct passwd ...

  8. 05机器学习实战之Logistic 回归scikit-learn实现

    https://blog.csdn.net/zengxiantao1994/article/details/72787849似然函数 原理:极大似然估计是建立在极大似然原理的基础上的一个统计方法,是概 ...

  9. C# to IL 8 Methods(方法)

    The code of a data type is implemented by a method, which is executed by the ExecutionEngine. The CL ...

  10. video conference s/w

    CamFrogWindows | Mac OS | Linux (Server only) | iOS | Android | Windows PhoneCamFrog lets you set up ...