我试图使用Lucene索引进行查询,但得到的结果为空,日志中出现以下错误,
Traversal query (query without index): select [jcr:path] from [nt:base] where isdescendantnode('/test') and name='World'; consider creating an index
[async] The index update failed
org.apache.jackrabbit.oak.api.CommitFailedException: OakAsync0002: Missing index provider detected for type [counter] on index [/oak:index/counter]
我正在使用RDB DocumentStore,我已经检查了索引和节点是在节点表中创建的。
@Autowired
NodeStore rdbNodeStore;
//create reposiotory
LuceneIndexProvider provider = new LuceneIndexProvider();
ContentRepository repository = new Oak(rdbNodeStore)
.with(new OpenSecurityProvider())
.with(new InitialContent())
.with((QueryIndexProvider) provider)
.with((Observer) provider)
.with(new LuceneIndexEditorProvider())
.withAsyncIndexing("async",
5).createContentRepository();
//login reposiotory and retrive session
ContentSession contentSession = repository.login(null, null);
Root root = contentSession.getLatestRoot();
//create lucene index
Tree index = root.getTree("/");
Tree t = index.addChild("oak:index");
t = t.addChild("lucene");
t.setProperty("jcr:primaryType", "oak:QueryIndexDefinition", Type.NAME);
t.setProperty("compatVersion", Long.valueOf(2L), Type.LONG);
t.setProperty("type", "lucene", Type.STRING);
t.setProperty("async", "async", Type.STRING);
t = t.addChild("indexRules");
t = t.addChild("nt:base");
Tree propnode = t.addChild("properties");
Tree t1 = propnode.addChild("name");
t1.setProperty("name", "name");
t1.setProperty("propertyIndex", Boolean.valueOf(true), Type.BOOLEAN);
root.commit();
//Create TestNode
String h = "Hello" + System.currentTimeMillis();
String w = "World" + System.currentTimeMillis();
Tree test = root.getTree("/").addChild("test");
test.addChild("a").setProperty("name", Arrays.asList(new String[] { h, w }), Type.STRINGS);
test.addChild("b").setProperty("name", h);
root.commit();
//Search
String query = "select [jcr:path] from [nt:base] where isdescendantnode('/test') and name='World' option(traversal ok)";
List<String> paths = executeQuery(root, query, "JCR-SQL2", true, false);
for (String path : paths) {
System.out.println("Path=" + path);
}
任何人都可以分享一些关于如何创建Lucene索引的示例代码吗?
你可能会做的事情有几个问题。首先是你观察到的错误。因为您使用的是初始内容
,它规定了带有type="计数器"
的索引。为此,您需要在构建存储库时使用. with(new NodeCounterEditorProvider())
。这应该可以避免您看到的错误。
但是,您的代码可能仍然无法工作,因为lucene索引是异步的(您已经正确配置)。由于这种异步行为,您无法在添加节点后立即进行查询。我尝试了你的代码,但不得不添加类似线程的东西。在进行查询之前先睡眠(10*1000)
。
另一方面,我建议您尝试使用IndexDefinitionBuilder
来创建lucene索引结构。因此,您可以替换树索引=根。getTree(“/”);
Tree t = index.addChild("oak:index");
t = t.addChild("lucene");
t.setProperty("jcr:primaryType", "oak:QueryIndexDefinition", Type.NAME);
t.setProperty("compatVersion", Long.valueOf(2L), Type.LONG);
t.setProperty("type", "lucene", Type.STRING);
t.setProperty("async", "async", Type.STRING);
t = t.addChild("indexRules");
t = t.addChild("nt:base");
Tree propnode = t.addChild("properties");
Tree t1 = propnode.addChild("name");
t1.setProperty("name", "name");
t1.setProperty("propertyIndex", Boolean.valueOf(true), Type.BOOLEAN);
root.commit();
与
IndexDefinitionBuilder idxBuilder = new IndexDefinitionBuilder();
idxBuilder.indexRule("nt:base").property("name").propertyIndex();
idxBuilder.build(root.getTree("/").addChild("oak:index").addChild("lucene"));
root.commit();
国际海事组织(imo)的后一种方法不太容易出错,而且更容易出错。
下面的lucene查询返回空字符串请帮忙,提前谢谢
我的任务是使用lucene在我们的产品表中搜索。我已经创建了一个索引,正在使用带有多个字段的QueryParser进行搜索,但结果不是我所需要的。我有一个存储为LM10的产品,但如果搜索词是LM 10,我希望能够找到它,但如果搜索词是Fred LM10或Fred LM 10,它也必须能够匹配。你知道我如何在Lucene做到这一点吗。 提前谢谢
我可以使用Lucene查询ElasticSearch索引吗? 我使用ElasticSearch创建了一个索引,并插入了以下三个文档: null 不幸的是,d.get(“_source”)也返回null。 如何检索匹配查询的文档字段? 谢谢你。
这是我想解决的问题: 我有多个Lucene索引,每个索引包含相同数据结构的子集(它们具有相同的字段,但是字段可能存在于文档中,也可能不存在于某个索引中) 索引之间共享一个全局标识符。也就是说,如果有4个索引,最多可能有4个文档共享一个密钥。 我有一个单一的Lucene查询 我使用一起查询所有索引,并且我能够使用找出命中来自哪个子索引。到目前为止还不错,但问题是: 为了执行一个(相当复杂的)合并逻辑
索引时间字段提升和查询时间提升 Lucene的FAQ似乎与javadoc冲突。(Lucene 4.9.0) 常见问题: 索引时间字段增强(field.set增强(增强))是一种表达类似于“此文档的标题价值是大多数文档标题的两倍”的方式。查询时间提升(query.setBoost(提升))是表达“我关心查询的这个子句上的匹配是关心查询的其他子句上的匹配的两倍”的一种方式。 如果您在每个文档上设置索引
为了在Lucene查询返回的文档中显示突出显示的匹配词,Lucene搜索结果可能包含用于将文档作为匹配我的请求返回的词。 例如: > Lucene查询:"狗猫" 结果:[“狗很好”,“狗和猫是朋友”] 如何通过Lucene实现这一点?我无法手动处理猫或狗,也无法处理请求词和返回词之间的任何差异。