solr5.5.0 字段索引,部分更新/删除等操作

1:在solr 的atomic updates 中提供了几种部分更新的方式

1)set-------- Set or replace the field value(s) with the specified value(s), or
   remove the values if 'null' or empty list is specified as the new value.
   May be specified as a single value, or as a list for multivalued fields

2) add-------- Adds the specified values to a multivalued field.
   May be specified as a single value, or as a list.


3) remove------ Removes (all occurrences of) the specified values from
   a  multivalued field.May be specified as a single value, or as a list.

4) removeregex--- Removes all occurrences of the specified regex from a
   multiValued field. May be specified as a single value, or as a list.

5) inc------------ Increments a numeric value by a specific amount.
   Must be specified as a single numeric value.

2: 具体例子关键代码


    public void removeData(){
        List<SolrInputDocument> documentList = new ArrayList<SolrInputDocument>();
        SolrInputDocument doc = new SolrInputDocument();
        doc.addField(SolrFields.id.name(), "123456788");
doc.addField(SolrFields.authorName_s.name(), "yinyunlong");
doc.addField(SolrFields.webSiteName_s.name(), "百度贴吧");
doc.addField(SolrFields.webSiteId_i.name(), "3");
doc.addField(SolrFields.content_zhn.name()
                   ,getAtomicUpdateMap(SolrAtomicUpdate.remove,"百度"));

        documentList.add(doc);
index.addList(documentList);

logger.info("index  finish..........");
     }

     private Map<String, Object> getAtomicUpdateMap(SolrAtomicUpdate update
                                                        , Object value) {
Map<String, Object> map = new HashMap<String, Object>();
map.put(update.name(), value);
return map;
     }

     private static enum SolrAtomicUpdate {
          set, add, remove, removeregex, inc;
     }




你可能感兴趣的:(solr5.5.0 字段索引,部分更新/删除等操作)