Skip to content

Instantly share code, notes, and snippets.

@elight
Created January 26, 2012 20:51
Show Gist options
  • Save elight/1685036 to your computer and use it in GitHub Desktop.
Save elight/1685036 to your computer and use it in GitHub Desktop.
1.9.2p290 :015 > ap Team.search("Manchester").map(&:name)
Team Load (3.5ms) SELECT "teams".*, ts_rank(to_tsvector('english', "teams"."name"::text), to_tsquery('english', 'Manchester'::text)) + ts_rank(to_tsvector('english', "teams"."description"::text), to_tsquery('english', 'Manchester'::text)) + ts_rank(to_tsvector('english', "teams"."icon"::text), to_tsquery('english', 'Manchester'::text)) + ts_rank(to_tsvector('english', "teams"."url"::text), to_tsquery('english', 'Manchester'::text)) + ts_rank(to_tsvector('english', "teams"."stadium"::text), to_tsquery('english', 'Manchester'::text)) AS "rank0.9075883588015157" FROM "teams" WHERE (to_tsvector('english', "teams"."name"::text) @@ to_tsquery('english', 'Manchester'::text) OR to_tsvector('english', "teams"."description"::text) @@ to_tsquery('english', 'Manchester'::text) OR to_tsvector('english', "teams"."icon"::text) @@ to_tsquery('english', 'Manchester'::text) OR to_tsvector('english', "teams"."url"::text) @@ to_tsquery('english', 'Manchester'::text) OR to_tsvector('english', "teams"."stadium"::text) @@ to_tsquery('english', 'Manchester'::text)) ORDER BY teams.name, "rank0.9075883588015157" DESC
[
[0] "Manchester City",
[1] "Manchester United",
[2] "X-Man City",
[3] "X-Man Utd"
]
=> ["Manchester City", "Manchester United", "X-Man City", "X-Man Utd"]
1.9.2p290 :016 > ap Team.search("Manchester City").map(&:name)
Team Load (3.4ms) SELECT "teams".*, ts_rank(to_tsvector('english', "teams"."name"::text), to_tsquery('english', 'Manchester\ City'::text)) + ts_rank(to_tsvector('english', "teams"."description"::text), to_tsquery('english', 'Manchester\ City'::text)) + ts_rank(to_tsvector('english', "teams"."icon"::text), to_tsquery('english', 'Manchester\ City'::text)) + ts_rank(to_tsvector('english', "teams"."url"::text), to_tsquery('english', 'Manchester\ City'::text)) + ts_rank(to_tsvector('english', "teams"."stadium"::text), to_tsquery('english', 'Manchester\ City'::text)) AS "rank0.0636798235894509" FROM "teams" WHERE (to_tsvector('english', "teams"."name"::text) @@ to_tsquery('english', 'Manchester\ City'::text) OR to_tsvector('english', "teams"."description"::text) @@ to_tsquery('english', 'Manchester\ City'::text) OR to_tsvector('english', "teams"."icon"::text) @@ to_tsquery('english', 'Manchester\ City'::text) OR to_tsvector('english', "teams"."url"::text) @@ to_tsquery('english', 'Manchester\ City'::text) OR to_tsvector('english', "teams"."stadium"::text) @@ to_tsquery('english', 'Manchester\ City'::text)) ORDER BY teams.name, "rank0.0636798235894509" DESC
[
[0] "Manchester City",
[1] "X-Man City"
]
=> ["Manchester City", "X-Man City"]
1.9.2p290 :017 > ap Team.search("Manchester United").map(&:name)
Team Load (3.4ms) SELECT "teams".*, ts_rank(to_tsvector('english', "teams"."name"::text), to_tsquery('english', 'Manchester\ United'::text)) + ts_rank(to_tsvector('english', "teams"."description"::text), to_tsquery('english', 'Manchester\ United'::text)) + ts_rank(to_tsvector('english', "teams"."icon"::text), to_tsquery('english', 'Manchester\ United'::text)) + ts_rank(to_tsvector('english', "teams"."url"::text), to_tsquery('english', 'Manchester\ United'::text)) + ts_rank(to_tsvector('english', "teams"."stadium"::text), to_tsquery('english', 'Manchester\ United'::text)) AS "rank0.7061382890469123" FROM "teams" WHERE (to_tsvector('english', "teams"."name"::text) @@ to_tsquery('english', 'Manchester\ United'::text) OR to_tsvector('english', "teams"."description"::text) @@ to_tsquery('english', 'Manchester\ United'::text) OR to_tsvector('english', "teams"."icon"::text) @@ to_tsquery('english', 'Manchester\ United'::text) OR to_tsvector('english', "teams"."url"::text) @@ to_tsquery('english', 'Manchester\ United'::text) OR to_tsvector('english', "teams"."stadium"::text) @@ to_tsquery('english', 'Manchester\ United'::text)) ORDER BY teams.name, "rank0.7061382890469123" DESC
[
[0] "Manchester United",
[1] "X-Man Utd"
]
=> ["Manchester United", "X-Man Utd"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment