solr/solrj按id进行索引更新

最近项目要求solr能够实现索引根据id进行field的局部更新,于是在网上查找了些资料,终于找到了方法,并进行了封装,,简单分享下主要方法体(这里是通过solr api进行的solrj操作索引):

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(); //在某个字段上递增JSONObject add1 = new JSONObject();JSONObject add2 = new JSONObject();JSONObject add3 = new JSONObject();JSONObject add4 = new JSONObject();try {set.put("set", "测试后1");set2.put("set", "新家的名字");set3.put("set", "新家的名字2");set5.put("set", "修改后的新华书店三孝口");add1.put("add", "del1"); //{"add":"Cyberpunk"}add2.put("add", "del2");add3.put("add", "del3");add4.put("add", "火锅领导者");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());}

@Testpublic void test {UpdateSolrField atmoUpdate = new UpdateSolrField(":8080/solr/core2");atmoUpdate.AddIndex();atmoUpdate.UpdateIndex();}

add:能够在原有的field上增加索引内容,注意,此时的field要为多值;若此field不存在,便会在当前的doc中创建一个field;

inc:能够在原有的field能容上递增

set:替换原有的field索引内容,若此时field不存在,便会在当前doc中创建field。

完整代码类可以到下载(下载直接可用)。

教育人的,激励人的,安慰人不开心的. 或者是 诗词 诗经里的..

solr/solrj按id进行索引更新

相关文章:

你感兴趣的文章:

标签云: