Custom Docid
bhellman1 opened this issue · comments
Any tanker forks that allow for creating a custom docid?
A custom doc id on the index Tank side?
Could you explain your question a little bit more?
Currently the docid is being assigned by tanker as follows:
Line 311 @ https://github.com/kidpollo/tanker/blob/master/lib/tanker.rb
create a unique index based on the model name and unique id
def it_doc_id
self.class.name + ' ' + self.id.to_s
end
I would like the docID to be comment.post.id so that every time there is a new comment the IndexTank record for that post gets updated with a string of all the posts comments. Currently every comment gets it's own IndexTank docid 'Comment 12' etc which I want to avoid.
Thoughts?
Hey @bhellman1
The reason tanker does doc ids that way is because we want to be able to use the same index for many of the models. The abstraction does the least it can do to correctly filter and intance new model objects. A contributor actually added the it_doc_id method because he wanted something similar though I never really understood why :P At the end the really did not need to change anything
What is the reason for avoiding Comment 12 may I ask?
I have the following models:
Post
Comment
I would like the search results to show Posts with a snippet & not a long list of Comments with duplicate post_ids in the results. The implementation idea being that in the Comment model I would add:
tankit 'rails_3_demo' do
indexes :comment_title
indexes :comment_collection
end
def comment_title
return self.post.title
end
def comment_collection
a = ''
self.post.comments.each do |comment|
a += comment.body
end
return a
end
And in IndexTank each post would be a document with a comment collection that is updated on every comment versus what's happening now which is every comment is a unique record in IndexTank.
Thoughts?
Does comment belong to post? If so why are you indexing all of the comments of the parent post all the time?
Why dont you just index on the Post model and the comments that go with it? You could have an instance method in Post called comment_collection not a comment_collection method in the comment model
Often times the simplest path is the best. Actually for the use case that you are telling me I would index comments individually and concentrate more on the query conditions to get the data as you want it. May be I am not understanding correctly
Thanks Kidpollo. Yes, comment does belong to post.
If I had the index in the post model with comment_collection. When a new comment was added how would I reindex the post index to include that comment? Thanks
Did this resolve the issue?
I am going to go ahead and close this
yep, thanks for asking!