- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一个文件夹 (MY_FILES),其中包含大约 500 个文件,并且每天都会收到一个新文件并将其放置在那里。每个文件的大小约为 4Mb。
我刚刚开发了一个简单的“void main”来测试我是否可以在这些文件中搜索特定的通配符。它工作得很好。
问题是我要删除旧的 indexed_folder 并重新索引。这需要花费大量时间并且显然效率低下。我正在寻找的是“增量索引”。意思是,如果索引已经存在 - 只需将新文件添加到索引中。
我想知道 Lucene 是否有某种机制可以在尝试索引之前检查“doc”是否已被索引。像 writer.isDocExists 这样的东西?
谢谢!
我的代码是这样的:
// build the writer
IndexWriter writer;
IndexWriterConfig indexWriter = new IndexWriterConfig(Version.LUCENE_36, analyzer);
writer = new IndexWriter(fsDir, indexWriter);
writer.deleteAll(); //must - otherwise it will return duplicated result
//build the docs and add to writer
File dir = new File(MY_FILES);
File[] files = dir.listFiles();
int counter = 0;
for (File file : files)
{
String path = file.getCanonicalPath();
FileReader reader = new FileReader(file);
Document doc = new Document();
doc.add(new Field("filename", file.getName(), Field.Store.YES, Field.Index.ANALYZED));
doc.add(new Field("path", path, Field.Store.YES, Field.Index.ANALYZED));
doc.add(new Field("content", reader));
writer.addDocument(doc);
System.out.println("indexing "+file.getName()+" "+ ++counter+"/"+files.length);
}
最佳答案
首先,您应该使用 IndexWriter.updateDocument(Term, Document)
而不是 IndexWriter.addDocument
来更新文档,这将防止您的索引包含重复条目。
要执行增量索引,您应该将last-modified
时间戳添加到索引的文档中,并且只索引较新的文档。
编辑有关增量索引的更多详细信息
您的文档应该至少有两个字段:
- the path of the file
- the time stamp when the file has been modified for the last time.
在开始索引之前,只需在您的索引中搜索最新的时间戳,然后爬取您的目录以查找时间戳比索引的最新时间戳更新的所有文件。
这样,每次文件更改时都会更新您的索引。
关于java - lucene:如何执行增量索引并避免 'delete and redo',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12462652/
这个问题已经有答案了: What is x after "x = x++"? (18 个回答) 已关闭 6 年前。 public static void main(String[] args)
我目前正在使用 jquery 循环插件。我有 3 个不同的幻灯片,它们彼此相邻并同时循环播放。我想做的是先关闭第一张幻灯片,然后是第二张幻灯片,然后是第三张幻灯片。无论如何,我可以通过增量或超时来做到
这个问题在这里已经有了答案: 关闭 11 年前。 Possible Duplicate: ++someVariable Vs. someVariable++ in Javascript 我知道您可以
我一直在查看 SVN 手册,但无法找到“svn log”和“svn st”的“--incremental”选项的简单用法示例或解释。 我正在编写一个开源 SVN GUI 前端,因此我需要一些有关此标志
我有这种矩阵。 非常抱歉,我没有可重现的示例。 表 1: [,1][,2][,3][,4][,5][,6][,7][,8][,9][,10] [1,] 3 NA NA NA
我在hdfs中有一个 Parquet 文件作为我的数据的初始加载。接下来的所有拼花地板只是这些数据集每天都会更改为初始负载(按时间顺序)。这是我的三角洲。 我想读取全部或部分 Parquet 文件,以
我目前有这样的功能,可以将任何输入数字四舍五入到最接近的模糊整数值: $(function(){ $('#my_value').blur(function() { $(this).va
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 要求提供代码的问题必须表现出对所解决问题的最低限度的了解。包括尝试的解决方案、为什么它们不起作用以及预期结果
我对 SQL 还很陌生,我想知道我是否可以使用它来自动解决我数据库中的一个复杂问题。 也就是说,我每天都在跟踪条目。因此,我们关注的列是: YYYY MM DD XXX YYYY 是年,MM 是月,D
我正在开发一个非常简单的数据库,但我不知道数据透视表是否是一个很好的解决方案。如果我使用数据透视表,我需要添加无用的表只是为了增量。 让我们从头开始。 在用户注册期间,会创建一个新表 GROUP。在G
在 MySQL 中你可以做这样的事情 SELECT @n := @n + 1 n, first_name, last_name FROM table1, (SELECT
如果我正在使用一个类,我知道如何重载运算符 += class temp { public: int i; temp(){ i = 10; } int operator+=(in
我有两个文件:file1、file2。我想从 file2 中获取 file1 中不存在的行。 我读过 post这告诉我使用 grep 的 -v 标志来执行此操作(我阅读了 grep 的手册页,但仍然不
我看了很多类似的题,功能很简单,用于API的嵌套for循环,每分钟可以调用5次。所以我将一年数据的范围设置为 75。你们能帮我解决这个问题吗?提前致谢! 第一部分正在运行,输入列表中的邮政编码。 fo
所以我想计算每日返回/增量的一些时间序列数据,其中每日增量 = value_at_time(T)/value_at_time(T-1) import pandas as pd df=pd.DataFr
请帮我解决这个问题。该表达式之后的步骤是: //Expression offSpring1[m1++] = temp1; //Steps: 1.- increment m1 2.- assign te
我正在开发一个解决方案,在该解决方案中,我通过 webapp 不同类型的实体(例如中央数据库上的用户、组、部门信息)和 ldap 进行身份验证。但是最终用户将与来自远程位置(他的办公室、节点)的数据交
我有以下 Python 数据结构: data1 = [{'name': u'String 1'}, {'name': u'String 2'}] data2 = [{'name': u'String
如果 AtomicInteger 会发生什么?达到 Integer.MAX_VALUE 并递增? 值会回到零吗? 最佳答案 由于integer overflow,它会环绕, 到 Integer.MIN
我是 C 的初学者,我正在尝试在 While 循环中进行 0.00001 增量。例如,double t = 0.00001 并且我希望循环每次以 0.00001 的增量运行,第二次是 0.00002
我是一名优秀的程序员,十分优秀!