texticle/texticle — Issue #6: search/group/count fail
Author: benhamill
Created: 2012-03-04 04:50:42+00:00
State: open

You can do `Post.group(:author).count` and get back, a hash of counts. You can do `Post.search('ruby').count` and get back the number of posts to do with ruby. But if, wanting the number of posts to do with ruby that each author wrote, you do `Post.group(:author).search('ruby').count` you get an exception like:

```
ActiveRecord::StatementInvalid: PGError: ERROR: column "rank0.4446982473864476" does not exist
LINE 1: ...'english', 'foo'::text)) GROUP BY author ORDER BY "rank0.792...
```

It has something to do with the way that `AR::Base.count` rewrites the `SELECT` portion of a grouped relation. It adds all this counting stuff to it, but doesn't respect previous `select` calls (where Texticle defines rank). It also doesn't remove the `ORDER` clause, which is where the reference to the rank is.