kidpollo / tanker

IndexTank Integration with your fav ORM

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Conditional Indexing

jon-n opened this issue · comments

With tanker, is there a way to make it so that a model is only indexed based on certain conditions? In my case, I only want to index if the model joins to another model. I've tried some different approaches, but so far nothing has been compatible with rake tanker:reindex.

yeah this is one of the main requests. something like a where statement, I will try to come up with a way. Any suggestions on how te api would look¿?

Yeah, something like a where statement, not sure exactly what's the best way. I was hoping there would be a way to just put some conditions around the "indexes" parts inside the tankit statement

I would also like the the ability to specify different indexes depending on Rails.env. Currently I have a yaml file which I've sourced in tanker.rb to conditionally set the index name depending on environment. It works fine, but it sorta sucks that I need both a yaml file and an initialization file.

Maybe tanker.rb could be smarter. With commented code snippets and corresponding documentation explaining different configuration options (e.g. pagination). I'm thinking something similar to simple_form.

Either way, it would be really nice if I could easily say: "Use this index in production. Use this index in staging. And so on."

@coryshires not sure if this makes it any better than your yaml setup, but here's how I have my configs set up so tanker uses the appropriate index depending on environment:

app/config/environments/development.rb:

config.indextank_index = 'development_index_name'

app/config/environments/production.rb:

config.indextank_index = 'production_index_name'

And then in the tankit part of in model, I just have:

tankit Rails.configuration.indextank_index do
(tanker stuff)
end

I am actually of the idea that YML files suck and that there is no reason to have credentials embebed in your ruby files loaded in the config directory. Rails already supports loading different config files depending in the environment or if you want a single file just have logic that uses the Rails.env call. I really want tanker to not be super tied to rails. I do have a railtie that can be extended so feel free to submit a patch I will consider it for sure.

@kidpollo

I'm fine with no yaml files. I actually think athst's suggestion will address my concerns.

Once I merge it into my project (and ensure it works, tho I don't see why it wouldn't), I'll probably update the read me to let others know the best way to set conditional indexes.

cool! I am finishing adding support for categories! I am exited for the new features of the gem

FYI - I am still interested in this feature.

I think the API could be pretty simple--i.e.:

tanker :index do
  indexes :title
  indexes :author
  conditions do
    published
  end
end

Then, if published is true for a particular instance, it will get indexed. If it is false, it will not get indexed.

Still working hard on this, sorry for the delay!

Here's our pull proposal (mine and @vvgomes): #60

Implemented :)