Git Product home page Git Product logo

Comments (8)

kidpollo avatar kidpollo commented on September 26, 2024

A custom doc id on the index Tank side?

Could you explain your question a little bit more?

from tanker.

bhellman1 avatar bhellman1 commented on September 26, 2024

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?

from tanker.

kidpollo avatar kidpollo commented on September 26, 2024

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?

from tanker.

bhellman1 avatar bhellman1 commented on September 26, 2024

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?

from tanker.

kidpollo avatar kidpollo commented on September 26, 2024

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

from tanker.

bhellman1 avatar bhellman1 commented on September 26, 2024

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

from tanker.

kidpollo avatar kidpollo commented on September 26, 2024

Did this resolve the issue?

I am going to go ahead and close this

from tanker.

bhellman1 avatar bhellman1 commented on September 26, 2024

yep, thanks for asking!

from tanker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.