cloriSearch是一套检索引擎内核,致力于解决常规业务开发中的策略检索与在线广告匹配问题,为中小互联网公司商业变现提供一套开源的广告检索技术解决方案。
除了广告检索以外,cloriSearch也可以作为规则引擎,应用于基于内容的策略发布/订阅系统中(content-based publish/ subscribe systems,即根据输入参数调度执行相应的策略),比如一般业务系统中的ABtest、调度引擎、策略匹配等模块。
cloriSearch目前支持简单倒排检索、范围检索(或者叫区间检索)、LBS检索等三种检索方式(基本能cover除搜索广告之外的其他广告定向条件),这三类检索方式的具体内涵是指
cloriSearch在设计与工程实现上参考了多个开源项目与相关论文,包括
此外,还部分参考了大型互联网公司的广告检索技术实现,包括
在使用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"
}
]
}
可以根据业务需求随意增加定向维度。
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"]
}
}]
}]
}
比如要检索一位年龄在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与过滤等功能尚在开发中,另外程序性能、对外接口等还有待斟酌,将在后续优化改进。