binarylogic / searchlogic
- Source
- Commits
- Network (63)
- Issues (42)
- Downloads (48)
- Wiki (1)
- Graphs
-
Branch:
master
-
Reverse named_scopes not only for just equal
2 comments Created 6 months ago by slainer68It would be very cool to also have "reverse" named_scope for all conditions, not only equal.
For example :
User.username_not_blank User.username_not_empty User.username_does_not_end_with("bjohnson") User.username_does_not_begin_with("bjohnson")and so on...
I may try to help for this :).
Nicolas
Comments
-
scope on a column beginning with the name of an association
4 comments Created 6 months ago by etaqueGiving this models :
User has_many :classifieds
ClassifiedUser model has the column "classifieds_count".
This search throws an error, because it seems to ignore User.classifieds_count column and to search on the associated Classified model :
User.classifieds_count_greater_than(5)Emilien
Comments
Has anyone got a quick fix for this? I would love to have it!!
binarylogic
Sun Aug 09 01:47:09 -0700 2009
| link
This has been fixed, let me know if you have any other issues.
-
I've put some of SL initialization values into rails initializers via Searchlogic::Config. Now in 2.0 it's missing.
Comments
binarylogic
Sun Aug 09 01:48:09 -0700 2009
| link
SL 2.0 trimmed a lot of fat, because of this no configuration is needed as of yet. Any helper configuration is passed to the helper directly, and the only helper present is order.
-
I love searchlogic, but it leaves out conditions with Array or Range values. For instance, a named scope may look like:
class State < ActiveRecord::Base named_scope :by_abbreviation, lambda{|a| {:conditions => {:abbreviation => a}} } endOne could pass a number of different types of arguments to such a scope:
State.by_abbreviation('MI') State.by_abbreviation(['MI', 'WA']) State.by_abbreviation('MA'..'MZ')These produce the following queries, respectively:
SELECT * FROM `states` WHERE (`states`.`abbreviation` = 'MI') SELECT * FROM `states` WHERE (`states`.`abbreviation` IN ('MI','WA')) SELECT * FROM `states` WHERE (`states`.`abbreviation` BETWEEN 'MA' AND 'MZ')Could these sorts of scopes be built into searchlogic, using "in" and "between" shorthand in the scope names?
Comments
binarylogic
Sun Aug 09 01:49:02 -0700 2009
| link
Thats a good idea, I will see what I can do to get this in there.
+1 -- I've been scratching my head on this one for a while. The scope works in my console when I run it directly, but in the app - which involves searchlogic - the scope doesn't work.
named_scope :occurred_at_between, lambda {|*args| {:conditions => ["alerts.occurred_at >= ? AND alerts.occurred_at <= ?", (args.first), (args.last)]}}This works in the console, but when added to a search object, it only gets one parameter.
binarylogic
Tue Aug 18 22:36:18 -0700 2009
| link
The problem is that the values sent from the form can only be strings, arrays, or hashes. You can't send ranges, etc. In the console this is dioble, but to have range support directly from the params hash is not possible. The only solution is to send an array to the scope and use the first and last values. You could also create an alias scope that handled a single value and translated to whatever scope you wanted to use.
laserlemon
Wed Aug 19 05:36:25 -0700 2009
| link
That's generally true, but it is entirely possible that a custom param parser is being used.
For instance, I use http://github.com/laserlemon/search_party which gives me search_params containing arrays, ranges, money objects, floats, etc.
Also, searchlogic is obviously much more useful than just passing params to named_scopes. The collection of scopes it adds to the picture are half the fun. In my case, I needed to pass a possible range value to a scope that queried a model's association. I really would rather not reinvent the wheel as far as the association support that's already been built in.
laserlemon
Wed Aug 19 08:33:59 -0700 2009
| link
I forked and addressed the issue using AR's existing attribute_condition and expand_range_bind_variables methods, so the behavior is consistent.
binarylogic
Wed Aug 19 13:52:54 -0700 2009
| link
I agree, thanks a lot for your commits I applied them.
-
s = Person.search s.ascend_by_name true s.all | Andy | Bob | Charlie . . . . . s.descend_by_name true s.all | Andy | Bob | Charlie . . . . . s.ascend_by_name false s.all | Zita | Yvonne | Xaviere . . . . .
Comments
why you need to use true or false? Just use ascend_by_name or descend_by_name and you will be fine.
binarylogic
Sun Aug 09 01:49:50 -0700 2009
| link
Im not sure what the question is.
-
order Helper doesn't honor existing search params
2 comments Created 6 months ago by willcodeforfooChanging the end of order() to something like the following will work:
new_params = params[options[:params_scope]].merge({:order => new_scope}) link_to options[:as], url_for(options[:params_scope] => new_params), html_optionsIt worked for my simple app, not sure if its a comprehensive solution, though.
Comments
it's already fixed for 2.0.2. See http://github.com/binarylogic/searchlogic/commit/c2c7c9374deeb9cb6ccaa072d795a4f1985df00d
binarylogic
Sun Aug 09 01:50:09 -0700 2009
| link
Thanks.
-
Comments
kalasjocke
Sun Aug 09 15:21:45 -0700 2009
| link
Just add the table name to the default scopes order, its kind of uggly but it works.
default_scope :order => "companies.name"
for example.
binarylogic
Wed Aug 19 14:38:58 -0700 2009
| link
Yeah, kalas has it right. Thanks.
-
5 comments Created 4 months ago by binarylogic@Ben Johnsonxfrom-lighthousexorderxInconsistent result of "order" method|S| openxPlease have a look at this:
@@@ ruby
Document.search("descend_by_datetime" => true).order => nil
Document.search(:order => "descend_by_datetime").order => "descend_by_datetime"
Document.search(:order => "datetime DESC").order => "datetime DESC" @@@
IMHO the "order" method should always return the same result.
This ticket has 0 attachment(s).
Comments
binarylogic
Fri Aug 07 15:22:36 -0700 2009
| link
Inconsistent result of "order" method
You make a good point here, but for your examples to pass it would change the underlying logic behind the Search class. The point is just to store values that map to a named scope. So "decend_by_datetime" and :order => "descend_by_datetime" are 2 different named scoped. The order named scope is really just an alias that calls other named scopes. The whole point of it is to make searching with the search object easier. My suggestion is to use "order" when dealing with the search object, and if you aren’t you can do whatever you want.
What do you think?
by Ben Johnson
binarylogic
Fri Aug 07 15:22:41 -0700 2009
| link
Inconsistent result of "order" method
I’m trying to understand, hm, but there is still something confusing if I want to get the order of an existing search object. I find out that using proxy_options gives better result:
@@@ ruby
Document.search("descend_by_datetime" => true).proxy_options[:order] => "documents.datetime DESC" # OK!
Document.search("descend_by_datetime" => true).construct_finder_sql({}) => "SELECT * FROM
documentsORDER BY documents.datetime DESC" # OK! @@@@@@ ruby
Document.search(:order => "descend_by_datetime").proxy_options[:order] => "documents.datetime DESC" # OK!
Document.search(:order => "descend_by_datetime").construct_finder_sql({}) => "SELECT * FROM
documentsORDER BY documents.datetime DESC" # OK! @@@But what is this?
@@@ rubyDocument.search(:order => "datetime DESC").order => "datetime DESC" # OK!
Document.search(:order => "datetime DESC").proxy_options => {} # ???
Document.search(:order => "datetime DESC").construct_finder_sql({}) => "SELECT * FROM
documents" # ??? @@@You see that the proxy_options are blank and the last SQL statement has no ORDER BY.
Maybe I’m the only one who is confused, maybe it’s because I’m going on holiday tomorrow ;-)Best wishes,
Georgby Georg Ledermann
binarylogic
Fri Aug 07 15:22:43 -0700 2009
| link
Inconsistent result of "order" method
That’s because the :order condition MUST be a named scope, you can’t pass raw SQL.
by Ben Johnson
binarylogic
Fri Aug 07 15:22:45 -0700 2009
| link
Inconsistent result of "order" method
Also, this is to protect from SQL injections
by Ben Johnson
binarylogic
Fri Aug 07 15:22:48 -0700 2009
| link
Inconsistent result of "order" method
Ok, totally agree. To avoid irritations, what about raising an exception (like "UnknownOrderError") if someone gives raw SQL (or unknown order scope) to the :order key? I think this would be a good thing, because there is already a Searchlogic::Search::UnknownConditionError raised for wrong :condition value.
by Georg Ledermann
-
4 comments Created 4 months ago by binarylogic@Ben Johnsonxfrom-lighthousexnamed_scopexsearchxBug: Problems with multiple scopes beginning with the same name|S| openxPlease have a look at this small example:
@@@ ruby class Contact < ActiveRecord::Base
has_many :documents, :as => :object has_many :involvements has_many :documents_involved, :through => :involvements, :source => :object, :source_type => ’Document’ endContact.search(:documents_involved_title_like => ’foo’).all
=> NoMethodError: undefined method `involved_title_like’ for #<Class:...>
@@@
Using Rails 2.3.3 and searchlogic plugin 2.1.13 released 2009-07-29
This ticket has 0 attachment(s).
Comments
binarylogic
Fri Aug 07 15:23:13 -0700 2009
| link
Bug: Problems with multiple scopes beginning with the same name
I am trying to create a failing test for this in my test suite and can’t seem to do it. Do you mind giving that a shot. I am 90% certain this has to do with the order of keywords in the regular expression. Ex:
/(documents|documents_involved)/
When it should be
/(documents_involved|documents)/
This is a really easy fix, but I want to get a failing test in place first.
by Ben Johnson
binarylogic
Fri Aug 07 15:23:17 -0700 2009
| link
Bug: Problems with multiple scopes beginning with the same name
This has got a little bit more complicated because the bug has changed since searchlogic 2.3.3. Now it occurs not every time. I can’t reproduce it and can’t write a failing test, sorry. But it seems that it has something to do with other calls to Contact.search BEFORE - very strange.
But I have found a very similar issue, perhaps they are related. Here is a small patch for the specs (just add one line) and the specs will fail:
@@@ diff --git a/vendor/plugins/searchlogic/spec/spec_helper.rb b/vendor/plugins/searchlogic/spec/spec_helper.rb
index a2b98f0..c155938 100644
--- a/vendor/plugins/searchlogic/spec/spec_helper.rb +++ b/vendor/plugins/searchlogic/spec/spec_helper.rb @@ -71,6 +71,7 @@ Spec::Runner.configure do |config|class User < ActiveRecord::Base belongs_to :company, :counter_cache => true has_many :orders, :dependent => :destroyhas_many :orders_big, :class_name => ’Order’, :conditions => ’total > 100’ end
class Order < ActiveRecord::Base @@@
by Georg Ledermann
binarylogic
Sat Aug 08 10:13:28 -0700 2009
| link
Thanks
-
2 comments Created 4 months ago by binarylogic@Ben Johnsonxfrom-lighthousexProblem with Multiple Conditions on STI Models|S| openxThe following is a result of the following example search condition
Ride.make_name_equals("Chevrolet").model_name_equals("Tahoe")
@@@ sql SELECT count(*) AS count_all FROM rides INNER JOIN make_models ON make_models.id = rides.model_id AND (make_models.type = ’Model’ ) INNER JOIN make_models makes_rides ON makes_rides.id = rides.make_id AND (makes_rides.type = ’Make’ ) WHERE ((((rides.deleted_at IS NULL) AND (make_models.name LIKE ’%Tahoe%’)) AND (make_models.name LIKE ’%Chevrolet%’)) AND (rides.deleted_at IS NULL))
@@@I currently have Makes and Models as subclasses to MakeModels, which is self-referential using nested_sets. So
Make has_many Models
Model belongs_to MakeNow... I don’t think this is necessarily a "bug".... but how would one go about changing this
@@@ sql (make_models.name LIKE ’%Tahoe%’)) AND (make_models.name LIKE ’%Chevrolet%’) @@@
to this with OR which will fix my dilemma (and hopefully any one else)
@@@ sql (make_models.name LIKE ’%Tahoe%’)) OR (make_models.name LIKE ’%Chevrolet%’) @@@
This ticket has 0 attachment(s).
Comments
binarylogic
Fri Aug 07 15:23:42 -0700 2009
| link
Problem with Multiple Conditions on STI Models
You could do:
Ride.make_name_equals_any("Chevrolet", "Tahoe")Does that fix the issue?
by Ben Johnson
binarylogic
Fri Aug 07 15:23:45 -0700 2009
| link
Problem with Multiple Conditions on STI Models
Well it would have to be make_model_name, but I would have to have an association to make_model, which given it’s a STI, isn’t really easy to do... since... well, hopefully you can see why...
Only way I’d get this to work is splitting the STI, which i can do... would mean more maintenance, but it would fix this issue...
I was trying to do this using a "filter" method i created based off the order method you provide..
@@@ ruby def filter(search, options = {}, html_options = {})
options[:params_scope] ||= :search options[:as] ||= options[:by].to_s.humanize options[:filter_scope] ||= "#{options[:by]}" new_scope = options[:filter_scope] link_to options[:as], url_for(options[:params_scope] => search.conditions.merge( { "#{options[:on]}_like" => new_scope } ) ), html_options end@@@
Where it would work like your order, just append search conditions based on links that a user can select from a list
by omarvelous
-
5 comments Created 4 months ago by binarylogic@Ben Johnsonxfrom-lighthousexSorting on a single table Help|S| openxI tried out using the example code on my controller i.e @search = new_search(params[:search]) and I am able to sort and view pages in 10, 25 etc.. However, when I add conditions the data is displayed correctly but the sorting and page links don’t work. I am trying this on a single table of data. Your comments and advised would be helpful.
This ticket has 0 attachment(s).
Comments
binarylogic
Fri Aug 07 15:24:05 -0700 2009
| link
Sorting on a single table Help
I have no idea. Can you please create a failing test, and then I can fix the issue. By test, I mean a test I can run in the searchlogic test suite. I apologize for asking you to do this, but its a new policy I am implementing with my open source projects. I am just very busy and this would help me easily knock out the issue.
by Ben Johnson
binarylogic
Fri Aug 07 15:24:11 -0700 2009
| link
Sorting on a single table Help
Wilco, but I need time, since I am a newbie
by ramesh
binarylogic
Fri Aug 07 15:24:14 -0700 2009
| link
Sorting on a single table Help
Will this help ?
When I use :-
"@search = ArdData.new_search(params[:search]);" in the controller the sql generated on sorting any column is :- "Processing ArdDataController#index (for 127.0.0.1 at 2009-04-01 18:01:17) [GET] Parameters: {"search"=>{"order_as"=>"ASC", "order_by"=>"stock"}} ArdData Columns (2.1ms) SHOW FIELDS FROMard_datasArdData Load (0.2ms) SELECT * FROMard_datasORDER BYard_datas.stockASC LIMIT 25 SQL (0.1ms) SELECT count(ard_datas.part_number) AS count_part_number FROMard_datasRendering ard_data/index
Completed in 46ms (View: 23, DB: 3) | 200 OK [http://localhost/ard_data?search%5Border_as%5D=ASC&search%5Border_by%5D=stock]"Here I have tried sorting on the "Stock" column. This works for other columns also.
When I use:-
"@search = ArdData.new_search(:conditions => {:store_type => ’DOR’, :cpq_category => ’P’});" in the controller the sql generated on sorting any column is :-
"Processing ArdDataController#index (for 127.0.0.1 at 2009-04-01 19:24:09) [GET] Parameters: {"search"=>{"order_as"=>"ASC", "order_by"=>"stock"}} ArdData Columns (2.1ms) SHOW FIELDS FROM
ard_datasArdData Load (0.2ms) SELECT * FROMard_datasWHERE (ard_datas.cpq_category= ’P’ ANDard_datas.store_type= ’DOR’) LIMIT 25 SQL (0.6ms) SELECT count(ard_datas.part_number) AS count_part_number FROMard_datasWHERE (ard_datas.cpq_category= ’P’ ANDard_datas.store_type= ’DOR’) Rendering ard_data/index
Completed in 73ms (View: 28, DB: 3) | 200 OK [http://localhost/ard_data?search%5Border_as%5D=ASC&search%5Border_by%5D=stock]"The difference I see is in the "ArdData Load". The first query(no conditions) has a "ORDER BY" clause whereas the second(with conditions) doesn’t.
by ramesh
binarylogic
Fri Aug 07 15:24:17 -0700 2009
| link
Sorting on a single table Help
Sorry for the lack of activity, is this still an issue. It looks like this bug is for the older version of searchlogic.
by Ben Johnson
binarylogic
Tue Aug 18 22:32:17 -0700 2009
| link
Guess not, thanks!
-
2 comments Created 4 months ago by binarylogic@Ben Johnsonxfrom-lighthousexorder() doesn’t order correctly from searchlogic > 2.1.5|S| newxPlease find attached test app to demonstrate the strangely order/sorting behaviour with searchlogic > 2.1.5
This ticket has 1 attachment(s).
Comments
binarylogic
Tue Aug 18 22:37:08 -0700 2009
| link
Can you please create a failing test for this. It would be much easier. I couldn't reproduce any problems with the app. Thank you.
-
ERROR MESSAGE: "ActiveRecord::StatementInvalid (PGError: ERROR: table name "tender_flags" specified more than once"
I am using a join with one table and as I use order by with that table it gives this error
Also any association based sorting by default use INNER JOIN but in my scenario I require LEFT JOIN any suggestion for getting through that issue. thanks.Comments
Details;
User.ascend_by_role_is_admin
in that case the query is;
User Load (1.5ms) SELECT "users".* FROM "users" INNER JOIN "roles" ON roles.user_id = users.id ORDER BY roles.is_admin ASCwhereas I need LEFT JOIN in the query for getting all records but order by is_admin field.
binarylogic
Tue Aug 18 22:43:53 -0700 2009
| link
I have this same problem in my application. There is no easy way around this. Your best bet is to write your own order condition that uses the same join so that AR will remove the duplicates. The other option is to give your left outer joins aliases like "optional_roles". This is what I've been doing in my apps. This really isn't an issue with SL directly, its more of an issue with just combining named scopes. If you want to modify the join that SL creates, you are better off just creating the named scope yourself and adding the join that you want.
Thanks.
-
It would be nice if one could do a simple
ORcondition like this.Article.name_or_content_like("something")I imagine the method_missing call could do a check for "
_or_" in the name, split by it, and add a condition for each resulting attribute.Comments
binarylogic
Tue Aug 18 21:51:19 -0700 2009
| link
Yeah, that's definitely doable. I'll throw something together for that.
josespinal
Tue Aug 18 22:27:27 -0700 2009
| link
Thanks!
binarylogic
Sat Aug 22 16:47:03 -0700 2009
| link
This has been added. It was actually pretty fun to code. Anyways, checkout the readme for some examples, or checkout the specs:
Let me know if you have any issues.
This works for me in a simple case like
Address.first_or_last_like("something")but im having problems with associations:
#Customer => has_many addresses Customer.address_first_or_address_last_like("something") # => error: The condition 'address_first' is not a valid condition, we could not find any scopes that match this. Customer.address_first_like_or_address_last_like("something") # => error: The condition 'address_last_like' is not a valid condition, we could not find any scopes that match thisAlso (im not sure why i was trying this) but this gave me a stack level too deep:
Customer.address_first_like_or_id_equals(0) -
Just as ActiveSupport adds the blank? and present? methods to Object to detect if something is either nil or a blank string/array/whatever, I thought it might be nice to provide the blank and not_blank conditions in searchlogic.
Example:
Person.first_name_blank # => SELECT * FROM people WHERE first_name != '' OR first_name IS NULLJust something we've found to be convenient for our app. Patch w/ specs can be found here:
Comments
Commited to bedecfc, but I think it's not correct:
not_blank should be
column != "" AND column IS NOT NULLYou see, AND instead of OR. Otherwise, the result set includes empty strings.
binarylogic
Mon Aug 24 14:03:57 -0700 2009
| link
Cool, this has been added
You're quite right about that. I rewrote the spec for non_blank to be a little bit more clear. Here's the new patch:
Granted, I think that just saying column != '' will have the same results, since I believe NULL values won't even be considered in a string comparison. I left it as you suggested though for completeness' sake.
Hm, this issue show be re-opened until Ben has commited the patch...
binarylogic
Tue Aug 25 01:40:00 -0700 2009
| link
Thanks, this has been fixed.
-
User.id_ne(10).login_not_like("root").count => 2644 User.id_ne(10).login_not_like("root").count => 2643
this produces
SQL (1.7ms) SELECT count() AS count_all FROM
usersWHERE (users.login LIKE '%root%') SQL (3.9ms) SELECT count() AS count_all FROMusersWHERE ((users.login LIKE '%root%') AND (users.id != 10))Comments
binarylogic
Fri Sep 11 22:30:24 -0700 2009
| link
This is passing for me:
it "should fix bug for issue 26" do count1 = User.id_ne(10).username_not_like("root").count count2 = User.id_ne(10).username_not_like("root").count count1.should == count2 endCan you write a failing test?
-
Association chains that mention the same table twice produce incorrect results
3 comments Created 5 months ago by GFunk911For the example, take the following schema:
Product: id
ProductCategory: id, product_id, category_id
Category: idRows: You have one product in multiple categories
Product id: 1ProductCategory id: 1, category_id: 1, product_id: 1
ProductCategory id: 2, category_id: 2, product_id: 1Category id: 1
Category id: 2Say you want to find all categories that contain a product which is also in category X.
The following scope returns 2 copies of category 1, since the where sql references the wrong product_categories table. It should return categories 1 and 2
Category.product_categories_product_product_categories_category_id_equals(1)
SELECT
categories.* FROMcategories
INNER JOINproduct_categoriesON product_categories.category_id = categories.id
INNER JOINproductsONproducts.id =product_categories.product_id
INNER JOINproduct_categoriesproduct_categories_products ON product_categories_products.product_id = products.id
WHERE (product_categories.category_id = 235)
Comments
binarylogic
Wed Aug 19 14:37:57 -0700 2009
| link
Yeah, I see what you're doing, AR supports this, I just need to figure out how to tap into it.
I also have something similar:
class Direction < ActiveRecord::Base belongs_to :start_point, :class_name => "Point" belongs_to :end_point, :class_name => "Point" end class Point < ActiveRecord::Base has_one :direction end > Direction.start_point_name_eq("A").end_point_name_eq("B")Will give:
SELECTdirections.* FROMdirectionsINNER JOINpointsONpoints.id =directions.end_point_id INNER JOINpointsstart_points_directions ONstart_points_directions.id =directions.start_point_id WHERE ((points.name = 'A') AND (points.name = 'B'))
-
7 comments Created 4 months ago by binarylogic@Ben Johnsonxfrom-lighthousexAttribute with multiple parameters|S| newxHello, here is a feature request
Using named scope like "created_at_after" with helper like "form.date_select" which produces created_at(1i), created_at(2i) ... are not handled.
@@@ html <% form_for(@foos) do |f| %>
<p> <%= f.label :bar_at, ’Bar at after’ %> <%= f.date_select :bar_at_after %> </p> <p> <%#= f.label :bar_at, ’Bar at after’ %> <%#= f.text_field :bar_at %> </p> <p> <%= f.label :bar %> <%= f.text_field :bar_equals %> </p> <p> <%= f.submit :search %> </p>@@@
It ends in an obvious attribute(xi) not recognized. I can still used a text_field helper and pass a string as shown in the example, but that’s not always what can be expected in a search form.
It would be nice feature to have.
JH. Chabran
This ticket has 0 attachment(s).
Comments
binarylogic
Sun Aug 09 01:51:30 -0700 2009
| link
I agree, I tend to always use a javascript calendar date select, etc. So I have never had this issues. I don't think this would be too difficult to solve.
I added support for Date, as you can see there : http://github.com/jhchabran/searchlogic/blob/2d3d7ac5d7a267c8a367bf0066683a9212efc1de/lib/searchlogic/search.rb
It lacks support Time class and maybe some cosmetic changes, but it basically works. ( an expectation was added to search_spec too ).
binarylogic
Sun Aug 09 20:54:50 -0700 2009
| link
Thanks for doing this. I tried refactoring the code and couldn't really follow it. I can't safely pull that code in because I don't completely understand it and it was really hard to follow.
binarylogic
Sun Aug 09 20:56:28 -0700 2009
| link
Also, that code would be best in a completely separate module instead of changing the class itself.
Separating it in a module is basically doable, but it will leads to hook Search#conditions=, Search#method_missing, which seems to me to be a lot of work for just one line and maybe a bit unreliable if you modify these later.
This feature is clearly not critical, but it feels to me that not supporting all form helpers makes it at just a small step from being completely transparent for developers using it.
You wrote you found it hard to follow, can you detail a bit more ?
Rails multi-parameters are weird and in my opinion should be handled earlier, so params[:created_at] should return a date object or at least one string when submitted with three parameters, which would solve everything in the current case.
This forces me to rewrite handling code for theses parameters because as they did in AR it's coupled with models, and leads to a tricky regexp ( created_at(3i) means third argument with need to be casted as an integer), it's easy to write clear code for that, but in the original AR multi-parameter stuff, they allowed support for things like attribute(4f) and I kept support for these to stay coherent.
It was that part you found confusing or something else ?
And btw while I'm here thanks for SearchLogic, I saved much time using it :-)
binarylogic
Tue Aug 18 22:40:17 -0700 2009
| link
I agree, the rails multi parameters are weird and complicated, which is why I try to avoid them. I don't know that your code was hard to follow, its the problem at hand that is hard. My BIG thing with v2 is to keep it simple, and if I add in a feature it needs to be separate out into its own module. v1 got bloated and very hard to maintain. I want to keep v2 simple. Simplicity is better for everyone. Less problems, better performance, etc.
So if you could split this out into a multi parameter module I would add that in. I added your code it and it started to get complicated and harder for me to maintain, which is why I removed it.
Thanks.
We needed this for a client project earlier today so I spent some time writing an alternative implementation. It hooks in a bit differently (alias_method_chain with conditions=) but it works well for the stuff I've tested.
It's a bit more complex than jhchabran's approach as well (although, it was
inspired / designed like it in some parts) and it's built around AR's implementation
/ how the AR implementation is coded as of Rails 2.3.You can see the patch changes at http://github.com/Sutto/searchlogic/, with the actual implementation itself at http://github.com/Sutto/searchlogic/blob/master/lib/searchlogic/search_ext/multiparameter_assignment.rb
-
4 comments Created 4 months ago by binarylogic@Ben Johnsonxconditionsxfrom-lighthousexgroupxgroupingxnot_group support|S| openxhey,
is something like a ’not_group’ available within searchlogic (or in combination with ActiveRecord)?
e.g.:
s=System.new_search
=> #25}>g=s.conditions.not_group => # g.name_equals="test" => "test" g.descr_equals="test" => "test" s.count => 95
generated sql:
SQL (0.5ms) SELECT count("systems".id) AS count_id FROM "systems" WHERE (NOT (("systems"."name" = ’test’ AND "systems"."descr" = ’test’)))This ticket has 0 attachment(s).
Comments
binarylogic
Fri Aug 07 15:24:37 -0700 2009
| link
not_group support
After digging around, trying to find another solution without success I decided to implement that feature within searchlogic. The changes are committed to a fork of searchlogic (http://github.com/sdecastelberg/searchlogic/tree/master). Maybe someone can have a look at it. Feedback is appreciated. (i’m rather new to ruby/ror..)
The implemented not_group works fine for my needs.
by sdecastelberg
binarylogic
Fri Aug 07 15:24:42 -0700 2009
| link
not_group support
Why wouldn’t you adjust your conditions to have the opposite effect instead of doing a not_group. Either way, whatever works for you, if you like the not_group solution then I think its fine, but couldn’t you accomplish the same thing by adjusting your conditions?
by Ben Johnson
binarylogic
Fri Aug 07 15:24:45 -0700 2009
| link
not_group support
the not_group was initially needed for a monitoring/inventory application to map network components (software and hardware) and provide configuration for different network and application layer scanners.
For bulk editing, reporting, etc. we needed an exact match search for every single attribute on every model.
Search Dialog
*group1
*SnmpScan (include) *oid=ssCpuIdle *alarm-threshold=90 *System (exclude) *Status=Test *Modified Date start: 2009-01-01would match the following search (when searching for systems)
(system.snmp_scan.oid=ssCpuIdle AND system.snmp_scan.alarm_threshold=90) AND NOT (system.state=Test AND modified_date>=2009-01-01)The attributes are grouped model-wise and can be combined differently (and, or) and the search can be expanded by adding other groups with subgroups.
The include/exclude flag just sets the not_group attribute on the group, without having to negate all the single attributes.by sdecastelberg
binarylogic
Fri Aug 07 15:24:47 -0700 2009
| link
not_group support
I see what you’re saying. But searchlogic deals with single conditions. If you are writing your own named scope for these conditions why not add in the "NOT" yourself? I guess I’m a little confused how you are using searchlogic and how you want to use it.
by Ben Johnson
-
3 comments Created 4 months ago by binarylogic@Ben Johnsonxassociationsxfrom-lighthousexorderxsearchx#search ignores :order argument on associations which have an order defined|S| openxConsider a class Foo, with associated Bars:
@@@ ruby class Foo < ActiveRecord::Base
has_many :bars, :order => :name end
@@@If you do:
@@@ ruby Foo.bars.search(:order => "ascend_by_size").all
@@@The results are still sorted by :name -- i.e. the "ascend_by_size" :order argument to the #search method is ignored.
The SQL query looks like:
@@@ sql SELECT * FROM bars WHERE bars.foo_id = 1 ORDER BY bars.name;
@@@--
Is this a bug?
This ticket has 0 attachment(s).
Comments
binarylogic
Fri Aug 07 15:25:14 -0700 2009
| link
#search ignores :order argument on associations which have an order defined
Hmm, I’m not sure, let me add a failing test and play around with it. If you want fork the project and write a quick failing test. It looks like the Searchlogic::Search#current_scope is taking priority.
by Ben Johnson
Here is a failing spec: It's running through a defined named_scope, same issue though:
it "should overwrite ordering through a named_scope" do %w(bjohnson thunt).each { |username| User.create(:username => username) } User.class_eval { named_scope :by_username, :order => "username DESC" } User.by_username.ascend_by_username.should == User.all(:order => "username ASC") endHmm, looks like this is the same problem as http://github.com/binarylogic/searchlogic/issues#issue/17 which is an AR problem, not a searchlogic one
-
5 comments Created 4 months ago by binarylogic@Ben Johnsonxfrom-lighthousexorderxorder_byxMulti column ordering|S| openxI would like to have ordering by multiple columns, where each of them can be ascending and descending. Example: "ORDER BY date ASC, id DESC"
What about creating scope like this:
order_by_date_asc_and_id_descSadly, nesting orders with scopes is not possible in Rails 2.3.2, see here:
https://rails.lighthouseapp.com/projects/8994/tickets/2253-named_scope-and-nested-order-clausesSo it should be created as ONE scope.
This ticket has 0 attachment(s).
Comments
binarylogic
Fri Aug 07 15:26:14 -0700 2009
| link
Multi column ordering
Yeah, that would be a nice feature and it’s probably something AR scopes should handle anyways. It looks like it will get applied though, I think they are just waiting on better tests.
by Ben Johnson
binarylogic
Fri Aug 07 15:26:16 -0700 2009
| link
Multi column ordering
Actually my tests are showing that AR does support multi column ordering by chaining named scopes. Are you not seeing that?
by Ben Johnson
binarylogic
Fri Aug 07 15:26:20 -0700 2009
| link
Multi column ordering
Hm, I tested the following with Rails 2.3.2:
@@@ Contact.scoped(:order => ’name DESC’)
=> SELECT * FROM
contactsORDER BY contacts.name DESCContact.scoped(:order => ’name DESC’).scoped(:order => ’id DESC’)
=> SELECT * FROM
contactsORDER BY contacts.name DESC@@@
You will see that the second scope is ignored.
Are we talking about different things? ;-)
by Georg Ledermann
binarylogic
Fri Aug 07 15:26:22 -0700 2009
| link
Multi column ordering
Yeah, my fault, it does chain them together when you pass order in an action method:
User.ascend_by_id.ascend_by_email.first(:order => "test") ActiveRecord::StatementInvalid: Mysql::Error: Unknown column ’test’ in ’order clause’: SELECT * FROM `users` ORDER BY test, users.id ASC LIMIT 1
But for me to make this work I would have to alter the default behavior of AR, which I don’t think is a good idea. I’m not sure what to do. I could do some tricky things in the Search object, but I want that to remain consistent with calling the named scopes directly.
by Ben Johnson
binarylogic
Fri Aug 07 15:26:25 -0700 2009
| link
Multi column ordering
I agree with you. My current solution to have mutliple ordering is by adding some named scopes like this:
@@@ ruby named_scope :ordered_by_name, :order => ’last_name ASC, first_name ASC’Contact.search(:ordered_by_name => true)
@@@Somtimes I need to override the predefined searchlogic ordering scopes like this:
@@@ ruby # Preserve insertion order for sorting by date named_scope :descend_by_date, :order => ’date DESC, id DESC’ named_scope :ascend_by_date, :order => ’date ASC, id ASC’ @@@For me, it’s ok to stay with this. We will see if ActiveRecord will merge multiple ordering scopes in the future.
by Georg Ledermann
-
3 comments Created 4 months ago by binarylogic@Ben Johnsonxfrom-lighthousexSome way to deal with i18n (*_translations tables)?|S| openxI tried long time to deal something with model translations tables, but i can’t figure out anything. Maybe somebody will find way to filter data by field from translations table...
This ticket has 0 attachment(s).
Comments
binarylogic
Fri Aug 07 15:26:49 -0700 2009
| link
Some way to deal with i18n (*_translations tables)?
I’m not sure what you are asking.
by Ben Johnson
binarylogic
Fri Aug 07 15:26:54 -0700 2009
| link
Some way to deal with i18n (*_translations tables)?
When using i18n with rails (in activerecord), translated columns are keept in other table (eg. you have table articles, so translated fields like title, content etc are in article_translations table). When i try search something in title of arcticle then i have error - unknown attribute. You have to do something like:
- check if table articles have specified attribute
- if have then process conditions for it
- if not then check if is article_translations table (or ArticleTranslation model will be easier)
- if exists then check attribute and process conditions
- if not then raise error
Im using for now such mechanism in my controller, but it’s not much pretty way...
by Kriss Kowalik
binarylogic
Fri Aug 07 15:26:56 -0700 2009
| link
Some way to deal with i18n (*_translations tables)?
I see what you are saying. The translations / mapping should happen above board, I don’t feel like this is searchlogic responsibility. Does active record do this with their attributes when trying to create / update records?
by Ben Johnson
-
Order only check columns, why not checking additional values requested via SELECT
3 comments Created 4 months ago by ZenCocoonHi Ben,
Looks like the order option only accept valid columns names. What about additional values requested with SELECT.
Example :
SELECT
users.*, COUNT(1) as count FROM ... ORDER BY count ASCIn this case, ordering by count can be extremely useful but doesn't look supported right now.
As quick workaround creating the named "scope ascend_by_count" and "descend_by_count" makes the job but still overload your models far to quick while adding such feature to searchlogic would keep things light and clean.
Thanks again for this great lib and excellent rewrite,
Warm regards,
-- Sebastien Grosjean - ZenCocoonComments
Yeah, I like this.
I often want to order asc/desc using the count of an associated class.
When you use a counter_cache this is pretty easy to do using the counter_cache column but I don't want to use counter_caches everywhere and every time.
Nicolas.
binarylogic
Fri Sep 11 22:32:06 -0700 2009
| link
Hi Sebastien, I'm not sure I follow, how would you dynamically create that scope? I guess you cold make an exception for count if that is an AR default.
Hi Ben,
Didn't look the inside of named scope system yet (I actually should). The fact is that as of now, it seems that you allow as order, only existing column names from the tables queried.
I my case, I'm looking to also allow values defined by the SELECT parameter. It can be "count" as shown in the previous example but also different values depending your named scope
Example :
named_scope :select_with_author_name_as_writter,
:select => "posts.*, authors.name AS writter", :joins => "LEFT OUTER JOIN authors ON authors.id = posts.author_id"Post.select_with_author_name_as_writter.descend_by_writter NoMethodError: undefined method `descend_by_writter' for #<Class:0x101d8dc48>
...Please let me know if it's still blurred.
-
Using OR searches with associated classes fails with Searchlogic::NamedScopes::OrConditions::UnknownConditionError errors
Comments
laserlemon
Thu Oct 01 11:45:50 -0700 2009
| link
I also encountered this and just confirmed it as a bug. The README says that the OR-joined scopes should work with scopes on associations but that doesn't seem to be the case and the code comments make it seem as though it's still pending.
In my fork, I've written a failing test and a possible solution which passes the test.
-
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!
Comments
carlosantoniodasilva
Thu Sep 03 04:53:28 -0700 2009
| link
The same for me, doing this works:
Update.subject_or_body_contains "list"But this does not:
Update.search(:subject_or_body_contains => "list").allRails 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
Fri Sep 11 00:15:58 -0700 2009
| link
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?
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?Confirming:
>> User.last_name_like_or_first_name_like('tom').size => 1 >> User.search(:last_name_like_or_first_name_like => 'tom').size => 3Same 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
Thu Sep 17 00:31:48 -0700 2009
| link
I'm having the same problem.
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:- name_and_username_like => not working
- name_like_and_user_name_like => working
I hope I can provide a fix for the remaining problem as well
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/
That's great news. I hope it will be pulled into the master repository soon!
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.
-
I'm looking for a way to use Searchlogic to find records which DON'T HAVE records for a given association. For example: "Find all Contacts which have no addresses"
class Contact < ActiveRecord::Base has_many :addresses end class Address < ActiveRecord::Base belongs_to :contact endIn SQL, this query does the job:
SELECT contacts.* FROM contacts LEFT JOIN addresses ON (addresses.contact_id = contacts.id) WHERE (addresses.ID IS NULL)So far as I understand, Searchlogic does not support this. Of course, I can creare a named scope for this:
class Contact named_scope :without_addresses, :joins => 'LEFT JOIN addresses ON addresses.contact_id = contacts.id', :conditions => 'addresses.id IS NULL' endBut I would like to have a more dynamic way, means Searchlogic creating this scope on the fly. What do you think?
Comments
binarylogic
Fri Aug 28 07:04:55 -0700 2009
| link
Searchlogic has a method called left_outer_joins that will create the join for you. But to the best way to solve this is to just add a named scope for each association. I would probably just create another module and do it in there.
Yes, creating scopes the explicit way will work. But I'm looking for a dynamic way. One more example:
Right now, with Searchlogic it's possible to find all contacts with an address in Germany:
>> Contact.search(:addresses_country_equals => 'DE') => "SELECT `contacts`.* FROM `contacts` INNER JOIN `addresses` ON addresses.contact_id = contacts.id WHERE (addresses.country = 'DE') "This creates an INNER JOIN, works fine.
Now, I want to find contacts which don't have an address in Germany. It would be great if Searchlogic could do this, perhaps with this statement:
>> Contact.search(:without_addresses_country_equals => 'DE') => "SELECT `contacts`.* FROM `contacts` LEFT JOIN `addresses` ON (addresses.contact_id = contacts.id AND addresses.country = 'DE') WHERE (addresses.id IS NULL) "The idea is: If the hash key has a "without" in front of the association name, Searchlogic builds the query with the LEFT-JOIN/ID-IS-NULL-Pattern.
IMHO such a feature (implemented in Searchlogic) would be very powerful.
One addition: The whole thing with the left join is required to include contacts which does not have any address, too. You may think my example can be reached with this simple query:
Contact.search(:addresses_country_is_not => 'DE')But this gives a different result set, because it does not include the contacts which have no addresses at all.
-
Exception "undefined method `call' for nil:NilClass"
10 comments Created 3 months ago by slainer68Hi,
I had a weird exception on my production server when using a Searchlogic named_scope, here is
the code :def index @products = Product.available.ascend_by_position.all # ... end
available is a regular named_scope and ascend_by_position is a Searchlogic named_scope on the position column.
The exception :
Error Message: -------------- NoMethodError: undefined method `call' for nil:NilClass Where: ------ orders#index [GEM_ROOT]/gems/activerecord-2.3.4/lib/active_record/named_scope.rb, line 97 Backtrace: ---------- [GEM_ROOT]/gems/activerecord-2.3.4/lib/active_record/named_scope.rb:97:in `ascend_by_position' [GEM_ROOT]/gems/activerecord-2.3.4/lib/active_record/named_scope.rb:181:in `send' [GEM_ROOT]/gems/activerecord-2.3.4/lib/active_record/named_scope.rb:181:in `method_missing' [GEM_ROOT]/gems/activerecord-2.3.4/lib/active_record/base.rb:2143:in `with_scope' [GEM_ROOT]/gems/activerecord-2.3.4/lib/active_record/named_scope.rb:113:in `__send__' [GEM_ROOT]/gems/activerecord-2.3.4/lib/active_record/named_scope.rb:113:in `with_scope' [GEM_ROOT]/gems/activerecord-2.3.4/lib/active_record/named_scope.rb:174:in `method_missing' [RAILS_ROOT]/app/controllers/orders_controller.rb:4:in `index' [GEM_ROOT]/gems/actionpack-2.3.4/lib/action_controller/base.rb:1331:in `send' [GEM_ROOT]/gems/actionpack-2.3.4/lib/action_controller/base.rb:1331:in `perform_action_without_filters' [GEM_ROOT]/gems/actionpack-2.3.4/lib/action_controller/filters.rb:617:in `call_filters' [GEM_ROOT]/gems/actionpack-2.3.4/lib/action_controller/filters.rb:610:in `perform_action_without_benchmark' [GEM_ROOT]/gems/actionpack-2.3.4/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue' [GEM_ROOT]/gems/activesupport-2.3.4/lib/active_support/core_ext/benchmark.rb:17:in `ms' [GEM_ROOT]/gems/activesupport-2.3.4/lib/active_support/core_ext/benchmark.rb:10:in `realtime' [GEM_ROOT]/gems/activesupport-2.3.4/lib/active_support/core_ext/benchmark.rb:17:in `ms' [GEM_ROOT]/gems/actionpack-2.3.4/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue' [GEM_ROOT]/gems/actionpack-2.3.4/lib/action_controller/rescue.rb:160:in `perform_action_without_flash' [GEM_ROOT]/gems/actionpack-2.3.4/lib/action_controller/flash.rb:146:in `perform_action' [GEM_ROOT]/gems/actionpack-2.3.4/lib/action_controller/base.rb:532:in `send' [GEM_ROOT]/gems/actionpack-2.3.4/lib/action_controller/base.rb:532:in `process_without_filters' [GEM_ROOT]/gems/actionpack-2.3.4/lib/action_controller/filters.rb:606:in `sass_old_process' [GEM_ROOT]/gems/haml-2.2.3/rails/../lib/sass/plugin/rails.rb:19:in `process' [GEM_ROOT]/gems/actionpack-2.3.4/lib/action_controller/base.rb:391:in `process' [GEM_ROOT]/gems/actionpack-2.3.4/lib/action_controller/base.rb:386:in `call' [GEM_ROOT]/gems/actionpack-2.3.4/lib/action_controller/routing/route_set.rb:437:in `call' [GEM_ROOT]/gems/actionpack-2.3.4/lib/action_controller/dispatcher.rb:87:in `dispatch' [GEM_ROOT]/gems/actionpack-2.3.4/lib/action_controller/dispatcher.rb:121:in `_call' [GEM_ROOT]/gems/actionpack-2.3.4/lib/action_controller/dispatcher.rb:130:in `build_middleware_stack' /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.2.5/vendor/rack-1.0.0-git/lib/rack/head.rb:9:in `call' /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.2.5/vendor/rack-1.0.0-git/lib/rack/head.rb:9:in `call' /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.2.5/vendor/rack-1.0.0-git/lib/rack/methodoverride.rb:24:in `call' [GEM_ROOT]/gems/actionpack-2.3.4/lib/action_controller/params_parser.rb:15:in `call' [GEM_ROOT]/gems/rails-2.3.4/lib/rails/rack/metal.rb:47:in `call' [GEM_ROOT]/gems/actionpack-2.3.4/lib/action_controller/session/abstract_store.rb:122:in `call' [GEM_ROOT]/gems/activerecord-2.3.4/lib/active_record/query_cache.rb:29:in `call' [GEM_ROOT]/gems/activerecord-2.3.4/lib/active_record/connection_adapters/abstract/query_cache.rb:34:in `cache' [GEM_ROOT]/gems/activerecord-2.3.4/lib/active_record/query_cache.rb:9:in `cache' [GEM_ROOT]/gems/activerecord-2.3.4/lib/active_record/query_cache.rb:28:in `call' [GEM_ROOT]/gems/activerecord-2.3.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:361:in `call' [GEM_ROOT]/gems/actionpack-2.3.4/lib/action_controller/failsafe.rb:26:in `call' /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.2.5/vendor/rack-1.0.0-git/lib/rack/lock.rb:11:in `call' /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.2.5/vendor/rack-1.0.0-git/lib/rack/lock.rb:11:in `synchronize' /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.2.5/vendor/rack-1.0.0-git/lib/rack/lock.rb:11:in `call' [GEM_ROOT]/gems/actionpack-2.3.4/lib/action_controller/dispatcher.rb:106:in `call' /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/rack/request_handler.rb:95:in `process_request' /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/abstract_request_handler.rb:207:in `main_loop' /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/railz/application_spawner.rb:378:in `start_request_handler' /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/railz/application_spawner.rb:336:in `handle_spawn_application' /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/utils.rb:183:in `safe_fork' /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/railz/application_spawner.rb:334:in `handle_spawn_application' /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/abstract_server.rb:352:in `__send__' /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/abstract_server.rb:352:in `main_loop' /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/abstract_server.rb:196:in `start_synchronously' /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/abstract_server.rb:163:in `start' /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/railz/application_spawner.rb:213:in `start' /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/spawn_manager.rb:262:in `spawn_rails_application' /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/abstract_server_collection.rb:126:in `lookup_or_add' /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/spawn_manager.rb:256:in `spawn_rails_application' /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/abstract_server_collection.rb:80:in `synchronize' /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize' /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/spawn_manager.rb:255:in `spawn_rails_application' /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/spawn_manager.rb:154:in `spawn_application' /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/spawn_manager.rb:287:in `handle_spawn_application' /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/abstract_server.rb:352:in `__send__' /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/abstract_server.rb:352:in `main_loop' /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/abstract_server.rb:196:in `start_synchronously' /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.2.5/bin/passenger-spawn-server:61
The weird thing is that I only had this exception on my production server, never had it on my development box.
I tried with and without the .all at the end of line without success. I had to remove the searchlogic named_scope and replace it by a regular named_scope to get rid of this exception.
Comments
binarylogic
Fri Sep 11 22:27:38 -0700 2009
| link
I'm really not sure, its hard for me to determine the problem from this. Is it just this named scope?
Hi Ben, I had this problem again, it seems to be only on this named_scope, strange.
I'll try to investigate more.
austinginder
Tue Nov 17 18:35:02 -0800 2009
| link
I had similar issues between development and production. It may not be related but I fix my problem by downgraded from version 2.3.6 to 2.3.5 on my production server, restarted apache and its working.
austinginder
Mon Nov 30 13:34:22 -0800 2009
| link
well scratch that, I still get the problem, its weird it only happens after the rails app has been running for awhile. Every time I get the problem I can restart my app and it fixes it. Its really annoying as the problem comes back after a day.
well. maybe we should also check which version of ruby we are using. in my case : REE 1.8.6. I'll try updating to REE 1.8.7 in some days...
austinginder, do you also get this exception when mixing searchlogic named_scope with a model named_scope and which are the name of your named_scopes ?
austinginder
Mon Nov 30 17:17:51 -0800 2009
| link
My development server is running
ruby 1.8.7 (2008-08-11 patchlevel 72) [universal-darwin10.0]while my production (the one with the issues) is running
ruby 1.8.7 (2009-06-12 patchlevel 174) [x86_64-linux]I am using the following search logic named scope:
@assets = TempAsset.processing_eq(true) I've also tried changing it to:
@assets = TempAsset.processing_equals(true) Both lines give the mysterious NoMethodError.TempAsset looks like this:
TempAsset(id: integer, title: string, artist: string, length_in_seconds: integer, media_file_name: string, media_content_type: string, media_file_size: integer, created_at: datetime, updated_at: datetime, processing: boolean)
stephankaag
Thu Dec 10 07:43:00 -0800 2009
| link
This look related and happens only with cache_classes turned on.:
class House < ActiveRecord::Base end class Admin::House < House end >> House.order >> Admin::House.order NoMethodError: undefined method `call' for nil:NilClass
mrcsparker
Mon Dec 21 07:08:56 -0800 2009
| link
Same problem here, running ruby 1.9 with rails 2.3.5
omarvelous
Thu Dec 24 17:37:42 -0800 2009
| link
You guys try the plugin?
-
stack level too deep in merge_scopes_with_or
2 comments Created 3 months ago by dougalcornClass Message < ActiveRecord::Base has_many :addresses, :class_name => "MessageAddress" named_scope :system, :joins => 'LEFT JOIN message_addresses ON message_addresses.message_id = messages.id', :conditions => 'message_addresses.id IS NULL' end Class MessageAddress < ActiveRecord::Base belongs_to :message belongs_to :recipeint, :polymorphic => true named_scope :for_user, lambda { |user| { :conditions => ["blah blah blah", user] } } endNow when I do Message.addresses_for_user_or_system(user) It generates a stack level too deep.
searchlogic (2.3.1) [v] lib/searchlogic/named_scopes/or_conditions.rb:104:in `send' searchlogic (2.3.1) [v] lib/searchlogic/named_scopes/or_conditions.rb:104:in `merge_scopes_with_or' searchlogic (2.3.1) [v] lib/searchlogic/named_scopes/or_conditions.rb:104:in `collect' searchlogic (2.3.1) [v] lib/searchlogic/named_scopes/or_conditions.rb:104:in `merge_scopes_with_or' searchlogic (2.3.1) [v] lib/searchlogic/named_scopes/or_conditions.rb:99:in `create_or_condition' searchlogic (2.3.1) [v] lib/searchlogic/named_scopes/or_conditions.rb:104:in `send' searchlogic (2.3.1) [v] lib/searchlogic/named_scopes/or_conditions.rb:104:in `merge_scopes_with_or' searchlogic (2.3.1) [v] lib/searchlogic/named_scopes/or_conditions.rb:104:in `collect' searchlogic (2.3.1) [v] lib/searchlogic/named_scopes/or_conditions.rb:104:in `merge_scopes_with_or' searchlogic (2.3.1) [v] lib/searchlogic/named_scopes/or_conditions.rb:99:in `create_or_condition' searchlogic (2.3.1) [v] lib/searchlogic/named_scopes/or_conditions.rb:22:in `addresses_for_user_or_without_addresses' searchlogic (2.3.1) [v] lib/searchlogic/named_scopes/or_conditions.rb:22:in `send' searchlogic (2.3.1) [v] lib/searchlogic/named_scopes/or_conditions.rb:22:in `method_missing' vendor/gems/mislav-will_paginate-2.3.11/lib/will_paginate/finder.rb:170:in `method_missing' app/models/message.rb:19:in `for_user'There's a couple problems here. Obviously there's a bug that causes the stack level too deep. But the or using an associated named scope seems to be completely unsupported. So maybe my answer is to just not do that. Oh, and I manually patched my searchlogic 2.3.1 with the latest version of or_condition.rb
Comments
binarylogic
Fri Sep 11 22:25:13 -0700 2009
| link
Yeah, association support is coming, I'm working out a couple of issues. I'll throw this in the test suite.
dougalcorn
Sat Sep 12 06:13:11 -0700 2009
| link
Searchlogic really is great. We're making a lot of use out of it. In this case we ended up just writing our own named scope: break out the sql!
-
Search with empty array returns all results instead of none
1 comment Created 3 months ago by gravisNot sure I understand correctly, it might not be a bug.
If I use :Activity.user_id_equals_any(current_user.friend_ids)
I expect this to be equivalent to
Activity.all(:conditions => {:user_id => current_user.friend_ids})and it's not. The first expression will return all activities if the user doesn't have friends, and the second no activity, as expected.
thanks !
Comments
-
I guess the example below will speak on it's own :
named_scope :select_with_authors,
:joins => "LEFT OUTER JOIN authors ON authors.id = posts.author_id"Post.select_with_authors.descend_by_author_name ActiveRecord::StatementInvalid: Mysql::Error: Not unique table/alias: 'authors': SELECT
posts.* FROMpostsINNER JOINauthorsONauthors.id =posts.author_id LEFT OUTER JOIN authors ON authors.id = posts.author_id ORDER BY authors.name DESCPlease let me know if you like further details.
Comments
-
Could be possible to add OR support even to Search class. I would like do this
Book.search(:title_or_description_like => 'ruby')or in chain
s = Book.search s.title_or_description_like('ruby')Now it produce only
s.conditions => {:title_or_description_like => false}Thanks for wonderful work.
Comments
is this going to be worked on, I just ran into this. A large part of using search logic is the search method, but you currently cant use or statements like: User.search(:gpa_lte_or_null => 4) It just ignores all the conditions.
theworkinggroup
Tue Oct 27 13:40:12 -0700 2009
| link
noticed the same issue. a bit annoying.
-
Please replace line 99 of search.rb
scope = conditions.inject(klass.scoped(current_scope)) do |scope, condition| with
scope = conditions.inject(klass.scoped(current_scope || {})) do |scope, condition| otherwise it doesn't work with Rails 2.2.2This issue was already described here http://binarylogic.lighthouseapp.com/projects/16601/tickets/94-nil-object-error but no solution has been given apart from upgrading to Rails 2.3.x, which sadly is often not possible.
Comments
-
Typecasting Range values isn't working and although Ranges aren't typically passed into the arguments for the search method, it's certainly not impossible (as I found out). The individual scopes work correctly, but when accessed through the
searchmethod, they fall apart. I've forked the repo, added a failing test and presented a solution.Comments
-
An existing named scope that shares its name with one of the model's columns is ignored when accessed via the
searchmethod. Thenormalize_scope_namemethod appends "_equals" with no regard for whether the scope already exists. I've forked the repo, added a failing test and presented a solution.Comments
-
Multiple record copies returned for habtm association
1 comment Created 3 months ago by infraredI committed a test case that reproduces the problem in http://github.com/infrared/searchlogic/commit/34d3b89122812df2b4fa9a0c8339674ecf25f206
When you have two models joined with has_and_belongs_to_many and you search one of them with something like:
FirstModel.search(:second_models_id_equals_any => [1, 2]).allmultiple copies of the same FirstModel record will be returned if a the record happens to be associated with more than one SecondModels.
Comments
laserlemon
Tue Dec 08 09:39:49 -0800 2009
| link
Same issue here. Definitely not the expected behavior.
-
For some reason, when I try to do an is(#) or equals(#) or _eq(#), I always get an error about there being the wrong number of arguments.
Table:
Workflow(id: integer, created_by: integer, held_by: integer, prefix: integer, project_id: integer, form_id: integer, fields: text, subject: string, priority: integer, status: integer, due_date: datetime, created_at: datetime, updated_at: datetime)
Records:
+----+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+ | id | cre... | hel... | prefix | pro... | for... | fields | sub... | pri... | status | due... | cre... | upd... | +----+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+ | 4 | 1 | 1 | 0 | 3 | 9 | 28d... | | 2 | 0 | | 200... | 200... | | 5 | 1 | 1 | 0 | 2 | 7 | | | 2 | 0 | | 200... | 200... | +----+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+
Trying to execute Workflow.status_is(0) results in:
ArgumentError: wrong number of arguments (2 for 1) from C:/Ruby/lib/ruby/gems/1.8/gems/searchlogic-2.3.5/lib/searchlogic/named_scopes/conditions.rb:93:in `attribut e_condition' from C:/Ruby/lib/ruby/gems/1.8/gems/searchlogic-2.3.5/lib/searchlogic/named_scopes/conditions.rb:93:in `create_p rimary_condition' from C:/Ruby/lib/ruby/gems/1.8/gems/searchlogic-2.3.5/lib/searchlogic/named_scopes/conditions.rb:151:in `call' from C:/Ruby/lib/ruby/gems/1.8/gems/searchlogic-2.3.5/lib/searchlogic/named_scopes/conditions.rb:151:in `scope_o ptions' from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/named_scope.rb:91:in `call' from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/named_scope.rb:91:in `named_scope' from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/named_scope.rb:96:in `call' from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/named_scope.rb:96:in `status_equals' from C:/Ruby/lib/ruby/gems/1.8/gems/searchlogic-2.3.5/lib/searchlogic/named_scopes/conditions.rb:175:in `send' from C:/Ruby/lib/ruby/gems/1.8/gems/searchlogic-2.3.5/lib/searchlogic/named_scopes/conditions.rb:175:in `create_ alias_condition' from C:/Ruby/lib/ruby/gems/1.8/gems/searchlogic-2.3.5/lib/searchlogic/named_scopes/conditions.rb:83:in `create_c ondition' from C:/Ruby/lib/ruby/gems/1.8/gems/searchlogic-2.3.5/lib/searchlogic/named_scopes/conditions.rb:66:in `method_m issing' from C:/Ruby/lib/ruby/gems/1.8/gems/searchlogic-2.3.5/lib/searchlogic/named_scopes/association_conditions.rb:19: in `method_missing' from C:/Ruby/lib/ruby/gems/1.8/gems/searchlogic-2.3.5/lib/searchlogic/named_scopes/association_ordering.rb:27:in `method_missing' from C:/Ruby/lib/ruby/gems/1.8/gems/searchlogic-2.3.5/lib/searchlogic/named_scopes/ordering.rb:30:in `method_mis sing' from C:/Ruby/lib/ruby/gems/1.8/gems/searchlogic-2.3.5/lib/searchlogic/named_scopes/or_conditions.rb:24:in `metho d_missing' from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:1833:in `method_missing' from (irb):11Comments
laserlemon
Tue Oct 06 08:20:19 -0700 2009
| link
It looks like this may be my fault. The problem is that
ActiveRecord::Base.attribute_conditiononly started accepting two arguments when it started supporting end-exclusive ranges, starting at ActiveRecord 2.3.1. I see you're using 2.2.2, which is causing the error.Is it worth having a version check in there for backwards compatibility?
laserlemon
Tue Oct 06 08:32:37 -0700 2009
| link
Could be. I defer to Ben.
-
Search through association with column named "name" fails
1 comment Created 2 months ago by naven87Take the following models
Earnings: belongs_to :period
Period: has_many :earnings
if Period has a string column titled "name" the following search fails
Earnings.period_name_like("Q309") with a MySQL error that the Table/Alias periods is not unique. If I look at the generated MySQL, it creates both an inner and and outer join on the periods table against the earnings table.If I instead call Earning.period_id_is(7) it works fine and no error is generated. The MySQL query only includes one outer join and no inner join.
Comments
So after more digging, I found that the column name was irrelevant, the real issue was any default scope on the model is merged into the query without concern for overlap. So if the default scope has a join or include in it, that will be included directly in the final query and if the searchlogic portion uses the same table name it will add it's own join into the query which can create the problem described
-
I am trying to use jqGrid's search function with searchlogic. The rub of it is jqGrid's aliases for 'less than or equal to' and a few others do not map onto searchlogic's. Right now, I am creating a hash constant in the application controller to the mapping. What I would love is to have a configuration file that would allow me to extend the aliases. This way, I could drop that config file in any app I so chose that I wanted to use both libraries in concert. Anyway, thank you for such a wonderful plugin and if you would like me to write up a spec, I would be more than happy to.
cheers,
-xnComments
-
in the server console, parameters coming in fine:
Processing GamesController#index (for 127.0.0.1 at 2009-10-16 07:12:36) [GET]
Parameters: {"commit"=>"Submit", "search"=>{"year_ge"=>"1920", "order"=>"", "year_le"=>"2009", "segment"=>"reg"}}but gets passed incorrectly to the scope:
NoMethodError (undefined method `year_ge' for {}:Hash):
Comments
-
Ben seems to show examples of "User.age_greater_than(20)" but age as an attribute is often used in models as a virtual attribute which calculates the current age from DOB.
When I use age as a virtual attribute and search on it, I get a "undefined method `age_greater_than' for #<Class:0x48fff80>"
What am I missing?
Comments
-
searchlogic uses NULL value on search by date (created_at_gte)
3 comments Created 2 months ago by spovichDoing a simple search on the created_at column will produce SQL that has a NULL value for the date.
In the form, I input in ISO date format (YYYY-MM-DD), and the values shows in the params in the logs:
Parameters: {"commit"=>"Search", "action"=>"index", "controller"=>"foos", "search"=>{"city_like"=>"", "created_at_gte"=>"2009-04-13"}}
But the resulting SQL gives a NULL for the date:
SELECT * FROM "foos" WHERE (foos.created_at >= NULL)
Comments
Ok, the issue is that searchlogic silently makes a nil when you provide a date for a datetime field. However, ruby converts date to time without a problem:
Time.parse "Jan 1, 2009" => Thu Jan 01 00:00:00 -0800 2009
So, this seems to be a bug to me. I'll write some failing specs if you agree that it should be able to convert a date to a datetime when searching.
Taking another look and I see search_spec.rb line 267 is a search of a datetime that is given an date, so we agree that a Date should be upcast to a dateTime.
The specs all pass for me using the SQLite db, but trying the same thing with a stock rails app 2.3.4 and ruby 1.8.7 in IRB (console) with Postgres 8.3 and latest pg gem (0.8.0) will fail (running on OS X):
>> s = Message.search
=> #<Searchlogic::Search:0x35e6ad4 @klass=Message(id: integer, type: string, uuid: string, title: string, description: text, created_at: datetime, updated_at: datetime), @current_scope=nil>
>> s.created_at_after = 'Jan 1, 2009' => "Jan 1, 2009" >> s.created_at_after => nil
I don't know how to make this fail in SQLIte, but it is clearly failing in postgres. Any ideas?
Thanks,
John -
This is what my search form sends:
"search"=>{"value_equals"=>"0..15000", "property_type_id"=>"1"}
The value_equals parameter is not read as a proper range, like from 0 to 15000 and while it should display as a result a record with value "10000", none is shown.
Comments
-
given a model
Company with attribute
nameand a model
Contact with attributes
first_name and last_nameThe Models are associated like this:
Contact belongs_to Company Company has_many ContactsI wish to make a search field into which I can type a portion of either the contact's first name, the contact's last name or the company name.
This works:
@contacts = Contact.company_name_like(params[:search])This works:
@contacts = Contact.first_name_or_last_name_like(params[:search])This does NOT work:
@contacts = Contact.company_name_or_first_name_or_last_name_like(params[:search]) It returns this error:
"The condition 'company_name' is not a valid condition, we could not find any scopes that match this."Evidently the scope company_name works by itself but not in combination with the other two. And the other two work, but not with company_name. I can only assume this has to do with the association and I am missing something obvious. Can anyone point out how to do it correctly?
The last example (company_name_or_first_name_or_last_name_like) worked in an earlier version of my app, when company was an attribute of Contact. When I made Company a separate model it stopped working.
I believe I have the current version of binarylogic-searchlogic. Rails version is 2.3.2, in development mode with standard sqlite database.
Thank you.
Comments
-
Only works when config.cache_classes = false
0 comments Created 2 months ago by jnarowskiI love search logic, but cannot get it to run in production mode. I found out that the cache_classes setting was the culprit. I know searchlogic works dynamically, but is there a way to enable searchlogic with class_caching?
When the classes are not cached I get:
undefined methodcached_tags_contains' for #<Array:0x4e064c0> or<br/> undefined methodid_contains' for #<Array:0x4e064c0>Comments
-
For some reason Searchlogic::Search.respond_to?(:paginate) returns false, even though you can call paginate on it.
This was messing up Hobo, so I monkey patched it:
class Searchlogic::Search
def respond_to?(symbol) return true if symbol === :paginate old_respond_to? symbol end endComments
-
The change log states that modifiers were added quite a while ago. However, I can't seem to use them. I keep getting errors like: "The lower_of_first_name_eq is not a valid condition. You may only use conditions that map to a named scope"
Are modifiers available in the latest release?
Comments
-
if Car has_many Tires
Tire has an integer column called sizeI should be able to do :
Car.tires_size_equals([4,5,6])
That fails though. I am able to do a single item though like Car.tires_size_equals(4)
Here is the error:
/Library/Ruby/Gems/1.8/gems/searchlogic-2.3.6/lib/searchlogic/named_scopes/conditions.rb:111: warning: multiple values for a block parameter (2 for 1)from /Library/Ruby/Gems/1.8/gems/searchlogic-2.3.6/lib/searchlogic/named_scopes/conditions.rb:173ActiveRecord::PreparedStatementInvalid: wrong number of bind variables (2 for 1) in: support_regions.region_id IN (?)
from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/base.rb:2398:in `raise_if_bind_arity_mismatch' from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/base.rb:2350:in `replace_bind_variables' from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/base.rb:2341:in `sanitize_sql_array' from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/base.rb:2230:in `sanitize_sql' from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/base.rb:1494:in `merge_conditions' from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/base.rb:1492:in `each' from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/base.rb:1492:in `merge_conditions' from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/base.rb:1804:in `add_conditions!' from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/base.rb:1687:in `construct_finder_sql' from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/base.rb:1548:in `find_every' from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/base.rb:615:in `find' from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/named_scope.rb:181:in `send' from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/named_scope.rb:181:in `method_missing' from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/base.rb:2143:in `with_scope' from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/named_scope.rb:113:in `__send__' from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/named_scope.rb:113:in `with_scope' from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/named_scope.rb:174:in `method_missing' from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/named_scope.rb:188:in `load_found' from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/named_scope.rb:166:in `proxy_found' from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/named_scope.rb:109:in `inspect' from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb.rb:302:in `output_value' from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb.rb:151:in `eval_input' from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb.rb:263:in `signal_status' from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb.rb:147:in `eval_input' from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb.rb:146:in `eval_input' from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb.rb:70:in `start' from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb.rb:69:in `catch' from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb.rb:69:in `start'Comments
-
What is the "right" way to search on boolean columns?
>> Invite.code_equals('F0LzDetW') => [#<Invite id: 29, created_at: "2009-11-14 20:53:51", updated_at: "2009-11-14 20:53:51", code: "F0LzDetW", table: nil, item: 11, accepted: nil, email: "bot@........lv">] >> Invite.code_equals('F0LzDetW').accepted_equals(false) => [] >> Invite.code_equals('F0LzDetW').accepted_equals(nil) => [] >> Invite.code_equals('F0LzDetW').accepted_does_not_equal(false) => [] >> Invite.code_equals('F0LzDetW').accepted_does_not_equal(nil) => [] >>Comments
-
I found some old issues, concerning the date_select helper. It looks like there should be support to use this helper in combination with searchlogic.
But when I use <%= f.date_select :start_after, :include_blank => true %> it fails with
"The is not a valid condition. You may only use conditions that map to a named scope"Comments
philrosenstein
Mon Dec 07 08:10:49 -0800 2009
| link
I have also encountered this issue. It looks like the dynamic finder is looking to match the individual date parts rather than the whole date...
undefined method `created_at_after(1i)='same probleme here :
The is not a valid condition. You may only use conditions that map to a named scope
I have encountered this issue as well. This is really a fundemental requirement in an application I am currently writing. I am a big fan of Searchlogic because it helps keep my code very clean and I'd hate to need to use something else in order to solve this problem.
I have write a quick/dirty solution to handle date_select :
make a file /config/initializer/searchlogic.rb -
searchlogic :order => 'ascend_by_id' throws Errors when having a named_scope :order in the model
0 comments Created about 1 month ago by hasclassHaving a named_scope :order (for the obvious reason of ordering) in a model, searchlogic ordering won't work anymore.
class Blog < ActiveRecord::Base
named_scope :order, lambda {|order| {:order => order}} endBlog.searchlogic(:order => "ascend_by_id") results in:
ActiveRecord::StatementInvalid: Mysql::Error: Unknown column 'ascend_by_id' in 'order clause': SELECT * FROMblogsORDER BY ascend_by_id DESC LIMIT 1must have something to do with the def scope? method in search.rb
cheers
Comments
-
Hello
As searchlogic is able to read scopes, it would be great we could code User.search(:username_or_first_name_like => "ben") just like we use User.username_or_first_name_like("ben")
My 2 (euro)cents
Comments
-
Example for combine scopes with ‘OR’ is incorrect
0 comments Created 26 days ago by vandrijevikThe second example in the Readme under the "Combine scopes with ‘OR’" section reads:
User.id_or_age_lt_or_username_or_first_name_begins_with(10) => "id < 10 OR age < 10 OR username LIKE 'ben%' OR first_name like'ben%'"however, running
User.id_or_age_lt_or_username_or_first_name_begins_with(10)results in the SQL:"id < 10 OR age < 10 OR username LIKE '10%' OR first_name LIKE '10%'"being run. Trying something like:
User.id_or_age_lt_or_username_or_first_name_begins_with(10, "ben")raises a ActiveRecord::PreparedStatementInvalid, so there is no way to get the users whose id or age is less than 10 or username or first name begins with "ben".
It seems that the only scopes this will work for are ones that take the same number of arguments, and operate on the same type of field (since username like '10%' makes little sense).
Comments
-
Passing an array to like_any changes the search field value
0 comments Created 25 days ago by wksmallI've got a form like this:
<% form_for @search do |f| %>
<fieldset> <legend>Search</legend> <%= f.label(:source_like_any, "Source:") %> <%= f.text_field(:source_like_any, :size => '40') %> <%= f.submit("Search") %> </fieldset><% end %>
My controller does this:
def index
options = params[:search] options['source_like_any'] = options['source_like_any'].to_s.split @search = MediaItem.searchlogic(options) @results = @search.all.paginate(:page => params[:page], :per_page => 20)end
I did this after watching Railscast #176 because I want to find all the words in any order.
The problem is that when the result form is displayed, the spaces are gone from the words in the search field. Resubmitting the search will get different results.
Any way around this or did I just miss something in the docs or Railscast?
Comments
-
Unfortunately when using postgres the default order is case sensitive such that all Capitalized values come before all lowercase values. This seems counter intuitive and certainly not desired in my project. As far as I can tell there is currently no support for case insensitive ordering with searchlogic. I was able to solve this by adding two new named_scopes in Searchlogic::NamedScopes::Ordering.create_ordering_conditions like so:
named_scope("iascend_by_#{column}".to_sym, {:order => "upper(#{table_name}.#{column}) ASC"}) named_scope("idescend_by_#{column}".to_sym, {:order => "upper(#{table_name}.#{column}) DESC"})Search logic rocks, and I know it's bad practice to be hacking plugins so I'm hoping you will include this in your next release. Let me know what you think!
Comments
-
Bug or just fundamental incompatibility w/rails default_scope? If I declare a default_scope on my model, none of the rails_helpers for click-sort column headings will work.
The search object is built up correctly, but rails clobbers it w/the default scope.
I can work around this by declaring default sort criteria in the controller where the search object is created, but the only thing I don't like is how the the default_scope silently kills your searchlogic search.
Any thoughts?
Comments
-
Multiple arguments breaks IN (?) support in forms
0 comments Created 15 days ago by slainer68Being able to pass multiple arguments is a great idea for custom named_scopes in the model but IMHO this feature should not be enabled by default on Searchlogic dynamic named_scopes.
I was using Searchlogic with my forms to pass multiple values in a Searchlogic _equals named_scope to create a IN (?) conditions, and since this commit, it is entirely broken.
>> User.state_equals(["refused", "banned", "aborted", "deleted"]).all (This works!) >> User.searchlogic(:state_equals => ["refused", "banned", "aborted", "deleted"]).all /Library/Ruby/Gems/1.8/gems/searchlogic-2.3.9/lib/searchlogic/named_scopes/conditions.rb:117: warning: multiple values for a block parameter (4 for 1) from /Library/Ruby/Gems/1.8/gems/searchlogic-2.3.9/lib/searchlogic/named_scopes/conditions.rb:175 ActiveRecord::PreparedStatementInvalid: wrong number of bind variables (4 for 1) in: users.state IN (?)Comments
-
Case insenitive search for PostgreSQL doesn't work under JRuby
0 comments Created 3 days ago by constrexBecause the JDBC adapter returns "JDBC" when sent ActiveRecord::Base.connection.adapter_name when running PostgreSQL, the condition in lib/searchlogic/named_scope/conditions.rb doesn't trigger when using a _like named scope.
A possible change could be to use ActiveRecord::Base.connection.respond_to?(:postgresql_version), but unfortunately, I don't have an installation of regular Ruby to test this against.
Comments
- @Ben Johnson▾
- associations▾
- conditions▾
- from-lighthouse▾
- group▾
- grouping▾
- named_scope▾
- order▾
- order_by▾
- search▾
- |S| new▾
- |S| open▾
- Apply to Selection
-
Change Color…
Preview:preview
- Rename…
- Delete






Bigtime. I've run into this with LIKE, and got suspicious results (duplicated rows) when I tried it myself across a join.
This has been in searchlogic for a couple of weeks now, sorry for not noticing this. But you should be good to go.