Zombo主要函数Scoring 和Highlighting

2020-01-14  本文已影响0人  zy_now

这两个函数可以返回查询文本的相似度和匹配的结果,使用场景非常足,先把文档翻译出来放在这里,以后再慢慢补充使用过程中的经验和玩法

Scoring

tutorial=# 
       SELECT zdb.score(ctid), * 
       FROM products 
      WHERE products ==> 'sports box' 
 ORDER BY score desc;

 score   | id |   name   |               keywords               |         short_summary          |                                  long_description                                   | price | 
----------+----+----------+--------------------------------------+--------------------------------+-------------------------------------------------------------------------------------+-------+-
  1.00079 |  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.698622 |  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 | 

ctid 是pg系统里面的隐藏唯一id列,作为zdb.score的参数
zdb.score()不可以用于where但可以用于order by
实现where功能需要使用dsl.min_score()

SELECT * FROM (
  SELECT zdb.score(ctid), *
  FROM products WHERE products ==> 'sports box' ) 
  x  WHERE x.score > 1.0;
# SELECT zdb.score(ctid), * FROM products 
#  WHERE products ==> 'sports box' AND zdb.score(ctid) > 1.0;
ERROR:  zdb.score() can only be used as a target entry or as a sort

Highlighting

tutorial=# 
     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.882384 | {"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.224636 | {"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).

上一篇 下一篇

猜你喜欢

热点阅读