Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. SELECT *
  2. FROM
  3. (
  4. SELECT *, keyword.name AS keyword_name, brand.name AS brand_name, product.name AS product_name, product.id AS product_id,
  5. setweight(to_tsvector(product.name), 'A') || setweight(to_tsvector(product.full_name), 'B') as document
  6. FROM product
  7. LEFT JOIN onsale ON product.id=onsale.id
  8. LEFT JOIN image ON product.id=image.product
  9. JOIN keyword ON product.keyword=keyword.id
  10. JOIN brand ON product.brand=brand.id
  11. WHERE (keyword.name=:keyword1 OR keyword.name=:keyword2)
  12. AND ((onsale.sale_price>=:min_price AND onsale.sale_price<=:max_price) OR (onsale.sale_price IS NULL AND product.price>=:min_price AND product.price<=:max_price))
  13. AND (brand.name=:brand1 OR brand.name=:brand2)
  14. AND (onsale.sale_price IS NOT NULL)
  15. AND (product.nr_ratings>0 AND ROUND(product.rating/product.nr_ratings)>=?)
  16. ) p_search
  17. WHERE p_search.document @@ plainto_tsquery(?)
  18. ORDER BY ts_rank(p_search.document, plainto_tsquery(?)) DESC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement