kidpollo / tanker

IndexTank Integration with your fav ORM

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Negative conditions don't work as expected (or at all?)

coryschires opened this issue · comments

From my console:

Profile.search_tank("Kris")

Returns:

+-----+------------+-----------+-------------------------+------------+
| id  | first_name | last_name | bio                     | department |
+-----+------------+-----------+-------------------------+------------+
| 240 | Miss       | Kris      | Atque consequuntur l... | Dolor      |
+-----+------------+-----------+-------------------------+------------+

So I'm expecting this:

Profile.search_tank("Kris", :conditions => {'-id' => [204]})

To return nothing, but instead I get:

+-----+------------+-----------+-------------------------+------------+
| id  | first_name | last_name | bio                     | department |
+-----+------------+-----------+-------------------------+------------+
| 240 | Miss       | Kris      | Atque consequuntur l... | Dolor      |
+-----+------------+-----------+-------------------------+------------+

Two thoughts:

  1. Am I missing something simple?
  2. In this case, does id refer to the index tank document id rather than the id of the resource I'm searching on (i.e. the profile's id)?

If tanker is filtering on the index_tank doc id, I suspect that's not the behavior that most people would expect. Ideally, we shouldn't need to concern ourselves with index_tank references.

Please let me know if I'm missing something easy. Otherwise, let me know if you'd like me to start working on a fork.

Thanks, Cory.

I think the problem is you are not indexing the id attribute.

My original reasoning that the user must decide to index or not the attributes he/she wants because for some people it might not make sense to fiter by id and for some not and I wanted to keep it minimal and extensive.

I am working on features where this might change in the future but you should not worry for now just make sure to index the id also, sorry if this is not clear I did not expect this was implied :D
Ej.

class Product
include Tanker

tankit 'tanker_integration_tests' do
indexes :id
indexes :name
indexes :href
indexes :tags
end

end

btw this can be achieved many ways, I am working on integration specs for better understanding of how thos works but here is a peek

...

 before(:all) do
    @doggie_1 = Product.create(:name => 'doggie 1', :tags => ['puppuy', 'pug'] )
    @doggie_2 = Product.create(:name => 'doggie 2', :tags => ['pug'] )
    @doggie_3 = Product.create(:name => 'doggie 3', :tags => ['puppuy', 'yoirkie'] )
  end

...

 it 'should not search for doggie_3' do
    @results = Product.search_tank('doggie', :conditions => {:tags => 'puppy', '-name' => 'doggie_3'})
    (@results - [@doggie_1]).should be_empty

    @results = Product.search_tank('doggie', :conditions => {:tags => 'puppy', 'NOT name' => 'doggie_3'})
    (@results - [@doggie_1]).should be_empty

    @results = Product.search_tank('doggie NOT doggie_3', :conditions => {:tags => 'puppy'} )
    (@results - [@doggie_1]).should be_empty
  end