mbleigh/acts-as-taggable-on — pull request #469 by jamesburke-examtime (2014-01-24 12:46:08+00:00)
Title: See #467, add option to order by number of matching tags.

Add option to order by number of matching tags when using ```tagged_with``` with the ```:any => true``` option.

### Option

```ruby
:order_by_matching_tag_count => true
```

### Option

```ruby
TaggableModel.tagged_with(["a", "b", "c"], :any => true, :order_by_matching_tag_count => true)
```

### Example usage:
```ruby
bob = TaggableModel.create(:name => "Bob", :tag_list => "fitter, happier, more productive")
frank = TaggableModel.create(:name => "Frank", :tag_list => "fitter, comfortable, eating well, sleeping well")
steve = TaggableModel.create(:name => 'Steve', :tag_list => 'fitter, comfortable, more productive, at ease')
earl = TaggableModel.create(:name => 'Earl', :tag_list => 'comfortable, sleeping well, eating well, self-employed')

TaggableModel.tagged_with(["fitter", "comfortable", "eating well", "sleeping well"], :any => true, :order_by_matching_tag_count => true)
# = [frank, earl, steve, bob]
```
Frank matches 4 tags
Earl matches 3 tags
Steve matches 2 tags
Bob matches 1 tag

### Additional ordering:
If additional order conditions are specified using the ```:order``` option, they will be included as secondary orders: e.g.:

```ruby
TaggableModel.tagged_with(["a", "b", "c"], :any => true,
:order_by_matching_tag_count => true,
:order => "taggable_models.name ASC")
```

Will order by tag count (descending) first, then model's name attribute second.

1 spec test included.