**
**
我们把正向索引用在推广计划推广单元还有创意上面。 检索的肯定是一些限制条件。
把索引放在redis 的缓存数据库中。
广告系统的 数据索引的维护:
在数据库中
**
**
**
**‘’‘’
然后定义索引实现类。在这里插入代码片
@Slf4j
@Component
public class AdPlanIndex implements IndexAware<Long,AdPlanObject> {
private static Map<Long, AdPlanObject> objectMap;
static {
objectMap = new ConcurrentHashMap<>();
}
@Override
public AdPlanObject get(Long key) {
return objectMap.get(key);
}
@Override
public void add(Long key, AdPlanObject value) {
log.info("before Add :{}",objectMap);
objectMap.put(key,value);
log.info("after add: {}",objectMap);
}
@Override
public void update(Long aLong, AdPlanObject value) {
log.info("before update :{}",objectMap);
AdPlanObject oldObject = objectMap.get(aLong);
if(oldObject==null){
objectMap.put(aLong,value);
}else{
//这里就是插入l
oldObject.update(value);
}
log.info("after update :{}",objectMap);
}
@Override
public void delete(Long aLong, AdPlanObject Value) {
log.info("before delete :{}",objectMap);
objectMap.remove(aLong);
log.info("after delete :{}",objectMap);
}
}
/*这是一个索引对象 这就是推广计划所涉及的属性*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class AdPlanObject {
private Long planId;
private Long userId;
private Integer planStatus;
private Date startDate;
private Date endDate;
//实现当前对象更新
public void update(AdPlanObject newObject){
if(newObject.getPlanId() != null){
this.planId= newObject.getPlanId();
}
if(newObject.getUserId()!=null){
this.userId=newObject.getUserId();
}
if(newObject.planStatus!=null){
this.planStatus=newObject.getPlanStatus();
}
if(newObject.startDate!=null){
this.startDate=newObject.getStartDate();
}
if(newObject.getEndDate()!=null){
this.endDate=newObject.getEndDate();
}
}
}
继续完成索引对象的服务。 这节课完成 推广单元索引的定义。 搜索的时候
创建索引对象:
然后对索引值进行增删改查: 定义索引对象的map 在静态代码块中实现初始化。
这里是通过key去索取索引对象。
这里是引用
关键词索引对象 的实现:
下面是兴趣与推广单元。
初始化两个map就可以进行增删改查。
定义创意对象的索引对象:
创意与推广单元的关联关系表。
1.创建索引对象:
2.创建索引服务
创意与推广单元是多对多的关系。
实现调用:
package com.imooc.ad.index;/*
author:ma
*/
import org.hibernate.tool.schema.internal.StandardTableExporter;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Bean;
import org.springframework.core.PriorityOrdered;
import org.springframework.stereotype.Component;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@Component
public class DataTable implements ApplicationContextAware, PriorityOrdered {
private static ApplicationContext applicationContext;
public static final Map<Class,Object> dataTableMap =
new ConcurrentHashMap<>();
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
DataTable.applicationContext =applicationContext;
}
@Override
public int getOrder() {
return PriorityOrdered.HIGHEST_PRECEDENCE;
}
@SuppressWarnings("all")
public static <T> T of(Class<T> clazz) {
T in = (T) dataTableMap.get(clazz);
if(in != null){
return in;
}
dataTableMap.put(clazz, bean(clazz));
return (T) dataTableMap.get(clazz);
}
@SuppressWarnings("all")
private static <T> T bean(String beanName){
return (T) applicationContext.getBean(beanName);
}
private static <T> T bean(Class c ){
return (T) applicationContext.getBean(c);
}
}