PostgreSQL10.0preview功能增強-JSON內容全文檢索

德哥發表於2017-03-14

標籤

PostgreSQL , 10.0 , jsonb , json , 全文檢索


背景

PostgreSQL 10.0 支援JSON內容的全文檢索了。

同樣支援ts rank和phrase 索引哦。

ts rank, phrase請參考

《從難纏的模糊查詢聊開 – PostgreSQL獨門絕招之一 GIN , GiST , SP-GiST , RUM 索引原理與技術背景》

Hi all  

I would like to propose patch with a set of new small functions for fts in  
case of  
jsonb data type:  

* to_tsvector(config, jsonb) - make a tsvector from all string values and  
  elements of jsonb object. To prevent the situation, when tsquery can find  
  a  
  phrase consisting of lexemes from two different values/elements, this  
  function will add an increment to position of each lexeme from every new  
  value/element.  

* ts_headline(config, jsonb, tsquery, options) - generate a headline  
directly  
  from jsonb object  

Here are the examples how they work:  


=# select to_tsvector(`{"a": "aaa bbb", "b": ["ccc ddd"], "c": {"d": "eee  
fff"}}`::jsonb);  
                   to_tsvector  
-------------------------------------------------  
 `aaa`:1 `bbb`:2 `ccc`:4 `ddd`:5 `eee`:7 `fff`:8  
(1 row)  


=# select ts_headline(`english`, `{"a": "aaa bbb", "b": {"c": "ccc  
ddd"}}`::jsonb, tsquery(`bbb & ddd & hhh`), `StartSel = <, StopSel = >`);  
     ts_headline  
----------------------  
 aaa <bbb> ccc <ddd>  
(1 row)  


Any comments or suggestions?  

這個patch的討論,詳見郵件組,本文末尾URL。

PostgreSQL社群的作風非常嚴謹,一個patch可能在郵件組中討論幾個月甚至幾年,根據大家的意見反覆的修正,patch合併到master已經非常成熟,所以PostgreSQL的穩定性也是遠近聞名的。

參考

https://commitfest.postgresql.org/13/1054/

https://www.postgresql.org/message-id/flat/CA+q6zcWm_1Ygg5QOq0gYbnB_=zq7G51uexQt3QEgDJa0qQnPKw@mail.gmail.com#CA+q6zcWm_1Ygg5QOq0gYbnB_=zq7G51uexQt3QEgDJa0qQnPKw@mail.gmail.com


相關文章