完整索引列表.md
7.41 KB
完整索引清单
📋 所有可用的推荐索引
1. i2i 相似度索引
1.1 行为相似索引(3种)
Swing算法:
i2i:swing:{item_id}
示例:i2i:swing:12345
Session Word2Vec:
i2i:session_w2v:{item_id}
示例:i2i:session_w2v:12345
DeepWalk:
i2i:deepwalk:{item_id}
示例:i2i:deepwalk:12345
1.2 内容相似索引(3种方法)
混合方法(推荐):
i2i:content_hybrid:{item_id}
示例:i2i:content_hybrid:12345
TF-IDF方法:
i2i:content_tfidf:{item_id}
示例:i2i:content_tfidf:12345
分类方法:
i2i:content_category:{item_id}
示例:i2i:content_category:12345
2. 兴趣点聚合索引
格式:interest:{list_type}:{dimension}:{value}
2.1 列表类型(list_type)
hot- 热门商品cart- 加购商品new- 新品global- 全局(所有数据)
2.2 单维度索引
业务平台(platform)
interest:hot:platform:pc
interest:hot:platform:mobile
interest:cart:platform:pc
interest:new:platform:mobile
interest:global:platform:pc
客户端平台(client_platform)
interest:hot:client_platform:web
interest:hot:client_platform:app
interest:cart:client_platform:web
interest:new:client_platform:app
interest:global:client_platform:web
供应商(supplier)
interest:hot:supplier:10001
interest:hot:supplier:10002
interest:cart:supplier:10001
interest:new:supplier:10002
interest:global:supplier:10001
一级分类(category_level1)
interest:hot:category_level1:100
interest:cart:category_level1:100
interest:new:category_level1:100
interest:global:category_level1:100
二级分类(category_level2)
interest:hot:category_level2:200
interest:cart:category_level2:200
interest:new:category_level2:200
interest:global:category_level2:200
三级分类(category_level3)
interest:hot:category_level3:300
interest:cart:category_level3:300
interest:new:category_level3:300
interest:global:category_level3:300
四级分类(category_level4)
interest:hot:category_level4:400
interest:cart:category_level4:400
interest:new:category_level4:400
interest:global:category_level4:400
2.3 组合维度索引
平台 + 客户端
interest:hot:platform_client:pc_web
interest:hot:platform_client:pc_app
interest:hot:platform_client:mobile_web
interest:hot:platform_client:mobile_app
平台 + 二级分类
interest:hot:platform_category2:pc_200
interest:hot:platform_category2:mobile_200
interest:cart:platform_category2:pc_200
interest:new:platform_category2:mobile_200
平台 + 三级分类
interest:hot:platform_category3:pc_300
interest:hot:platform_category3:mobile_300
interest:cart:platform_category3:pc_300
interest:new:platform_category3:mobile_300
客户端平台 + 二级分类
interest:hot:client_category2:web_200
interest:hot:client_category2:app_200
interest:cart:client_category2:web_200
interest:new:client_category2:app_200
🎯 按业务场景的索引使用
场景1: 首页个性化推荐
方案A: 基于平台
key = f"interest:hot:platform:{user_platform}"
# 示例:interest:hot:platform:pc
方案B: 基于分类偏好
key = f"interest:hot:category_level2:{user_favorite_category}"
# 示例:interest:hot:category_level2:200
方案C: 基于平台+分类
key = f"interest:hot:platform_category2:{user_platform}_{category_id}"
# 示例:interest:hot:platform_category2:pc_200
场景2: 详情页相关推荐
方案A: 行为相似
key = f"i2i:swing:{current_item_id}"
# 示例:i2i:swing:12345
方案B: 内容相似
key = f"i2i:content_hybrid:{current_item_id}"
# 示例:i2i:content_hybrid:12345
方案C: 融合推荐
behavior_similar = redis.get(f"i2i:swing:{item_id}")
content_similar = redis.get(f"i2i:content_hybrid:{item_id}")
# 融合两种结果
场景3: 分类页推荐
方案A: 该分类热门
key = f"interest:hot:category_level2:{category_id}"
# 示例:interest:hot:category_level2:200
方案B: 该分类新品
key = f"interest:new:category_level2:{category_id}"
# 示例:interest:new:category_level2:200
方案C: 该分类+平台
key = f"interest:hot:platform_category2:{platform}_{category_id}"
# 示例:interest:hot:platform_category2:pc_200
场景4: 供应商店铺页
方案A: 供应商热门商品
key = f"interest:hot:supplier:{supplier_id}"
# 示例:interest:hot:supplier:10001
方案B: 供应商新品
key = f"interest:new:supplier:{supplier_id}"
# 示例:interest:new:supplier:10001
场景5: 搜索结果页推荐
方案A: 全局热门
key = "interest:global:platform:pc"
方案B: 分类相关
key = f"interest:global:category_level2:{search_category}"
# 示例:interest:global:category_level2:200
📊 索引数量统计
i2i索引
- 行为相似:3种算法 × 商品数量
- 内容相似:3种方法 × 商品数量
- 总计:6 × 商品数量
兴趣点聚合索引
单维度:
- platform: 2-10个
- client_platform: 2-5个
- supplier: 100-1000个
- category_level1: 10-50个
- category_level2: 50-200个
- category_level3: 200-1000个
- category_level4: 1000-5000个
组合维度:
- platform_client: 4-50个
- platform_category2: 100-2000个
- platform_category3: 400-10000个
- client_category2: 100-1000个
列表类型:每个维度 × 4种类型(hot/cart/new/global)
预估总数:10000-50000条索引
🔍 查询示例代码
Python示例
import redis
# 连接Redis
r = redis.Redis(host='localhost', port=6379, db=0, decode_responses=True)
# 1. 查询商品的相似商品
item_id = "12345"
similar_items = r.get(f"i2i:swing:{item_id}")
if similar_items:
items = similar_items.split(',')
for item in items[:5]: # 取前5个
item_id, score = item.split(':')
print(f"商品ID: {item_id}, 相似度: {score}")
# 2. 查询分类热门商品
category_id = "200"
hot_items = r.get(f"interest:hot:category_level2:{category_id}")
if hot_items:
items = hot_items.split(',')
for item in items[:10]: # 取前10个
item_id, score = item.split(':')
print(f"商品ID: {item_id}, 得分: {score}")
# 3. 查询平台+分类组合
platform = "pc"
category_id = "200"
key = f"interest:hot:platform_category2:{platform}_{category_id}"
items = r.get(key)
Redis命令行示例
# 查询商品相似度
redis-cli GET "i2i:swing:12345"
# 查询分类热门
redis-cli GET "interest:hot:category_level2:200"
# 查询供应商商品
redis-cli GET "interest:hot:supplier:10001"
# 模糊查询所有热门索引
redis-cli KEYS "interest:hot:*"
# 查看某个分类的所有类型
redis-cli KEYS "interest:*:category_level2:200"
📝 注意事项
- 索引命名规范:严格遵循
type:subtype:dimension:value格式 - 值的格式:
item_id1:score1,item_id2:score2,... - 过期时间:建议设置7天过期
- 更新频率:建议每天更新一次
- 查询优先级:
- 优先使用细粒度索引(如四级分类)
- 粗粒度索引作为后备(如一级分类)
- 融合多个索引结果
版本: v1.1
生成日期: 2025-10-16
索引总数: 约10000-50000条