第十六章 广告检索系统(二)

该博客详细介绍了广告检索系统的实现过程,包括推广单元的筛选、创意获取、索引服务响应对象填充以及广告检索服务的完善。在推广单元筛选中实现了UnitDistrictIndex的match方法,并在SearchImpl中进行了三重过滤。通过CreativeUnitIndex和CreativeIndex获取创意ID,并对UnitObject和CreativeObject进行过滤。在Controller层完善接口,并在网关中配置检索系统。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

1. 根据匹配信息实现对推广单元的再筛选:

1.1 完善 UnitDistrictIndex:

之前定义的 UnitDistrictIndex 类中并没有 match 的实现方法,需要我们去添加。

public boolean match(Long adUnitId, List<DistrictFeature.ProvinceAndCity> districts){
   
   
    if (unitDistrictMap.containsKey(adUnitId) && CollectionUtils.isNotEmpty(unitDistrictMap.get(adUnitId))){
   
   
        Set<String> unitDistricts = unitDistrictMap.get(adUnitId);
        List<String> targetDistricts = districts.stream().map(
                d -> CommonUtils.stringConcat(d.getProvince(),d.getCity())
        ).collect(Collectors.toList());
        return CollectionUtils.isSubCollection(targetDistricts,unitDistricts);
    }
    return false;
}

1.2 在 SearchImpl 中实现三重过滤:

由于限制间存在 AND 或者 OR 的关系,所以需要分情况进行过滤。

@Slf4j
@Service
public class SearchImpl implements ISearch {
   
   

    @Override
    public SearchResponse fetchAds(SearchRequest request) {
   
   
        // 请求的广告位信息
        List<AdSlot> adSlots = request.getRequestInfo().getAdSlots();
        // 三个 Feature
        KeywordFeature keywordFeature = request.getFeatureInfo().getKeywordFeature();
        DistrictFeature districtFeature = request.getFeatureInfo().getDistrictFeature();
        ItFeature itFeature = request.getFeatureInfo().getItFeature();
        FeatureRelation relation = request.getFeatureInfo().getRelation();
        // 构造响应对象
        SearchResponse response = new SearchResponse();
        Map<String, List<SearchResponse.Creative>> adSlot2Ads = response.getAdSlot2Ads();
        for (AdSlot adSlot : adSlots) {
   
   
            Set<Long> targetUnitIdSet;
            // 根据流量类型获取初始 AdUnit
            Set<Long> adUnitIdSet = DataTable.of(
                    AdUnitIndex.class
            ).match(adSlot.getPositionType());
            if (relation == FeatureRelation.AND){
   
   
                //进行三重过滤
                filterKeywordFeature(adUnitIdSet, keywordFeature);
                filterDistrictFeature(adUnitIdSet, districtFeature);
                filterItTagFeature(adUnitIdSet, itFeature);

                targetUnitIdSet = adUnitIdSet;
            }else {
   
   
                targetUnitIdSet = getORRelationUnitIds(adUnitIdSet,keywordFeature,districtFeature,itFeature);
            }
        }
        return null;
    }

    private Set<Long> getORRelationUnitIds(Set<Long> adUnitIdSet, KeywordFeature keywordFeature, DistrictFeature districtFeature, ItFeature itFeature) {
   
   
        if (CollectionUtils.isEmpty(adUnitIdSet)) {
   
   
            return Collections.emptySet();
        }

        Set<Long> keywordUnitIdSet = new HashSet<>(adUnitIdSet);
        Set<Long> districtUnitIdSet = new HashSet<>(adUnitIdSet);
        Set<Long> itUnitIdSet 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值