# Algolia plugin broken: undefined method \`topic\_count'

**URL:** <https://meta.discourse.org/t/algolia-plugin-broken-undefined-method-topic-count/255962>\
**Category:** Bug\
**Tags:** algolia-search\
**Created:** [February 22, 2023, 5:12pm UTC](https://meta.discourse.org/t/algolia-plugin-broken-undefined-method-topic-count/255962 "2023-02-22T17:12:15Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)\
**Post date:** [February 22, 2023, 5:12pm UTC](https://meta.discourse.org/t/algolia-plugin-broken-undefined-method-topic-count/255962/1 "2023-02-22T17:12:15Z")

</div>

`bundle exec rake algolia:reindex` crashes because there is no `tag.topic_count` any more since [this](https://github.com/discourse/discourse/commit/f122f24b35a8116e47649ae139910d44e3d7488e) commit.

```plaintext
Clearing users from Algolia
Pushing users to Algolia
..
Successfully pushed 530 users to Algolia
Clearing tags from Algolia
Pushing tags to Algolia
rake aborted!
NoMethodError: undefined method `topic_count' for #<Tag id: 1, name: "installation", created_at: "2021-12-09 11:10:14.145911000 +0000", updated_at: "2021-12-09 11:10:14.145911000 +0000", pm_topic_count: 0, target_tag_id: nil, description: nil, public_topic_count: 3, staff_topic_count: 3>
Did you mean? pm_topic_count
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/activemodel-7.0.4.1/lib/active_model/attribute_methods.rb:458:in `method_missing'
/var/www/discourse/plugins/discourse-algolia/lib/discourse_algolia/tag_indexer.rb:18:in `should_index?'
/var/www/discourse/plugins/discourse-algolia/lib/discourse_algolia/indexer.rb:22:in `block in process!'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4.1/lib/active_record/relation/batches.rb:71:in `each'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4.1/lib/active_record/relation/batches.rb:71:in `block in find_each'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4.1/lib/active_record/relation/batches.rb:138:in `block in find_in_batches

```

Manually changing it to staff\_topic\_count fixes stuff but maybe there are side effects to this?

```ruby
--- a/lib/discourse_algolia/tag_indexer.rb
+++ b/lib/discourse_algolia/tag_indexer.rb
@@ -15,10 +15,10 @@ class DiscourseAlgolia::TagIndexer < DiscourseAlgolia::Indexer
   end
 
   def should_index?(tag)
- @guardian.can_see?(tag) && tag.topic_count > 0
+ @guardian.can_see?(tag) && tag&.staff_topic_count > 0
   end
 
   def to_object(tag)
- { objectID: tag.id, url: tag.url, name: tag.name, topic_count: tag.topic_count }
+ { objectID: tag.id, url: tag.url, name: tag.name, topic_count: tag.staff_topic_count }
   end
 end

```

---

_[View the full topic](https://meta.discourse.org/t/algolia-plugin-broken-undefined-method-topic-count/255962)._
