Blame view

offline_tasks/doc/COMPLETE_INDEX_LIST.md 7.41 KB
5ab1c29c   tangwang   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
  # 完整索引清单
  
  ## 📋 所有可用的推荐索引
  
  ### 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: 基于平台**
  ```python
  key = f"interest:hot:platform:{user_platform}"
  # 示例:interest:hot:platform:pc
  ```
  
  **方案B: 基于分类偏好**
  ```python
  key = f"interest:hot:category_level2:{user_favorite_category}"
  # 示例:interest:hot:category_level2:200
  ```
  
  **方案C: 基于平台+分类**
  ```python
  key = f"interest:hot:platform_category2:{user_platform}_{category_id}"
  # 示例:interest:hot:platform_category2:pc_200
  ```
  
  ### 场景2: 详情页相关推荐
  
  **方案A: 行为相似**
  ```python
  key = f"i2i:swing:{current_item_id}"
  # 示例:i2i:swing:12345
  ```
  
  **方案B: 内容相似**
  ```python
  key = f"i2i:content_hybrid:{current_item_id}"
  # 示例:i2i:content_hybrid:12345
  ```
  
  **方案C: 融合推荐**
  ```python
  behavior_similar = redis.get(f"i2i:swing:{item_id}")
  content_similar = redis.get(f"i2i:content_hybrid:{item_id}")
  # 融合两种结果
  ```
  
  ### 场景3: 分类页推荐
  
  **方案A: 该分类热门**
  ```python
  key = f"interest:hot:category_level2:{category_id}"
  # 示例:interest:hot:category_level2:200
  ```
  
  **方案B: 该分类新品**
  ```python
  key = f"interest:new:category_level2:{category_id}"
  # 示例:interest:new:category_level2:200
  ```
  
  **方案C: 该分类+平台**
  ```python
  key = f"interest:hot:platform_category2:{platform}_{category_id}"
  # 示例:interest:hot:platform_category2:pc_200
  ```
  
  ### 场景4: 供应商店铺页
  
  **方案A: 供应商热门商品**
  ```python
  key = f"interest:hot:supplier:{supplier_id}"
  # 示例:interest:hot:supplier:10001
  ```
  
  **方案B: 供应商新品**
  ```python
  key = f"interest:new:supplier:{supplier_id}"
  # 示例:interest:new:supplier:10001
  ```
  
  ### 场景5: 搜索结果页推荐
  
  **方案A: 全局热门**
  ```python
  key = "interest:global:platform:pc"
  ```
  
  **方案B: 分类相关**
  ```python
  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示例
  
  ```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命令行示例
  
  ```bash
  # 查询商品相似度
  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"
  ```
  
  ---
  
  ## 📝 注意事项
  
  1. **索引命名规范**:严格遵循 `type:subtype:dimension:value` 格式
  2. **值的格式**`item_id1:score1,item_id2:score2,...`
  3. **过期时间**:建议设置7天过期
  4. **更新频率**:建议每天更新一次
  5. **查询优先级**
     - 优先使用细粒度索引(如四级分类)
     - 粗粒度索引作为后备(如一级分类)
     - 融合多个索引结果
  
  ---
  
  **版本**: v1.1  
  **生成日期**: 2025-10-16  
  **索引总数**: 约10000-50000条