Created
May 11, 2012 14:16
-
-
Save fabiokr/2659947 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE VIEW searches AS ((((((((((((((((((((((((( | |
(SELECT brands.name AS term, | |
brands.id AS searchable_id, | |
'Brand'::character varying AS searchable_type | |
FROM brands | |
UNION SELECT staffs.name AS term, | |
staffs.id AS searchable_id, | |
'Staff'::character varying AS searchable_type | |
FROM staffs) | |
UNION | |
SELECT staffs.email AS term, | |
staffs.id AS searchable_id, | |
'Staff'::character varying AS searchable_type | |
FROM staffs) | |
UNION | |
SELECT customers.first_name AS term, | |
customers.id AS searchable_id, | |
'Customer'::character varying AS searchable_type | |
FROM customers) | |
UNION | |
SELECT customers.last_name AS term, | |
customers.id AS searchable_id, | |
'Customer'::character varying AS searchable_type | |
FROM customers) | |
UNION | |
SELECT customers.organization AS term, | |
customers.id AS searchable_id, | |
'Customer'::character varying AS searchable_type | |
FROM customers) | |
UNION | |
SELECT customers.title AS term, | |
customers.id AS searchable_id, | |
'Customer'::character varying AS searchable_type | |
FROM customers) | |
UNION | |
SELECT addresses.address AS term, | |
customers.id AS searchable_id, | |
'Customer'::character varying AS searchable_type | |
FROM customers | |
JOIN addresses ON customers.id = addresses.addressable_id | |
AND addresses.addressable_type::text = 'Customer'::text) | |
UNION | |
SELECT addresses.city AS term, | |
customers.id AS searchable_id, | |
'Customer'::character varying AS searchable_type | |
FROM customers | |
JOIN addresses ON customers.id = addresses.addressable_id | |
AND addresses.addressable_type::text = 'Customer'::text) | |
UNION | |
SELECT addresses.state AS term, | |
customers.id AS searchable_id, | |
'Customer'::character varying AS searchable_type | |
FROM customers | |
JOIN addresses ON customers.id = addresses.addressable_id | |
AND addresses.addressable_type::text = 'Customer'::text) | |
UNION | |
SELECT addresses.zip AS term, | |
customers.id AS searchable_id, | |
'Customer'::character varying AS searchable_type | |
FROM customers | |
JOIN addresses ON customers.id = addresses.addressable_id | |
AND addresses.addressable_type::text = 'Customer'::text) | |
UNION | |
SELECT addresses.phone AS term, | |
customers.id AS searchable_id, | |
'Customer'::character varying AS searchable_type | |
FROM customers | |
JOIN addresses ON customers.id = addresses.addressable_id | |
AND addresses.addressable_type::text = 'Customer'::text) | |
UNION | |
SELECT addresses.fax AS term, | |
customers.id AS searchable_id, | |
'Customer'::character varying AS searchable_type | |
FROM customers | |
JOIN addresses ON customers.id = addresses.addressable_id | |
AND addresses.addressable_type::text = 'Customer'::text) | |
UNION | |
SELECT contacts.first_name AS term, | |
contacts.id AS searchable_id, | |
'Contact'::character varying AS searchable_type | |
FROM contacts) | |
UNION | |
SELECT contacts.last_name AS term, | |
contacts.id AS searchable_id, | |
'Contact'::character varying AS searchable_type | |
FROM contacts) | |
UNION | |
SELECT contacts.organization AS term, | |
contacts.id AS searchable_id, | |
'Contact'::character varying AS searchable_type | |
FROM contacts) | |
UNION | |
SELECT contacts.title AS term, | |
contacts.id AS searchable_id, | |
'Contact'::character varying AS searchable_type | |
FROM contacts) | |
UNION | |
SELECT addresses.address AS term, | |
contacts.id AS searchable_id, | |
'Contact'::character varying AS searchable_type | |
FROM contacts | |
JOIN addresses ON contacts.id = addresses.addressable_id | |
AND addresses.addressable_type::text = 'Contact'::text) | |
UNION | |
SELECT addresses.city AS term, | |
contacts.id AS searchable_id, | |
'Contact'::character varying AS searchable_type | |
FROM contacts | |
JOIN addresses ON contacts.id = addresses.addressable_id | |
AND addresses.addressable_type::text = 'Contact'::text) | |
UNION | |
SELECT addresses.state AS term, | |
contacts.id AS searchable_id, | |
'Contact'::character varying AS searchable_type | |
FROM contacts | |
JOIN addresses ON contacts.id = addresses.addressable_id | |
AND addresses.addressable_type::text = 'Contact'::text) | |
UNION | |
SELECT addresses.zip AS term, | |
contacts.id AS searchable_id, | |
'Contact'::character varying AS searchable_type | |
FROM contacts | |
JOIN addresses ON contacts.id = addresses.addressable_id | |
AND addresses.addressable_type::text = 'Contact'::text) | |
UNION | |
SELECT addresses.phone AS term, | |
contacts.id AS searchable_id, | |
'Contact'::character varying AS searchable_type | |
FROM contacts | |
JOIN addresses ON contacts.id = addresses.addressable_id | |
AND addresses.addressable_type::text = 'Contact'::text) | |
UNION | |
SELECT addresses.fax AS term, | |
contacts.id AS searchable_id, | |
'Contact'::character varying AS searchable_type | |
FROM contacts | |
JOIN addresses ON contacts.id = addresses.addressable_id | |
AND addresses.addressable_type::text = 'Contact'::text) | |
UNION | |
SELECT hardwares.name AS term, | |
hardwares.id AS searchable_id, | |
'Hardware'::character varying AS searchable_type | |
FROM hardwares) | |
UNION | |
SELECT hardwares.identifier AS term, | |
hardwares.id AS searchable_id, | |
'Hardware'::character varying AS searchable_type | |
FROM hardwares) | |
UNION | |
SELECT hardware_groups.name AS term, | |
hardware_groups.id AS searchable_id, | |
'HardwareGroup'::character varying AS searchable_type | |
FROM hardware_groups) | |
UNION | |
SELECT services.name AS term, | |
services.id AS searchable_id, | |
'Service'::character varying AS searchable_type | |
FROM services) | |
UNION | |
SELECT services.username AS term, | |
services.id AS searchable_id, | |
'Service'::character varying AS searchable_type | |
FROM services; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment