老师,关于UnitKeywordIndex更新的操作

来源:7-5 关键词索引对象定义与服务实现

张婧仪

2019-05-22

如果我非要写更新操作,我写的这个可以吗?老师

public void update(String key, Set<Long> value) {
            log.info("keyword index can not support update");
            Set<Long> unitIdSet=CommonUtils.getorCreate(key,keywordUnitMap,ConcurrentSkipListSet::new);
            Iterator<Long> iterator=unitIdSet.iterator();
            while(iterator.hasNext()){
                Set<String> keyword=unitKeywordMap.get(iterator.next());
                keyword.remove(key);
            }

            for(Long unitId:value){
                Set<String> keywordSet=CommonUtils.getorCreate(unitId,unitKeywordMap,ConcurrentSkipListSet::new);
                keywordSet.add(key);
            }
           keywordUnitMap.put(key,value);

    }
写回答

1回答

张勤一

2019-05-22

同学你好:

    你这样的实现是没问题的,不过,这种更新操作发生的概率极低,通常都会不实现的。最合适的做法是删除,重新创建一条记录。


    欢迎来 QQ 群随时交流、讨论,也非常感谢同学的支持!

1
0

Spring Cloud微服务架构 设计实现广告系统

广告营销系统,未来大中型企业的标配

2136 学习 · 927 问题

查看课程