The recent project requires SOLR to be able to implement an index based on the ID of the local field update, so on the Internet to find some information, finally found the method, and encapsulated, simple sharing under the Main method body (here is the SOLRJ operation index through the SOLR API):
...
public void Updateindex () {
Jsonarray content = new Jsonarray ();
Jsonobject json = new Jsonobject ();
Jsonobject set = new Jsonobject ();
Jsonobject Set2 = new Jsonobject ();
Jsonobject Set3 = new Jsonobject ();
Jsonobject set5 = new Jsonobject ();
Jsonobject inc = new Jsonobject (); Increment on a field
Jsonobject add1 = new Jsonobject ();
Jsonobject add2 = new Jsonobject ();
Jsonobject add3 = new Jsonobject ();
Jsonobject add4 = new Jsonobject ();
try {
Set.put ("Set", "1 after Test");
Set2.put ("Set", "New home Name");
Set3.put ("Set", "New home Name 2");
Set5.put ("Set", "modified Xinhua bookstore Three filial mouth");
Add1.put ("Add", "Del1"); {"Add": "Cyberpunk"}
Add2.put ("Add", "Del2");
Add3.put ("Add", "Del3");
Add4.put ("Add", "hotpot leader");
Json.put ("id", "1")
. put ("Name_ss", Set3)
. put ("name_s", Set2)
. Put ("name", set)
. put ("Ca1_ss", ADD1)
. put ("Cat2_ss", ADD2)
. put ("Cat3_ss", ADD3)
. put ("Content_smart_max_2", ADD4)
. put ("Content_smart_max_2", SET5);
Content.add (JSON);
SYSTEM.OUT.PRINTLN (content);
SYSTEM.OUT.PRINTLN (JSON);
} catch (Final Jsonexception e) {
}
Sendhttpmessage (Base_url + "/update", content.tostring ());
}
@Test
public void Test {
Updatesolrfield atmoupdate = new Updatesolrfield ("Http://172.37.37.21:8080/solr/core2");
Atmoupdate.addindex ();
Atmoupdate.updateindex ();
}
Add: Ability to add indexed content to the original field, note that the field at this time is multi-valued, and if this field does not exist, a field is created in the current doc;
INC: Ability to increase in existing field capacity
Set: Replaces the original field index content, and if the field does not exist at this point, the field is created in the current doc.
The full code class can be downloaded to http://download.csdn.net/detail/u013035314/8825933 (download is available directly).
SOLR/SOLRJ index updates by ID