Advertisement
Pandaaaa906

ProdSearch API Improve

May 29th, 2023
1,643
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. SELECT
  2. --  prod.*,
  3.     prod.id,
  4.     prod.brand_name,
  5.     prod.cat_no,
  6.     pkg.packages
  7. FROM t_product prod
  8.  
  9. -- where magic happens
  10. LEFT JOIN LATERAL (
  11.     SELECT
  12.     json_agg(k) packages
  13.     FROM t_product_package k
  14.     WHERE k.brand_name = prod.brand_name
  15.     AND k.cat_no = prod.cat_no
  16. ) pkg
  17. ON True
  18.  
  19. WHERE
  20.     1 = 1
  21.     AND prod.ID IN (
  22.     SELECT ID
  23.     FROM
  24.         t_product tp
  25.     WHERE
  26.         (
  27.             cn_name ILIKE'%' || '阿莫西林' || '%'
  28.             OR en_name ILIKE'%' || '阿莫西林' || '%'
  29.             OR brand_name = '阿莫西林'
  30.             OR cn_synonym ILIKE'%' || '阿莫西林' || '%'
  31.             OR en_synonym ILIKE'%' || '阿莫西林' || '%'
  32.             OR cat_no = '阿莫西林'
  33.             OR cas ='阿莫西林'
  34.             OR mw = '阿莫西林'
  35.             OR mf ='阿莫西林'
  36.         )
  37.         AND is_delete = 1
  38.     )
  39.     AND ( "brand_name" ='cato' )
  40. ORDER BY
  41.     similarity ( cat_no,'阿莫西林' ) DESC NULLS LAST,
  42.     similarity ( cas,'阿莫西林' ) DESC NULLS LAST,
  43.     similarity ( cn_name,'阿莫西林' ) DESC NULLS LAST,
  44.     similarity ( en_name,'阿莫西林' ) DESC NULLS LAST,
  45.     similarity ( cn_synonym,'阿莫西林' ) DESC NULLS LAST,
  46.     similarity ( en_synonym,'阿莫西林' ) DESC NULLS LAST,
  47.     similarity ( mf,'阿莫西林' ) DESC NULLS LAST,
  48.     similarity ( mw,'阿莫西林' ) DESC NULLS LAST
  49.     LIMIT 50 OFFSET 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement