Zombo主要函數(shù)Scoring 和Highlighting

這兩個(gè)函數(shù)可以返回查詢文本的相似度和匹配的結(jié)果,使用場(chǎng)景非常足,先把文檔翻譯出來(lái)放在這里,以后再慢慢補(bǔ)充使用過(guò)程中的經(jīng)驗(yàn)和玩法

Scoring

  • 用法 zdb.score(tid) RETURNS real
  • 作用 返回當(dāng)前對(duì)比列的得分
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系統(tǒng)里面的隱藏唯一id列,作為zdb.score的參數(shù)
zdb.score()不可以用于where但可以用于order by
實(shí)現(xiàn)where功能需要使用dsl.min_score()

SELECT * FROM (
  SELECT zdb.score(ctid), *
  FROM products WHERE products ==> 'sports box' ) 
  x  WHERE x.score > 1.0;
  • 錯(cuò)誤示范
# 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

  • 用法zdb.highlight(tid, fieldname [, json_highlight_descriptor]) RETURNS text[]
  • 功能 返回帶標(biāo)注的重點(diǎn)結(jié)果,es的默認(rèn)標(biāo)注結(jié)果,第三個(gè)參數(shù)可以自定義highligh標(biāo)注的方法
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).

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • This chapter covers the basic setup for using this librar...
    ngugg閱讀 1,157評(píng)論 0 1
  • 一. Java基礎(chǔ)部分.................................................
    wy_sure閱讀 3,988評(píng)論 0 11
  • 50個(gè)常用的sql語(yǔ)句Student(S#,Sname,Sage,Ssex) 學(xué)生表Course(C#,Cname...
    哈哈海閱讀 1,326評(píng)論 0 7
  • Django 準(zhǔn)備 “虛擬環(huán)境為什么需要虛擬環(huán)境:到目前位置,我們所有的第三方包安裝都是直接通過(guò) pip inst...
    33jubi閱讀 1,390評(píng)論 0 5
  • pyspark.sql模塊 模塊上下文 Spark SQL和DataFrames的重要類: pyspark.sql...
    mpro閱讀 9,888評(píng)論 0 13

友情鏈接更多精彩內(nèi)容