binarylogic / searchlogic

Searchlogic provides object based searching, common named scopes, and other useful tools.
http://rdoc.info/projects/binarylogic/searchlogic
MIT License
1.39k stars 133 forks source link

Problem with "OR" named_scopes in forms #24

Closed hsa closed 13 years ago

hsa commented 15 years ago

It seems its not working from the form:

- form_for @search do |f|
  %p
    = f.text_field :name_or_description_like
    = f.submit "Search"

It works from the console, using Report.name_or_description_like but when I use it in the form I just get a "false" result in the text field, and no filters are applied (I checked the logs).

Let me know if you need any more info (I'm using the latest version of searchlogic and rails 2.3.2).

I also run a test creating a new rails app from scratch with rails 2.3.3 and exactly the same happens, it doesn't get filtered and it shows a "false" string in the form (as a response).

Thanks a lot for a great plugin!

fabiokr commented 15 years ago

It happens to me too.

carlosantoniodasilva commented 15 years ago

The same for me, doing this works:

    Update.subject_or_body_contains "list" 

But this does not:

    Update.search(:subject_or_body_contains => "list").all
imanel commented 15 years ago

Rails 2.3.4, SL 2.3.3: Update.search(:subject_or_body_contains => "list") produces:

<Searchlogic::Search:0xb7457ac4 @klass=Update(id: integer, subject: string, body: string, created_at: datetime, updated_at: datetime), @conditions={:subject_or_body_contains=>false}, current_scopenil

joerichsen commented 15 years ago

Same for me Rails 2.3.4 and SL 2.3.3

User.name_or_email_like('Gade').size => 2 User.search(:name_or_email_like => 'Gade').all.size => 379

?

imanel commented 15 years ago

There will be exacly the some with: s = User.search s.name_or_email_like('Gade') That's because in Search model in "or" conditions is some bug that set any "or" condition to false(it is visible as I showed earlier but value = false) so no filtering by that condition. Right now I can't find the exact line, but I think that it is somehow connected to validating scope "or" spliting (lib/searchlogic/named_scopes/or_conditions.rb) Any ideas?

henrypoydar commented 15 years ago

Confirming:

User.last_name_like_or_first_name_like('tom').size => 1 User.search(:last_name_like_or_first_name_like => 'tom').size => 3

ghost commented 15 years ago

Same for me:

 >> User.login_or_email_like('lec').size
 SQL (0.4ms)   SELECT count(*) AS count_all FROM `users` WHERE ((users.email LIKE '%lec%') OR (users.login LIKE '%lec%')) 
 => 2

 >> User.search(:login_or_email_like => "lec").size
 SQL (0.3ms)   SELECT count(*) AS count_all FROM `users` 
 => 23
gavinhughes commented 15 years ago

I'm having the same problem.

theconektd commented 15 years ago

Same here.

namxam commented 15 years ago

Ok… I encountered the same problem and checked the source code (quite impressive). After some digging and testing I found the problem, but so far I did not came up with a perfect solution for it. Until then, I have a partial quick fix which I provide at: http://github.com/namxam/searchlogic/ This fix is only working for fully qualified conditions:

I hope I can provide a fix for the remaining problem as well

nebolsin commented 15 years ago

Hi! I finally fixed this problem even for not fully qualified conditions. And also added type convertion, so User.search(:id_or_age_lte, '10') will now work properly.

The fix is here: http://github.com/nebolsin/searchlogic/

namxam commented 15 years ago

That's great news. I hope it will be pulled into the master repository soon!

awd commented 14 years ago

I am running 2.3.5, but it still appears to be present in this version as well. I am new to searchlogic, so if a work around has been mentioned - I apologize, and point me in the right direction.

note: I did see nebolsins repo above, but have not tried it yet.

gardelea commented 14 years ago

First off , thanks for the awesome search dsl !

Is there any chance of the fix in http://github.com/nebolsin/searchlogic/ being pulled into the official repo ? I keep running into this problem and do not want to create yet another fork for this one issue.

thanks .

cknoxrun commented 14 years ago

Awesome job on searchlogic, but I agree, this one is bugging me too!

nebolsin commented 13 years ago

Seems like my fix is included by 00aab642be72171aa098108002d2fd43b6092f05 and this issue could be closed.

hsa commented 13 years ago

Indeed, closing, thanks for fix.