搜索体验优化:ABP vNext 的查询改写(Query Rewrite)与同义词治理

🔎 搜索体验优化:ABP vNext 的查询改写(Query Rewrite)与同义词治理



1. 背景与问题界定 🧩

痛点:零结果、弱相关、错拼(键邻/近音/形近)、品牌/部门别名不一致(“华为/HUAWEI/华爲”)、多叫法(“摄像头/相机/camera”)。
目标(示例):ZRR 下降 ≥ 30%(📉)、首条点击率 +10%(📈)、二次搜索率 -15%(📉)(以 AB 实验为准)。
约束:多租户隔离、可灰度、可回滚、可观测、可复现。


2. 总体架构(ABP 模块化 + 多租户 + 分层) 🏗️

  • 模块Search.QueryRewriteModuleDomain/Application/HttpApi/Infrastructure)。

  • 多租户ICurrentTenant 贯穿数据、缓存、指标;缓存键必须包含 TenantId;后台跨租户操作用 ICurrentTenant.Change(...)

  • 存储分层

    • 检索面:Elasticsearch(中文分词 + 同义词 + DSL)
    • 规则面:PostgreSQL(词典/规则/行为聚合)
    • 热数据:Redis(24h CTR / Dwell Top-K;ABP 官方 Redis 模块支持批量 SetManyAsync/GetManyAsync
  • 流程:改写(检索前)→ ES 查询 → 轻量行为重排(可选 RRF 融合多路召回)。

🗺️ 架构总览(Mermaid)

🛡️ 治理后台
ABP 应用层
词典/规则
在线行为
🧭 Rewrite Admin UI
🛠️ QueryRewritePipeline
Normalize→Spell→Synonym→Alias→Rule→Safety
🌐 HttpApi: /rewrite
🔎 ES Query
multi_match + tie_breaker
Elasticsearch
🎯 轻量重排
(CTR/Dwell)
🧑‍💻 用户/前端
✅ 最终结果
🗄️ PostgreSQL
⚡ Redis

3. 数据模型(PostgreSQL,含索引) 🧬

关键修正:spell_lexicon 主键改为 (tenant_id, term),避免多租户冲突;为热路径增加索引。

create table synonym_set (
  tenant_id uuid not null,
  group_id  uuid not null,
  terms     text[] not null,
  direction smallint not null, -- 0: 双向, 1: 单向 from→to
  boost     double precision not null default 1.0,
  version   int not null default 1,
  primary key (tenant_id, group_id)
);

create table alias (
  tenant_id uuid not null,
  entity_type text not null,    -- brand/department/sku
  key text not null,
  aliases text[] not null,
  boost double precision not null default 0.8,
  primary key (tenant_id, entity_type, key)
);

create table spell_lexicon (
  tenant_id uuid not null,
  term text not null,
  freq bigint not null default 0,
  flags int not null default 0,
  primary key (tenant_id, term)
);

create table rewrite_rule (
  tenant_id uuid not null,
  id uuid not null,
  cond_json jsonb not null,     -- {"category":"phone"}
  action_json jsonb not null,   -- {"extend":["phone case","保护壳"]}
  weight double precision not null default 1.0,
  active_from timestamptz,
  active_to   timestamptz,
  primary key (tenant_id, id)
);

create table click_log (
  tenant_id uuid not null,
  query text not null,
  doc_id text not null,
  clicked boolean not null,
  dwell_ms int,
  ts timestamptz not null default now()
);

-- 索引建议
create index idx_syn_terms on synonym_set using gin (terms);
create index idx_alias_key on alias(
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Kookoos

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值