第十章 广告检索系统——加载全量索引(一)

此博客用于个人学习,来源于网上,对知识点进行一个整理。

1. 导出表数据定义:

接下来来实现加载全量索引的服务,加载全量索引就需要我们将数据库内广告主投放的数据导出到文件里面。一般情况下,这种功能是定义在索引相关操作的服务中,但是这份索引数据是针对于所有服务的,于是我们将其定义在 ad-common 中,其他服务都可以调用。

1.1 定义文件的存储位置:

首先,需要确定的就是文件存储到哪个地方,于是先定义一个类,在其中确定好文件的存储路径和各个索引对应的存储文件名称。

public class DConstant {
   
   

    public static final String DATA_ROOT_DIR = "/Users/imooc/mysql_data/";

    //各个表数据的存储文件名
    public static final String AD_PLAN = "ad_plan.data";
    public static final String AD_UNIT = "ad_unit.data";
    public static final String AD_CREATIVE = "ad_creative.data";
    public static final String AD_CREATIVE_UNIT = "ad_creative_unit.data";
    public static final String AD_UNIT_IT = "ad_unit_it.data";
    public static final String AD_UNIT_DISTRICT = "ad_unit_district.data";
    public static final String AD_UNIT_KEYWORD = "ad_unit_keyword.data";
}

1.2 定义存储的索引表对象:

索引表对象的属性与一开始定义的索引对象的属性相同。

1)广告计划索引表数据:

@Data
@AllArgsConstructor
@NoArgsConstructor
public class AdPlanTable {
   
   

    private Long planId;
    private Long userId;
    private Integer planStatus;
    private Date startDate;
    private Date endDate;
}

2)广告单元索引及其限制表数据:

@Data
@NoArgsConstructor
@AllArgsConstructor
public class AdUnitTable {
   
   

    private Long unitId;
    private Integer unitStatus;
    private Integer positionType;
    private Long planId;
}
@Data
@NoArgsConstructor
@AllArgsConstructor
public class UnitKeywordTable {
   
   

    private Long unitId;
    private String keyword;
}
@Data
@NoArgsConstructor
@AllArgsConstructor
public class UnitItTable {
   
   

    private Long unitId;
    private String itTag;
}
@Data
@NoArgsConstructor
@AllArgsConstructor
public class UnitDistrictTable {
   
   

    private Long unitId;
    private String province;
    private String city;
}

3)广告创意索引与关联表对象:

@Data
@NoArgsConstructor
@AllArgsConstructor
public class CreativeTable {
   
   

    private Long adId;
    private String name;
    private Integer type;
    private Integer materialType;
    private Integer height;
    private Integer width;
    private Integer auditStatus;
    private String adUrl;
}
@Data
@NoArgsConstructor
@AllArgsConstructor
public class CreativeUnitTable {
   
   

    private Long adId;
    private Long unitId;
}

2. 表数据导出文件功能实现:

表数据对象构建完毕后,就是实现表数据导出文件功能了。考虑到需要调用到索引的各种方法,于是将其定义在 ad-sponsor 的 test 文件夹中。

2.1 启动类:

@SpringBootApplication
public class Application {
   
   

    public static void main(String[] args) {
   
   
        SpringApplication.run(Application.class,args);
    }
}

2.2 配置文件:

server:
  port: 7000
  servlet:
    context-path: /ad-sponsor #Controller 的前缀

spring:
  application:
    name: eureka-client-ad-sponsor
  jpa:
    show-sql: true #是否打印 SQL 语句
    hibernate:
      ddl-auto: none #手动创建表,主动控制权会更高
    properties:
      hibernate.format_sql: true #是否对 SQL 语句进行格式化
    open-in-view: false #在懒加载的时候,如果找不到一些 bean 的配置会导致错误,所以设置为 false
  datasource:
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值