lucene

Lucene in Action-构建索引

泪湿孤枕 提交于 2019-12-17 20:50:25
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 文档和域(document、filed) 索引过程,将原始数据转换成Lucene能识别的 document和filed 搜索过程,被搜索对象为域值 Lucene 索引过程 分析过程,将 域文本 处理成 大量语汇单元 提取文本、创建文档 分析文档 分析文本,先将其转换成语汇单元串 也包括一系列可选操作:比如去除无意义词语,改变词语的状态等 IndexWriter 的 addDocument 向索引添加文档 倒排索引存储结构,有效利用磁盘空间 将语汇单元作为查询关键字,而不是整个文档 索引段 Lucene 索引都包含一个或多个段 每个段都是独立索引 是整个文档索引的子集 每当write刷新缓存区增加的文档、挂起目录、删除操作,都会新增加一个段 搜索索引时,每个段独立访问,结果合并返回 每个段包含多个文件 格式为 _x.<ext> .<ext>为扩展名,表示对应的索引的某个部分 压缩成单一文件:_X.cfs 特殊文件:段文件 _<N> 指向所有激活的段 Lucene 先打开它,再去打开他指向的段 <N> 代表整数,修改一次索引 加1 段集聚太多 周期性合并一些段成新的段(然后删掉老的多个段) 基本索引操作 向索引中添加文档 删除索引文档 优化删除,强制合并索引段 更新索引文档 Lucene无法做到更新操作

谈谈lucene中的BytesRefHash

◇◆丶佛笑我妖孽 提交于 2019-12-17 20:50:09
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> lucene中很多的数据结构都采用了个性化的实现,而且没有利用一些通用的开源的其它框架,主要的目的还是为了 灵活可控、保证高效率、节约内存, BytesRefHash就是其中一个基本的、重要的、核心的数据结构。 根据lucene中给出的注释,BytesRefHash是一个类似于HashMap的数据结构,但我个人认为它更像一个ArrayList与HashSet的混合物。因为它并不能像传统的HashMap一样存储任意的key和value,只能基于元素的索引号与元素值进行一些简单的读取、判断元素是否存在等功能。基于元素的索引号读取元素类似于ArrayList,判断元素是否存在(内部实现通过哈希算法实现)类似于HashSet。 在其内部有一个核心的类就是ByteBlockPool,基于该类可以 保证数据在物理上的连续性,带来的好处是提高数据的访问效率,并节约内存空间。 关于提高数据的访问效率比较好理解,因为物理上连续的数据能更好的利用cpu cache。能节约内存空间主要是因为java对象的内存布局主要包含3个部分:对象头、数据域和padding,而BytesRefHash主要是对BytesRef字节对象进行处理,通过对字节对象的合并连续存储能够减少对象头和padding占用的空间,从而节约内存。

谈谈lucene的数据域合并

China☆狼群 提交于 2019-12-17 20:37:02
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 记得一年前写了 谈谈lucene的数据域存储 ,主要说明了数据域的存储结构和压缩,而这里主要说明多个数据段中数据域的合并。 一种最朴素的合并方法是将每个数据段中的document读取出来,然后重新写成一个新的数据段。当然lucene采用了更加“灵活”的方法,而这种朴素的合并方法也只有当不同的lucene版本进行合并时才使用。实际上lucene真正合并时有三种方式: 1、第一种为needsIndexSort属性为true时的写入方式(由于对该属性暂时未研究,因此放到以后进行分析); 2、当数据段采用了相同的压缩算法,每个段中的chunkSize相同并且没有更新数据时,可以将整个段中的数据直接复制到当前的数据段中,这也是最快的方式;这里有个注意事项,由于每个数据段中通常最后一个数据块是写不满的(lucene中称之为脏块),当脏块的数量超过一定限度时,是不能直接按照该方式进行合并的! 3、如果不满足第二个条件,此时就需要从每个数据段中将document读取出来,然后再写入,但是lucene记录了每条数据的文件指针,所以在读取时并没有解析数据类型,而是直接复制字节数组。 最后从lucene的代码中也可以看出,lucene是在数据合并时将更新数据重新写入新的数据块中的。 来源: oschina 链接: https:/

Solr/Lucene fieldCache OutOfMemory error sorting on dynamic field

▼魔方 西西 提交于 2019-12-17 19:29:39
问题 We have a Solr core that has about 250 TrieIntField s (declared as dynamicField ). There are about 14M docs in our Solr index and many documents have some value in many of these fields. We have a need to sort on all of these 250 fields over a period of time. The issue we are facing is that the underlying lucene fieldCache gets filled up very quickly. We have a 4 GB box and the index size is 18 GB. After a sort on 40 or 45 of these dynamic fields, the memory consumption is about 90% and we

How to query lucene with “like” operator? [duplicate]

五迷三道 提交于 2019-12-17 18:28:10
问题 This question already has answers here : Leading wildcard character throws error in Lucene.NET (3 answers) Closed 6 years ago . The wildcard * can only be used at the end of a word, like user* . I want to query with a like %user% , how to do that? 回答1: Lucene provides the ReverseStringFilter that allows to do leading wildcard search like *user. It works by indexing all terms in reverse order. But I think there is no way to do something similar to 'LIKE %user%'. 回答2: The trouble with LIKE

How do i implement tag searching? with lucene?

﹥>﹥吖頭↗ 提交于 2019-12-17 17:41:33
问题 I havent used lucene. Last time i ask (many months ago, maybe a year) people suggested lucene. If i shouldnt use lucene what should i use? As am example say there are items tagged like this apples carrots apples carrots apple banana if a user search apples i dont care if there is any preference from 1,2 and 4. However i seen many forums do this which i HATED is when a user search apple carrots 2 and 3 have high results while 1 is hard to find even though it matches my search more closely.

How do i implement tag searching? with lucene?

狂风中的少年 提交于 2019-12-17 17:41:14
问题 I havent used lucene. Last time i ask (many months ago, maybe a year) people suggested lucene. If i shouldnt use lucene what should i use? As am example say there are items tagged like this apples carrots apples carrots apple banana if a user search apples i dont care if there is any preference from 1,2 and 4. However i seen many forums do this which i HATED is when a user search apple carrots 2 and 3 have high results while 1 is hard to find even though it matches my search more closely.

Lucene.Net Search result to highlight search keywords

我的未来我决定 提交于 2019-12-17 17:29:28
问题 I use Lucene.Net to index some documents. I want to show the user a couple of lines as to why that document is in the result set. just like when you use google to search and it shows the link and followed by the link there are a few lines with the keywords highlighted. any ideas? 回答1: When you have a result you can get the indexed text pass it along with your query through a method similar to this: public string GeneratePreviewText(Query q, string text) { QueryScorer scorer = new QueryScorer

NLuke版本更新信息

我是研究僧i 提交于 2019-12-17 11:38:27
1、 NLuke是什么? NLuke是参照Luke(lukeall)的功能开发的Lucene索引管理工具。 2、NLuke的运行 NLuke是用C#开发的基于.Net Framework运行的程序。 3、下载信息 产品名:NLuke 版本号:0.1.3 作 者:谢平 项目地址:http://code.google.com/p/nluke/ 源码下载: http ://nluke.googlecode.com/svn/trunk/ (使用svn checkout) 更新时间:2009-11-1 02:04 平台需求:.Net Framework 2.0 帮助信息: Lucene.Net索引管理工具NLuke使用帮助 (带界面图像) 更新说明: 由于更换公司过程中导致源码丢失,因此这部分是重新的代码。最近一直很忙,闲下来的时候也没想起来要更新,还有朋友跟我要源码。呵呵,抱歉了,这个版本实现了大部分的功能,搜索部分没有做,下次补上。 本次有价值的更新主要是更改了对索引有效性的判别。 ---------------------------------------------------------------------- 产品名:NLuke 版本号:0.1.2 作 者:谢平 下载地址: NLuke0.12.rar (212K,RAR压缩) 更新时间:2008- 9-23 16:23

Remove results below a certain score threshold in Solr/Lucene?

六月ゝ 毕业季﹏ 提交于 2019-12-17 10:49:35
问题 Is there a built-in functionalities in solr/lucene to filter the results if they fall below a certain score threshold? Let's say if I provide a score threshold of .2, then all documents with score less than .2 will be removed from my results. My intuition is that this is possible by updating/customizing solr or lucene. Could you point me to right direction on how to do this? Thanks in advance! 回答1: You could write your own Collector that would ignore collecting those documents that the scorer