Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT *
- FROM
- (
- SELECT *, keyword.name AS keyword_name, brand.name AS brand_name, product.name AS product_name, product.id AS product_id,
- setweight(to_tsvector(product.name), 'A') || setweight(to_tsvector(product.full_name), 'B') as document
- FROM product
- LEFT JOIN onsale ON product.id=onsale.id
- LEFT JOIN image ON product.id=image.product
- JOIN keyword ON product.keyword=keyword.id
- JOIN brand ON product.brand=brand.id
- WHERE (keyword.name=:keyword1 OR keyword.name=:keyword2)
- 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))
- AND (brand.name=:brand1 OR brand.name=:brand2)
- AND (onsale.sale_price IS NOT NULL)
- AND (product.nr_ratings>0 AND ROUND(product.rating/product.nr_ratings)>=?)
- ) p_search
- WHERE p_search.document @@ plainto_tsquery(?)
- ORDER BY ts_rank(p_search.document, plainto_tsquery(?)) DESC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement