zombodb 得分以及高光
得分以及高光在搜索引擎中有很重要的作用
得分zdb.score
- 使用方法
zdb.score(tid)
- 参考示例
SELECT zdb.score(ctid), *
FROM products
WHERE products ==> 'sports box'
ORDER BY score desc;
结果:
score | id | name | keywords | short_summary | long_description | price | inventory_count | discontinued | availability_date
----------+----+----------+--------------------------------------+--------------------------------+-------------------------------------------------------------------------------------+-------+-----------------+--------------+-------------------
1.06561 | 4 | Box | {wooden,box,"negative space",square} | Just an empty box made of wood | A wooden container that will eventually rot away. Put stuff it in (but not a cat). | 17000 | 0 | t | 2015-07-01
0.723777 | 2 | Baseball | {baseball,sports,round} | It's a baseball | Throw it at a person with a big wooden stick and hope they don't hit it | 1249 | 2 | f | 2015-08-21
(2 rows)
- 说明
对于进行使用得分进行需要使用dsl 的dsl.min_score()
高光highlight 函数
- 方法签名
zdb.highlight(tid, fieldname [, json_highlight_descriptor]) RETURNS text[]
- 使用
SELECT zdb.score(ctid), zdb.highlight(ctid, 'long_description'), long_description
FROM products
WHERE products ==> 'wooden person'
ORDER BY score desc;
结果:
score | highlight | long_description
----------+--------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------
0.914156 | {"Throw it at a <em>person</em> with a big <em>wooden</em> stick and hope they don't hit it"} | Throw it at a person with a big wooden stick and hope they don't hit it
0.243605 | {"A <em>wooden</em> container that will eventually rot away. Put stuff it in (but not a cat)."} | A wooden container that will eventually rot away. Put stuff it in (but not a cat).
(2 rows)
自定义高光函数编写
主要是基于zdb 提供的函数
- 官方提供的一个高光函数
CREATE TYPE esqdsl_highlight_type AS ENUM ('unified', 'plain', 'fvh');
CREATE TYPE esqdsl_fragmenter_type AS ENUM ('simple', 'span');
CREATE TYPE esqdsl_encoder_type AS ENUM ('default', 'html');
CREATE TYPE esqdsl_boundary_scanner_type AS ENUM ('chars', 'sentence', 'word');
FUNCTION highlight(
type zdb.esqdsl_highlight_type DEFAULT NULL,
require_field_match boolean DEFAULT false,
number_of_fragments int DEFAULT NULL,
highlight_query zdbquery DEFAULT NULL,
pre_tags text[] DEFAULT NULL,
post_tags text[] DEFAULT NULL,
tags_schema text DEFAULT NULL,
no_match_size int DEFAULT NULL,
fragmenter zdb.esqdsl_fragmenter_type DEFAULT NULL,
fragment_size int DEFAULT NULL,
fragment_offset int DEFAULT NULL,
force_source boolean DEFAULT true,
encoder zdb.esqdsl_encoder_type DEFAULT NULL,
boundary_scanner_locale text DEFAULT NULL,
boundary_scan_max int DEFAULT NULL,
boundary_chars text DEFAULT NULL,
phrase_limit int DEFAULT NULL,
matched_fields boolean DEFAULT NULL,
"order" text DEFAULT NULL)
RETURNS json
- 使用
SELECT zdb.score(ctid),
zdb.highlight(ctid,
'long_description',
zdb.highlight(pre_tags=>'{<b>}', post_tags=>'{</b>}')
),
long_description
FROM products
WHERE products ==> 'wooden person'
ORDER BY score desc;
score | highlight | long_description
----------+------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------
0.914156 | {"Throw it at a <b>person</b> with a big <b>wooden</b> stick and hope they don't hit it"} | Throw it at a person with a big wooden stick and hope they don't hit it
0.243605 | {"A <b>wooden</b> container that will eventually rot away. Put stuff it in (but not a cat)."} | A wooden container that will eventually rot away. Put stuff it in (but not a cat).
(2 rows)
参考资料
https://github.com/zombodb/zombodb/blob/master/SCORING-HIGHLIGHTING.md
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-highlighting.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
2017-04-02 web 优化原则