Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

See #467, add option to order by number of matching tags. #469

Merged
merged 1 commit into from
Jan 27, 2014

Conversation

Burkazoid
Copy link
Contributor

See issue #467.

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

Option

:order_by_matching_tag_count => true

Option

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

Example usage:

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.:

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. Tests passing for me locally.

@seuros
Copy link
Collaborator

seuros commented Jan 25, 2014

Can you rebase and force push so i can merge it ?

- Adds :order_by_matching_tag_count to tagged_with method
@Burkazoid
Copy link
Contributor Author

@seuros Done, I think? Let me know if you need me to do anything else :)

seuros added a commit that referenced this pull request Jan 27, 2014
Featured added: Option to order by number of matching tags.
@seuros seuros merged commit 9cf3dd7 into mbleigh:master Jan 27, 2014
tekniklr pushed a commit to tekniklr/acts-as-taggable-on that referenced this pull request Mar 19, 2021
Featured added: Option to order by number of matching tags.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants