使用 Java 更新 Solr 中的文档
众所周知,wiki 中 Solrj 的文档非常贫乏。我设法使用 CommonsHttpSolrServer 查询索引,但从未使用嵌入式版本查询索引。不管怎样,现在我使用 EdgeNGrams 来显示自动建议,并且我的索引中有一个字段“count”,这样我就可以按照人们查询元素的次数对结果进行排序。
我现在想做的是能够更新我的 Java 程序中的这个“count”字段,我想这应该很容易吧?我从源代码中查看了测试文件,但它非常复杂,并且尝试做类似的事情对我来说总是失败。也许通过使用 Solrj ?
感谢您的帮助。
编辑: 在我的 java 代码中,我有:
CoreContainer.Initializer initializer = new CoreContainer.Initializer();
CoreContainer coreContainer = initializer.initialize();
此时我期望得到的是 coreContainer 中 solr.xml 中定义的核心,但那里没有核心(但 defaultCoreName 表示 collection1)。我的 solr.xml 文件与示例目录中的相同:
<solr persistent="false">
<cores adminPath="/admin/cores" defaultCoreName="collection1">
<core name="collection1" instanceDir="." />
</cores>
</solr>
As everybody knows, the documentation of Solrj in the wiki is pretty poor. I managed to query the index using the CommonsHttpSolrServer, but never with the Embedded version. Anyway, now I'm using the EdgeNGrams to display auto-suggestions, and I have a field "count" in my index, so that I can sort the results by the number of times people queried the element.
What I want to do now, is to be able to update this "count" field in my Java program, which should be quite easy I guess? I looked at the test files from the source code, but it's very complicated, and trying to do something similar always failed for me. Maybe by using Solrj?
Thanks for your help.
Edit:
In my java code, I have:
CoreContainer.Initializer initializer = new CoreContainer.Initializer();
CoreContainer coreContainer = initializer.initialize();
What I expect to get at this point, is the cores defines in solr.xml present in the coreContainer, but there is no core there (but defaultCoreName says collection1). My solr.xml file is the same as in the example dir:
<solr persistent="false">
<cores adminPath="/admin/cores" defaultCoreName="collection1">
<core name="collection1" instanceDir="." />
</cores>
</solr>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
修改自 这个测试示例。要将值添加到 Solr,然后对其进行修改,您可以执行以下操作:
这会将原始 10 值增加到 25。您还可以“添加”到现有字段,或者通过更改您输入的命令来“设置”现有值你在 HashMap 中放入的内容。
Modified from this test example. To add a value to Solr and then subsequently modify it you can do the following:
This increments the original 10 value to 25. You can also "add" to an existing field or simply "set" an existing value by changing what command you put what you put the in the HashMap.
我最后只是将这个计数存储在 Solr 中,然后检索它并更新它,然后运行更新,因为不可能更新 Solr 中的单个字段以及计数字段,这可能非常方便!
I finally just store this count in Solr, then retrieve it and update it, then run an update, since it is not possible to update a single field in Solr and also the count field, which could be very handy!