Giter Site home page Giter Site logo

westfly / clorisearch Goto Github PK

View Code? Open in Web Editor NEW

This project forked from shpilu/clorisearch

0.0 1.0 0.0 352 KB

广告检索引擎(针对在线广告设计,支持简单倒排检索、范围检索、LBS检索,持续完善中)

License: MIT License

CMake 3.31% C++ 92.25% C 4.44%

clorisearch's Introduction

English Version

cloriSearch

cloriSearch是一套检索引擎内核,致力于解决常规业务开发中的策略检索与在线广告匹配问题,为中小互联网公司商业变现提供一套开源的广告检索技术解决方案。

除了广告检索以外,cloriSearch也可以作为规则引擎,应用于基于内容的策略发布/订阅系统中(content-based publish/ subscribe systems,即根据输入参数调度执行相应的策略),比如一般业务系统中的ABtest、调度引擎、策略匹配等模块。

主要特性

cloriSearch目前支持简单倒排检索、范围检索(或者叫区间检索)、LBS检索等三种检索方式(基本能cover除搜索广告之外的其他广告定向条件),这三类检索方式的具体内涵是指

  • 简单倒排检索 - 最基础的检索方式,term的值是一个有限集合,比如 city ∈ {北京, 上海, 深圳},gender ∈ {male}或者device ∈ {iOS}
  • 范围检索 - 定向条件是一个数值区间(开/闭/半开半闭区间都支持),比如time ∈ [2018-12-01 00:00, 2018-12-20 00:00),age ∈ [18, 25],flow_index ∈ (20, 80]
  • LBS检索 - 基于地理位置(经纬度)的广告定向,比如检索出以某经纬度为圆心、某距离为半径圈定的圆形范围内的定投广告

设计**

cloriSearch在设计与工程实现上参考了多个开源项目与相关论文,包括

  • Indexing Boolean Expressions - 斯坦福大学发表的布尔表达式检索论文,是cloriSearch所采用的核心广告检索算法
  • Lucene - 倒排检索的工程实现
  • Redis - LBS检索参考并引入了redis对geohash的实现
  • brpc - json与protobuf的互相转换
  • cloriSkip - 跳跃表实现

此外,还部分参考了大型互联网公司的广告检索技术实现,包括

实例

  • 1.定义索引结构

在使用cloriSearch之前,需要定义索引结构(具体proto定义参考src/proto/inverted_index.proto),比如要支持城市、性别、年龄、地理位置等四个定向维度的索引结构定义为

{
    "terms": [{
            "name": "city",
            "key_type": "string",
            "index_type": "simple"
        },
        {
            "name": "age",
            "key_type": "int32",
            "index_type": "interval"
        },
        {
            "name": "gender",
            "key_type": "string",
            "index_type": "simple"
        },
        {
            "name": "location",
            "key_type": "double",
            "index_type": "geo"
        }
    ]
}

可以根据业务需求随意增加定向维度。

  • 2.写入倒排数据

cloriSearch目前只支持析取范式格式的倒排写入(具体proto定义参考src/proto/inverted_index.proto),比如一条docid=1,定向北上广深、年龄在[18, 25]之间的女性用户投放的广告倒排描述为

// docid=1,定向北上广深、年龄在[18, 25]之间的女性用户
{
    "mode": "stanard",
    "docid": 1,
    "disjunctions": [{
        "conjunctions": [{
            "name": "city",
            "value": {
                "sval": ["beijing", "shanghai", "guangzhou", "shenzhen"]
            }
        }, {
            "name": "age",
            "value": {
                "int32_intvl": [{
                    "left": 18,
                    "right": 25,
                    "flag": 3
                }]
            }
        }, {
            "name": "gendor",
            "value": {
                "sval": ["female"]
            }
        }]
    }]
}

// docid=3, 定投国贸周边的男性用户
{
    "mode": "stanard",
    "docid": 3,
    "disjunctions": [{
        "conjunctions": [{
            "name": "location",
            "value": {
                "geo": {
                    "lon": 116.461805,
                    "lat": 39.909005
                }
            }
        }, {
            "name": "gender",
            "value": {
                "sval": ["male"]
            }
        }]
    }]
}
  1. 检索匹配的广告

比如要检索一位年龄在20岁、位于北京市经纬度坐标(116.400693, 39.907688)的女学生所命中的广告(LBS定向半径1km),其检索式为

Query query;
query["city"] = "beijing";
query["age"] = 20; 
query["gendor"] = "female";
query["is_student"] = true;
query["location"] = GeoRange(116.400693, 39.907688, 1000);

std::vector<int> res = sch->Search(query, 10);
for (auto &p : res) {                                                                                                                 
    std::cout << "docid=" << p << std::endl;
} 

具体代码实现可以参考src/example/tutorial_xxx.cc中的例子

安装

cloriSearch对protobuf有依赖,在安装cloriSearch之前,必须先安装protobuf,之后你可以按照以下方式安装

mkdir build && cd build
cmake ..
make
sudo make install

同时cloriSearch的数据持久化功能默认是关闭的,如果有数据持久化需求,你需要先安装leveldb,然后执行

mkdir build && cd build
cmake .. -DENABLE_PERSIST=1
make
sudo make install

也可以直接拷贝代码到你的项目中并加以改进,以适配你的业务需求。

待完成列表

cloriSearch目前只支持全量索引与倒排检索,正排索引、增量索引、广告Rank与过滤等功能尚在开发中,另外程序性能、对外接口等还有待斟酌,将在后续优化改进。

作者

返回顶部

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.