lucene本身對原子更新沒有太多的介紹,但solr對其進行了封裝,這裡簡單做個介紹;這點操作還是對索引很實用的。 具體在代碼中使用如下:
- public static void updateSolrField()throws Exception{
- SolrInputDocument doc = new SolrInputDocument();
- doc .addField("id", "10");//根據id唯一辨別
- Map<String,String> map=new HashMap<String, String>();
- map.put("add", "新加的field");//放入支援的操作,對多值域管用 ,增加field
- //map.put("set", "更新後的field");//對單值和多值域管用,更新field
- //map.put("inc", "100");//放入支援的操作,對數值域管用
- sd.addField("name", map);
- server.add(sd);
- server.commit();
- System.out.println("原子更新成功!");
- }
當然要注意一點的是,操作的field必須為存儲(store="true"),否則更新的索引會覆寫前面的索引。