English 中文(简体)
在Solr和Java更新一份文件
原标题:Updating a document in Solr with Java

大家都知道,在维基,索利奇的文件相当不好。 我利用共同点HttpSolrServer询问了指数,但从未使用过该版本。 不管怎么说,现在,我用“边缘民族”来显示自治选择,我的指数中有一个实地“计数”,以便我能够根据被问到该要素的人数来分析结果。

我现在想要做的是,能否在我的 Java方案中更新这个“计时”领域,这应当非常容易我猜测? 我审视了来源法的测试档案,但是它非常复杂,试图做类似的事情总是对我失败。 可否使用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>
最佳回答

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!

问题回答

Modified from this test example. To add a value to Solr and then subsequently modify it you can do the following:

//add value to Solr
doc = new SolrInputDocument();
doc.addField("id", "A");
doc.addField("value", 10);
client.add(doc);
client.commit();

//query Solr
SolrQuery q = new SolrQuery("id:A");
QueryResponse r = client.query(q);

//update value
SolrDocument oldDoc = r.getResults().get(0);
SolrInputDocument newDoc = new SolrInputDocument();
newDoc.addField("id", oldDoc.getFieldValue("id");
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("inc", 15);
newDoc.addField("value", map);
client.add(newDoc);
client.commit();

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.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签