Use Tanker and Searchify to search for a Post's User

155 views Asked by At

As stated in the title, I'm looking for the tankit index method in my model that allows for indexing for a Post's User. In my model I have:

    tankit 'idx' do 
      indexes :title
      indexes :content
      indexes :post_loc
      indexes :user_id   
    end

However, this only allows for searching the user's id. Which is not what I want. All users have a username and I'd like to be able to search by that to display all of the reports by that user. I would like to do something like indexes :(User.find(user_id).username) or something along that line but that does not work.

1

There are 1 answers

0
koosa On

Assuming you have an association named 'user', you need to add this kind of method to index values of associations:

tankit 'idx' do 
  indexes :title
  indexes :content
  indexes :post_loc
  indexes :username do 
     user.username
  end
end

You can even map multiple values for one to many associations:

indexes :userlocations
    user.locations.map {|l| l.cityname }
end