Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
498 views
in Technique[技术] by (71.8m points)

solr - solrj api for partial document update

Solr 4 beta is out, the GA version will follow soon. Partial document updates has been around for a while as explained here: http://solr.pl/en/2012/07/09/solr-4-0-partial-documents-update/

However, I haven't figured out how to do it with solrj api.

Does anyone knows if it is possible with solrj? Or is solrj just not up-to-speed with this feature?

update: as I describe in the mailing list (see reply here), I found that in the solrj api, the value of a SolrInputField can be a map - it doesn't have to be a simple scalar value. If it is a map, solrj adds an additional update attribute to the field's xml element. For example, This code:

SolrInputDocument doc = new SolrInputDocument();
Map<String, String> partialUpdate = new HashMap<String, String>();
partialUpdate.put("set", "foo");
doc.addField("id", "test_123");
doc.addField("description", partialUpdate);

yields this document:

<doc boost="1.0">
    <field name="id">test_123</field>
    <field name="description" update="set">foo</field>
</doc>

In this example I used the word "set" for this additional attribute, but it doesn't work. Solr doesn't update the field as I expected. According to this link: http://solr.pl/en/2012/07/09/solr-4-0-partial-documents-update/ valid values are "set" and "add".

Any idea?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As it turns out, the code snippet shown above in the question actually works. I don't know what was wrong the first time I tried it, perhaps I simply forgot to commit or my schema was misconfigured.

In any case, this question is very localized. However, since the api with the hash map is so poorly documented, I thought maybe it is worth to keep this question and answer.

The key of the hash map can be one of three values:

  • set - to set a field.
  • add - to add to a multi-valued field.
  • inc - to increment a field.

There is an example of this code in the solrj unit tests, in a method called testUpdateField.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...