Giter VIP home page Giter VIP logo

meta_search's People

Contributors

benhutton avatar burlesona avatar dessy avatar dx7 avatar ernie avatar jbarreneche avatar knoopx avatar scarroll32 avatar windock avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

meta_search's Issues

default scopes and sorting

Hi,
Perhaps, this is more of a SO question rather than an issue...but I'll go ahead with it.

I have a scope defined in my Listing model:

scope :recent, order("updated_at DESC")

I would like use this scope by default in my Listing controller but "ignore" it when I click sort_link in my views:

def index
@search = Listing.search(params[:search])
@listings = @search
end

I tried calling it:
@search = Listing.recent.search(params[:search])

but it seems, sort_link sorting comes after recent scope in SQL, hence sort_links stop working altogether.

Is that feasible in any way?

Recursive data in has_many relationship

I have two models with a has_many relationship. I'm doing the search on the parent table but searching for rows in child table. My problem is, on the result set, rows from the parent table exists multiple times. Actually as the count of the matched rows in child table.

Is this the default behaviour? I solved the issue bu using a scope just before "search" command which includes a "distinct" on "id" column. But didn't like the solution.

Thanks.

or but not and ?

Hi,
I try to explain my idea
i have 2 value in database : "min." and "max."
I need to search all items where the value (type by users in search form) is in this 2 points.

I try in form :
text_field :min.gte
text_field :max.lte

i need min.gte AND max.lte, but the metasearch make min.gte OR max.lte

I try
text_field :eq_hab_mini_eq_hab_max_all ,doesn't work!

i don't know how to use multiparameter-between in this case, with to different DB column name.

Is it possible to make a option AND with 2 text_field or in the multiparameter_field.

Thx

Custom Where and null param

Hi!

I'm trying to implement a custom where to implement some sort of relative date matching (for example, all entries created since the last day/month/year). In the view, this is represented by a helper composed of 3 selects, one for each parameter.

My implementation is as follow:

MetaSearch::Where.add :gt_relative_date, :gt_reda,
  :predicate => :gt,
  :types => [:date, :datetime, :timestamp, :time],
  :formatter => Proc.new {|param|
    p "format param => " + param.to_json # debug
    param
  },
  :validator => Proc.new {|param| 
    p "validator param => " + param.to_json # debug
      param.is_a?(Array) && !(param[0].blank? || param[1].blank? || param[2].blank?)
  }

However, I never get passed the validator, and the debug line prints param as null.
I guess I'm missing something or doing something wrong, but I can not find what from the doc.

For the record, here are the parameters from the log:
{"commit"=>"Search", "utf8"=>"✓", "search_title"=>"", "application_table_id"=>"2", "search"=>{"name_contains"=>"", "updated_at_gt_relative_date(1i)"=>"4", "updated_at_gt_relative_date(2i)"=>"0", "created_at_gt_relative_date(1i)"=>"0", "updated_at_gt_relative_date(3i)"=>"0", "created_at_gt_relative_date(2i)"=>"0", "created_at_gt_relative_date(3i)"=>"0", "slug_contains"=>""}}

Search on atribute :status doesn't work

I have several models with a :status attribute.

Including f.input :status in a search form will result in an error
'undefined method 'status' for #MetaSearch::Searches::Transaction:0x0000010361f428

I worked around this by adding an extra scope in my model

     search_methods :state

and calling f.input :state

meta_search breaks thinking_sphinx on Rails 3.1rc1

First of all, thanks for the great gem.

I am getting "Association named 'applications_forums' was not found; perhaps you misspelled it?" errors when trying to reconfigure thinking_sphinx. If meta_search gem has been commented out in Gemfile then configuration process passes without errors.

Stack trace:

https://gist.github.com/1006487

My Gemfile:

gem 'rails', '3.1.0.rc1'
gem 'thinking-sphinx', :git => 'https://github.com/freelancing-god/thinking-sphinx.git', :branch => 'rails3'
gem 'meta_search', :git => 'https://github.com/ernie/meta_search.git'

My models:

class Post < ActiveRecord::Base
  belongs_to :forum

  define_index do
    has forum.applications_forums.application_id
  end
end

class class Forum < ActiveRecord::Base
  has_many :applications_forums
end

class ApplicationsForum < ActiveRecord::Base
  belongs_to :application
  belongs_to :forum
end

Probably, it's an issue of Thinking Sphinx then sorry for bothering you.

Multi-level polymorphic associations cannot be traversed

Is it simply a limitation that multi-level polymorphic associations cannot be traversed? Please find below my use case.

Given:

class Document < ActiveRecord::Base
  belongs_to :documentable, :polymorphic => true
end

class Subject < ActiveRecord::Base
  has_many :documents, :as => :documentable
  belongs_to :program
end

class Program < ActiveRecord::Base
  has_many :subjects
end

When:

Document.search(:documentable_subject_type_program_name_contains => "Query")

Then:

NoMethodError: You have a nil object when you didn't expect it!

Full error: https://gist.github.com/900229

The following works:

Document.search(:documentable_subject_type_program_id_equals => 1)

Thanks for the great gem!

(Nested .includes() Hashes + .where()) + Meta-Search = :(

Hello!

I'm running Rails 3.1.0RC6. The following issue applies to the latest 2-3 releases of Meta-Search, as well as the current git master.

The following use of .includes works great.

User.includes([:conversations])
User.includes(:conversations)
User.includes(:conversations)
User.includes([:tags, :conversations])

Nesting works as expected too.

User.includes([:tags, {:conversations => :messages}])

So does appending a .where() without the nested includes

User.includes([:tags, :conversations]).where(['conversations.id = ?', 1])

however if I combine the last two examples, things go bad

User.includes([:tags, {:conversations => :messages}]).where(['conversations.id = ?', 1])

When I disable Meta-Search, I can run the above without any trouble. It doesn't matter if any of the models have attr_searchable or assoc_searchable called within them.

Here is the backtrace.

/Users/jason/.rvm/gems/ruby-1.9.2-p290/bundler/gems/meta_search-dfdd9c3a9956/lib/meta_search/join_dependency.rb:64:in `build_polymorphic': Association named 'messages' was not found; perhaps you misspelled it? (ActiveRecord::ConfigurationError)
    from /Users/jason/.rvm/gems/ruby-1.9.2-p290/bundler/gems/meta_search-dfdd9c3a9956/lib/meta_search/join_dependency.rb:55:in `block in graft_with_meta_search'
    from /Users/jason/.rvm/gems/ruby-1.9.2-p290/bundler/gems/meta_search-dfdd9c3a9956/lib/meta_search/join_dependency.rb:53:in `each'
    from /Users/jason/.rvm/gems/ruby-1.9.2-p290/bundler/gems/meta_search-dfdd9c3a9956/lib/meta_search/join_dependency.rb:53:in `graft_with_meta_search'
    from /Users/jason/.rvm/gems/ruby-1.9.2-p290/gems/squeel-0.8.8/lib/squeel/adapters/active_record/relation.rb:156:in `build_join_dependency'
    from /Users/jason/.rvm/gems/ruby-1.9.2-p290/gems/squeel-0.8.8/lib/squeel/adapters/active_record/relation.rb:85:in `build_arel'
    from /Users/jason/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0.rc6/lib/active_record/relation/query_methods.rb:167:in `arel'
    from /Users/jason/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0.rc6/lib/active_record/relation.rb:98:in `respond_to?'
    from /Users/jason/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0.rc6/lib/active_record/connection_adapters/abstract/database_statements.rb:8:in `to_sql'
    from /Users/jason/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0.rc6/lib/active_record/connection_adapters/abstract/database_statements.rb:18:in `select_all'
    from /Users/jason/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0.rc6/lib/active_record/connection_adapters/abstract/query_cache.rb:63:in `select_all'
    from /Users/jason/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0.rc6/lib/active_record/relation/finder_methods.rb:205:in `find_with_associations'
    from /Users/jason/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0.rc6/lib/active_record/relation.rb:111:in `to_a'
    from /Users/jason/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0.rc6/lib/active_record/relation.rb:129:in `to_a'
    from /Users/jason/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0.rc6/lib/active_record/relation.rb:436:in `inspect'
        ....

[feature] click sort column header

Would be nice to have a helper that gives simple click sort column headers. This is the only feature from searchlogic I'm missing. SL does this by adding an 'order' to the search param and a missing_method on ascend_by__/descend_by__:

example: foo?search[name_contains]=foo&search[order]=ascend_by_name

Would you be interested in a patch to do something like this? Thoughts?

Thanks,
John

:default_order => :desc not working in 'meta_search', '1.1.0.pre'

Hello

Great gem, thanks so much :)
Im using meta_search with Rails 3.1.0 rc3 which may cause this issue.
meta_where is not installed.

:default_order seems to be ignored.
The default order remains always the same whether you change it to :desc or :asc

Cheers !

View:

Sort by:
<li><%= sort_link @search, :name %></li>
<li><%= sort_link @search, :created_at, "Newest" %></li>
<li><%= sort_link @search, :updated_at, "Last updated", :default_order => :desc %></li>
Contoller:
    @search = Good.search(params[:search])
    @goods = @search.all

checks and named scopes

When using checks or collection_checks with ids in search form with searchable scope, then after form submit, collection_checks method cant determine what values was checked. It's because of the following line in the helpers/form_builder.rb
https://github.com/ernie/meta_search/blob/master/lib/meta_search/helpers/form_builder.rb#L130
It happens because value is integer but the array of ids in contains strings. Thus calling value.to_s insteard of value should fix this issue, but I don't know if it would break other cases.

MetaSearch::Where.add not having same result as the native wheres

To get started with defining custom Wheres, i have reimplemented the default "contains" with a different name.

MetaSearch::Where.add :incloses,
  :predicate => :matches,
  :types => [:string, :text, :binary],
  :formatter => Proc.new {|param| param}


Its in initializers/meta_search.rb as suggested in the docs.
 Also i have used this Where definition from the docs for reference:


 ['contains', 'like', 'matches', {:types => STRINGS, :predicate => :matches, :formatter => '"%#{param}%"'}]

However if i use "incloses" with my model it delivers different results as when i'm using "contains"

<%= f.text_field :name_or_description_incloses %>

Instead of matching partials of a string or text, it only returns a result if the param matches the entire string or text.

Also, i noticed that the constant STRINGS is not found (Rails 3.1.0.rc3, MetaSearch from git) so i had to specify the types manually.

Thanks :)

doens't play well with sunspot

I can't use meta_search in the same project that already have Sunspot, as it will overwrite sunspot default "search" method. There shall be a way to enable/disable per model, as sunspot does.

Using Module#delegate to delegate to non-public methods is deprecated

Using Rails 3.1.0rc6 I get the following deprecation errors while running tests:

DEPRECATION WARNING: Using Module#delegate to delegate to non-public methods is deprecated. Please declare your methods as public if they are going to accessed from other classes. (called from /usr/local/lib/ruby/gems/1.9.1/gems/meta_search-1.1.0.pre2/lib/meta_search/builder.rb:26)

Association in combination with a scope doesn't seem to work

class Customer < ActiveRecord::Base
  has_many :invoices

  scope :whatever
  search_methods :whatever
end

class Invoice < ActiveRecord::Base
  belongs_to :customer
end

An invoice filter form with


doesn't seem to work and fails with

```undefined method `customer_whatever' for #MetaSearch::Searches::Invoice:0x000001091f25c0

undefined method name_contains for #<ActiveRecord::Relation:0x94749fc>

Recently I checked out meta_search and tried implemeting
I am using Ruby: 1.9.2, Rails: 3.0.6 and RubyGem: 1.6.23
I have product model and its columns are name, price..etc
Configured meta_where and meta_search in GemFile

index.html.erb
<%= form_for :search , @search, :url => products_path, :html => {:method => 'get'} do |f| %>


<%= f.label :name_contains %>
<%= f.text_field :name_contains %>


<%= f.submit "Submit"%>
<% end %>

<%=render 'products'%>

def index
@search = Product.search(params[:search])
@products = @search.all
end

I am getting "undefined method name_contains for #ActiveRecord::Relation:0x94749fc" error.

running 'bundle install' says invalid gemfile

This isn't causing any issues in runtime, but is making bundler complain loudly.

...
Using meta_search (0.3.0) from git://github.com/ernie/meta_search.git (at master)

meta_search at /Users/jdell/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/meta_search-89d49504efdda205f4b1878599899fc2d77ba519-master did not have a valid gemspec.
This prevents bundler from installing bins or native extensions, but that may not affect its functionality.
The validation message from Rubygems was:
["lib/meta_search/railtie.rb", "lib/meta_search/searches/base.rb"] are not files
...

dependency version conflicts between a gem's spec, bundler, and gem install

I'm trying to install meta_search-1.1.0.pre2. The gem's spec, bundler, and rubygems each report/install different dependency version requirements.

I have a new rails3 project (here are my rails, ruby, rubygems and installed gem versions), with one new line in my Gemfile:

gem 'meta_search', '1.1.0.pre2'

The meta_search-1.1.0.pre2 page on rubygems.org reports these dependencies:

actionpack ~> 3.1.0.alpha
activerecord ~> 3.1.0.alpha
activesupport ~> 3.1.0.alpha

However, installing it pulls down activesupport and activemodel-3.1.1.rc1:

muldoon@fedora14$ gem install meta_search -v 1.1.0.pre2
Fetching: activesupport-3.1.1.rc1.gem (100%)
Fetching: meta_search-1.1.0.pre2.gem (100%)
Fetching: activemodel-3.1.1.rc1.gem (100%)
Successfully installed activesupport-3.1.1.rc1
Successfully installed meta_search-1.1.0.pre2
Successfully installed activemodel-3.1.1.rc1
3 gems installed

..and bundler reports that meta_search needs activesupport-3.1.0.beta1.

muldoon@fedora14$ bundle update
Fetching source index for http://rubygems.org/
Bundler could not find compatible versions for gem "activesupport":
  In Gemfile:
    rails (= 3.1.0) depends on
      activesupport (= 3.1.0)

    meta_search (= 1.1.0.pre2) depends on
      activesupport (3.1.0.beta1)

Very strange! Have you seen such a thing before? Any suggestions?

thx!
Mike

problem w/vendor'd arel

Running a fresh 'bundle install' using the git meta_search in a clean env will produce:

Updating git://github.com/ernie/meta_search
fatal: reference is not a tree: 42ff84241ce0e9c34116a9810c5bc56401522b49
Unable to checkout '42ff84241ce0e9c34116a9810c5bc56401522b49' in submodule path 'vendor/arel'
An error has occurred in git. Cannot complete bundling.

Why are you vendor'ing arel as a submodule anyway?

Formatting search fields (dates)

Hello,
I'm doing something like this to keep the date format inline with the jQuery date picker:

ETD: From <%= f.text_field :shipment_booking_etd_gteq, {:readonly => '', :class => 'date_picker', :value => @search.shipment_booking_etd_gteq.try(:to_s,:db)} %>

Am I doing it right? It doesn't look very elegant...

Search with multiple words across multiple fields

Is it possible to search for multiple words across multiple fields? Here is an example:
Search is
<%= f.text_field :first_name_or_item_family_name_or_item_family_brand_contains %>
ItemFamily(attrs: name, brand) has many ItemVariant (attrs: first_name)
Lets say I have a record with:
ItemFamily('iphone', 'apple') and a ItemVariant('3GS')
With my current search, i can't search for 'apple iphone', it will not return the record.
Is there a way to tell metasearch to split (and strip) the user input and search any search words ('apple', 'iphone') in any of the searched fields (name, brand, first_name)?

Remove meta_sort Order Indicator

Is there any way to remove the order indicator arrows for meta_sort columns? I searched through the documentation but was unable to determine if it is possible. This would be very helpful in order to implement custom, image based arrows as part of a style applied to the sort_link, sort_link asc, and sort_link desc classes. Thanks in advance for any help/insight on this topic.

Invalid Gemspec

Seems the Gemspec is not properly formated.

Invalid gemspec in [/var/www/apps/<application>/vendor/gems/ruby/1.8/specifications/meta_search-1.1.0.pre2.gemspec]: invalid date format in specification: "2011-07-07 00:00:00.000000000Z"

Error for Rails 3.1 beta

(disclaimer, I know it is beta...)

I get this error with rails 3.1 beta (using the master or beta1 gem):

ActiveRecord::Associations is not missing constant JoinDependency!

This happens on a call to:

@search = Invoice.search params[:search]

Without any search params (so params[:search} is nil)

'contains' should use 'ILIKE' w/ PostgreSQL

I am trying to figure how to make meta_search do a case-insensitive search for postgres (LIKE is case sensitive in pg which is not what you want 99.99% of the time). Because of this fact, SearchLogic uses ILIKE if the adapter is PostgreSQL, otherwise it used LIKE.

Having read through (but not fully understood) meta_search code, it looks like this is further up the food chain in AREL. Any thoughts?

Thanks,
John

Database views not supported?

I have a rails 2 app that uses searchlogic that I am converting to rails 3 and trying to use meta-search. Everything seems to work just fine except when I try to search models that are based upon a database view. I get a variant of the following error when clicking the submit button on the search form:

NoMethodError in ReportsController#action
undefined method `eq' for nil:NilClass

activesupport (3.0.7) lib/active_support/whiny_nil.rb:48:in `method_missing'
meta_search (1.0.5) lib/meta_search/where.rb:106:in `send'
meta_search (1.0.5) lib/meta_search/where.rb:106:in `evaluate'
meta_search (1.0.5) lib/meta_search/where.rb:106:in `map'
meta_search (1.0.5) lib/meta_search/where.rb:106:in `evaluate'
meta_search (1.0.5) lib/meta_search/builder.rb:217:in `set_attribute_method_value'
meta_search (1.0.5) lib/meta_search/builder.rb:138:in `method_missing'
meta_search (1.0.5) lib/meta_search/builder.rb:118:in `send'
meta_search (1.0.5) lib/meta_search/builder.rb:118:in `assign_attributes'
meta_search (1.0.5) lib/meta_search/builder.rb:117:in `each_pair'
meta_search (1.0.5) lib/meta_search/builder.rb:117:in `assign_attributes'
meta_search (1.0.5) lib/meta_search/builder.rb:92:in `build'
meta_search (1.0.5) lib/meta_search/searches/active_record.rb:43:in `search'
activerecord (3.0.7) lib/active_record/associations/association_collection.rb:444:in `send'
activerecord (3.0.7) lib/active_record/associations/association_collection.rb:444:in `method_missing'
activerecord (3.0.7) lib/active_record/base.rb:1122:in `with_scope'
activerecord (3.0.7) lib/active_record/associations/association_proxy.rb:207:in `send'
activerecord (3.0.7) lib/active_record/associations/association_proxy.rb:207:in `with_scope'
activerecord (3.0.7) lib/active_record/associations/association_collection.rb:440:in `method_missing'

The undefined method could be "matches" or "gteq" or whatever condition I am using for a field on the form. I see this on rails 3.0.7, postgresql 8.4, and pg gem 0.11.0.

Is there a simple resolution to this or is it a bit more complicated? I know there are differences in even Rails 2 to Rails 3. For example, using my database view based model in Rails 2 the command "Model.find(1)" works whereas in Rails 3 the same command results in

NoMethodError: undefined method `eq' for nil:NilClass
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-3.0.7/lib/active_support/whiny_nil.rb:48:in `method_missing'
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-3.0.7/lib/active_record/relation/finder_methods.rb:299:in `find_one'
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-3.0.7/lib/active_record/relation/finder_methods.rb:289:in `find_with_ids'
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-3.0.7/lib/active_record/relation/finder_methods.rb:107:in `find'
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-3.0.7/lib/active_record/base.rb:439:in `__send__'
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-3.0.7/lib/active_record/base.rb:439:in `find'
from (irb):3

Interestingly, "Model.find_by_id(1)" works in both Rails 2 and Rails 3.

I would greatly appreciate any guidance in this area.

per_page parameter ignored when defined on model (will_paginate)

Hi Ernie,

I can't get over how great this gem is! Such a time saver and so flexible! :)

I've run into a strange problem with using will_paginate in combination with meta_search. If I define the per_page class attribute like so:

cattr_reader :per_page
@@per_page = 2

and then do a standard search:

@search = Warranty.search(params[:search])
@warranties = @search.paginate(:page => params[:page])

The per_page setting gets ignored. I tried defining the per_page settings in the actual .paginate call and it works well there, so somewhere along the line it's getting filtered out. I've check and confirmed that the per_page class attribute is working on a model that doesn't use meta-search to get the records.

Hope that helps :D

Join table must be a string in a has_and_belongs_to_many association

If you have a join table for an association which is a symbol rather than a string, searching this association fails (sorry, I cant remember the exact error as I have fixed it now !) - the end result was active record trying to downcase a symbol in the count_aliases_from_table_joins method.

Changing the :join_table definition in my model to a string fixed it.

Cheers

Gary

Segmentation faults when used together with Devise

Using meta_search 1.1.0.pre and devise 1.3.4 together in a rails 3.1.0.rc4 app causes random segmentation faults on loading the application (so rails s, rails c, rails g and `rake' etc). See this ruby issue as well, although that might concern multiple different bugs.

Disabling either meta_search or devise makes the problem go away, but does not solve it of course.

NameError: uninitialized constant ActiveRecord::Associations::ClassMethods::JoinDependency

Environment

  • Ruby 1.9.2
  • Rails 3.1.0.rc5
  • meta_search 0.5.4

Steps to reproduce

rails new foo
cd foo
echo "gem 'meta_search'" >> Gemfile
bundle
rails g model bar
rake db:migrate
rails c

Then from the IRB shell:

irb(main):001:0> Bar.search

This results in the following error:

NameError: uninitialized constant ActiveRecord::Associations::ClassMethods::JoinDependency
    from /usr/local/Cellar/ruby/1.9.2-p180/lib/ruby/gems/1.9.1/gems/meta_search-0.5.4/lib/meta_search/builder.rb:151:in `build_join_dependency'
    from /usr/local/Cellar/ruby/1.9.2-p180/lib/ruby/gems/1.9.1/gems/meta_search-0.5.4/lib/meta_search/builder.rb:40:in `initialize'
    from /usr/local/Cellar/ruby/1.9.2-p180/lib/ruby/gems/1.9.1/gems/meta_search-0.5.4/lib/meta_search/searches/active_record.rb:35:in `new'
    from /usr/local/Cellar/ruby/1.9.2-p180/lib/ruby/gems/1.9.1/gems/meta_search-0.5.4/lib/meta_search/searches/active_record.rb:35:in `search'
    from (irb):1
    from /usr/local/Cellar/ruby/1.9.2-p180/lib/ruby/gems/1.9.1/gems/railties-3.1.0.rc5/lib/rails/commands/console.rb:45:in `start'
    from /usr/local/Cellar/ruby/1.9.2-p180/lib/ruby/gems/1.9.1/gems/railties-3.1.0.rc5/lib/rails/commands/console.rb:8:in `start'
    from /usr/local/Cellar/ruby/1.9.2-p180/lib/ruby/gems/1.9.1/gems/railties-3.1.0.rc5/lib/rails/commands.rb:40:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

method "search" conflict with thinking-sphinx

when I use meta_search and thinking-sphinx,the method "search" has a conflict problem,cause the two gem all add the same method to ActiveRecord::Base.
How do I reslove this problem?
Btw,the two gems have their own advantage,so I want to use both of them .

Default scope

Not sure if this is an issue or I'm just doing it wrong...

Can you use default scope with meta, it seems if I do it breaks the function of the sorts? Ex:

default_scope :order => 'created_at DESC'

Is there a way to define a default order if no order is specified?

Thank you

MetaSearch breaks when you click through search result pages

So it turns out that it breaks in this simple case: I search for a record containing "wombat", which changes the url to this:

http://localhost:3000/items?utf8=✓&search%5Btitle_or_keywords_contains%5D=wombat

Then I click to go to the second page of results and I get this:

invalid byte sequence in UTF-8

If I try to paginate my results. This is the url generated:

http://localhost:3000/items?_=1308917894388&page=2&search[title_or_keywords_contains]=wombat&utf8=%E2

For some reason it truncates %E2%9C%93 to %E2, when I try to browse through the search results, causing the error. I've tried both will_paginate and kaminari with the same results.

here's my setup:

#Gemfile
gem "meta_search" 
gem "will_paginate", "~> 3.0.pre2"

#view
= form_for @search, :url => items_path, :html => { :method => :get} do |f|
  = f.label :Filter
  = f.text_field :title_or_keywords_contains

= will_paginate @items

#controller
@search = Item.search(params[:search])
@items = @search.paginate(:page => params[:page])

Invalid gemspec in [D:/Ruby187/lib/ruby/gems/1.8/specifications/meta_search-1.0.

Invalid gemspec in [D:/Ruby187/lib/ruby/gems/1.8/specifications/meta_search-1.0.
6.gemspec]: invalid date format in specification: "2011-07-07 00:00:00.000000000
Z"

When boot my app, i got this error, after google it. Change s.date = %q{2011-07-07 00:00:00.000000000Z} in meta_search-1.0.6.gemspec
to s.date = %q{2011-07-07} solving the problem.

error for Rails 3.1rc1

Hi,

I cannot install last version of meta-search for following reason (bundler message):

In Gemfile:
meta_search (= 1.0.5) depends on
arel (~> 2.0.2)

rails (= 3.1.0.rc1) depends on
  arel (2.1.1)

For this reason, Bundler keeps installing version 0.5.4 which is not compatible with rails 3.1rc1.

Could you fix this? Thank's a lot,

Nicolas.

Stripping leading and trailing spaces in search fields

I'm wondering if it's possible to ask MetaWhere to remove leading and trailing spaces before proceeding with the request.
In my app, I have:
<%= f.text_field :customer_name_contains %>
In the DB, i have a customer with name 'Rick'.
If I search for 'Rick ', the 'Rick' record doesn't come out when it should...

It seems that the search object accepts some kind of options but I don't see any ways of 'striping' the input before hitting the DB.
I could doctor the param but it doesn't feel right.

multiple level associations support

As I start deploying the use of meta_search for most of my dynamic searching requests, I seems like hitting a limit by searching through multiple level of associations.

class Client
  has_many :orders
end

class Order
  has_many :items
end

class Item
  validates_presence_of :description
end

then Client.search(:orders_items_description => 'xxx') return undefined method. Now I can only implement the function using complex scope with lengthy sql statement, and then invoke it through your newly added search_methods. Is there a chance that meta_search can support this kind of search?

Conflict with Cancan

I'm using Cancan and MetaSearch.

I have a index action in a controller that when submitted the field that acts as a constrain in Cancan inhibit the "where" condition that should be placed by MetaSearch. This happens when using scopes with search_methods.

Example:
I do have a model named Area that has a belongs_to relationship with Enterprise and in the ability.rb (rules to Cancan) has a constraint in the field enterprise_id like this:
can :manage, Area, :enterprise_id => Enterprise.where(bla-bla-bla)

In Area model there is a scope named :em with the clause search_methods :em

search_methods :em
scope :em, lambda {|date| where('? between areas.date_begins and areas.date_ends or (? >= areas.date_begins and areas.data_ends is null)', date, date) }

When I try to list Areas in AreasController's :index action selecting a enterprise_id_equals (3) and date equals to '2011-05-20', it should construct a SQL statement like this:

SELECT areas.* FROM areas WHERE areas.enterprise_id IN (3, 4, 6) AND areas.enterprise_id = 3 AND ('2011-05-20' between areas.date_begins and areas.date_ends or ('2011-05-20' >= areas.date_begins and areas.date_ends is null)) ORDER BY classificacao LIMIT 15 OFFSET 0

The condition areas.enterprise_id IN (3, 4, 6) is placed by Cancan. The condition areas.enterprise_id = 3 should be placed by MetaSearch as I selected the Enterprise 3 as filter.

But, what happens is:

SELECT areas.* FROM areas WHERE areas.enterprise_id IN (3, 4, 6) AND ('2011-05-20' between areas.date_begins and areas.date_ends or ('2011-05-20' >= areas.date_begins and areas.date_ends is null)) ORDER BY classificacao LIMIT 15 OFFSET 0

The where clause condition areas.enterprise_id = 3 is not placed in the SQL command, resulting in a no wanted result. Instead of Area of the Enterprise 3, is listed Areas from all Enterprises I do have access.

This happens only when I do use scopes with search_methods.

Best regards.

Polymorphic association + nested association

Given the following classes:

class Discussion < ActiveRecord::Base
    belongs_to :parent, :polymorphic => true
end

class User < ActiveRecord::Base
    has_one :identity
    has_one :discussion, :as => :parent,
end

class Identity < ActiveRecord::Base
    belongs_to :owner,:class_name => "User",:foreign_key => "user_id"
end

Everything works fine if I try to find discussions based on User attributes (e.g. :parent_user_type_id_greather_than).

However when I try to find discussions based on Identity attributes (e.g. :parent_user_type_identity_first_name_like) I get the following error:

You have a nil object when you didn't expect it! You might have
expected an instance of Array. The error occurred while evaluating
nil.[]

The trace :

activerecord (3.0.7) lib/active_record/associations.rb:1936:in `cache_joined_association'
activerecord (3.0.7) lib/active_record/associations.rb:1950:in `build'
meta_search (1.0.6) lib/meta_search/join_dependency.rb:17:in `block in graft_with_metasearch'
meta_search (1.0.6) lib/meta_search/join_dependency.rb:12:in `each'
meta_search (1.0.6) lib/meta_search/join_dependency.rb:12:in `graft_with_metasearch'
activerecord (3.0.7) lib/active_record/relation/query_methods.rb:248:in `build_joins'
activerecord (3.0.7) lib/active_record/relation/query_methods.rb:176:in `build_arel'
activerecord (3.0.7) lib/active_record/relation/query_methods.rb:149:in `arel'
activerecord (3.0.7) lib/active_record/relation.rb:64:in `to_a'
activerecord (3.0.7) lib/active_record/relation/finder_methods.rb:143:in `all'
meta_search (1.0.6) lib/meta_search/builder.rb:26:in `all'
app/controllers/discussions_controller.rb:62:in `load_instance_variables'

Is anything wrong with the way I named the search option or is this a Meta-Search limitation ?

Thanks, D.

Unable to disambiguate tables on search.

Perhaps this is expected behavior, but this doesn't work:

Client.search(params[:search]).includes(:industry).order(sort_column + " " + sort_direction).page(params[:page])

...because it results in ambiguous column error due to the fact that both Client and Industry have a :name column. Keep in mind that sort_column == "industries.name" here.

However, meta_where saves the day, as this works fine:

 Client.where(:name.matches => "%#{params[:search]}%").includes(:industry).order(sort_column + " " + sort_direction).page(params[:page])

Allow both INNER and LEFT OUTER joins

Is it possible to make it configurable whether the queries generated by meta_search use inner joins or left outer joins? Left outer joins can't be optimized for order and it's causing my queries to run much longer than if I force inner joins.

Is it just a matter of making line 260 in builder.rb configurable based on some options?

   @join_dependency.send(:build_with_metasearch, association, parent, Arel::Nodes::OuterJoin, klass)

Thanks

memory leaks in development

Definitions MetaSearch::Searches.for and MetaSearch::Searches::DISPATCH makes memory leaks in development mode.

Example:

class ArticlesController < ApplicationController
  def index
    Article.search nil
    render :text => "Size: #{MetaSearch::Searches::DISPATCH.size}"
  end
end 

First request: "Size: 1"
Second request: "Size: 2"
Third request: "Size: 3"
And so on

Defining MetaSearch::Searches.for and MetaSearch::Searches::DISPATCH as follows helps:

module MetaSearch
  module Searches
    def self.for(klass)
      DISPATCH[klass.name]
    end

    private

    DISPATCH = Hash.new do |hash, klass_name|
      class_name = klass_name.gsub('::', '_')
      hash[klass_name] = module_eval <<-RUBY_EVAL
          class #{class_name} < MetaSearch::Builder
            def self.klass
            ::#{klass_name}
            end
           end
          #{class_name}
      RUBY_EVAL
    end
  end
end

title_or_description_contains_all works different than expected

I am having a Product with :title and :description. To allow users to search in both through one search field, i am using the ORed _or to join the fields.

Also, i am splitting the params of this field into an array to allow users to enter mutliple search terms in a single form. This is why i also append the _all to make sure the results match all terms entered by the user.

_search_form.html.erb
 <%= f.text_field :title_or_description_contains_all %>

products_controller.rb
def index
 p = params[:search][:title_or_description_contains_all].split(' ')
 ...

If the user enters 2 search terms, title_or_description_contains_all will match only results that have both terms in title or both terms in description. It does not deliver results where one term is in title and the other in description.

So the logic i would have expected was

(title_or_description)_contains_all

but instead it seems to do

(title_contains_all) or (description_contains_all)

This may be how arel works so maybe not really an issue of Meta_search. But is there a way how to express this with the existing wheres or would i need to write a custom Where or scope?

Thanks :)

Check arity for scopes

When using a checkbox on a form to include a named scope in a search, the value of the form element is automatically passed to the scope regardless of whether or not the scope requires a parameter. I think that the arity should be checked before passing arguments.

Can scope defined in the model class supported as a search condition?

Just wonder if it is possible to support scope of the base object as search condition. For example,

class Client < ActiveRecord::Base
  scope :full_name_like, lambda {|name| where("clients.surname || '  ' || clients.given_name like ?", "%#{name}%")}
end

so that
Client.search(:gender_eq=>'male', :full_name_like=>'Peter')
is equivalent to
Client.search(:gender_eq=>'male').relation.full_name_like('Peter')

If it is workable then the search form logic can be simplified a lot by just add a text field with name of a scope
<%= form_for :search, @search do |f| %>
<%= f.text_field :gender %>
<%= f.text_field :full_name_like %>
<% end %>

Thanks

Single-table inheritance + Polymorphic association + has_many :through association

I have a complex model design.

Say, the Tag model here uses single-table inheritance for different type of categories. The Tagging model use polymorphic assocation for taggings of different category types as well.

Given the following models:

class Tag < ActiveRecord::Base
end

class PostCategory < Tag
has_many :taggings, :foreign_key => "tag_id"
has_many :posts, :through => :taggings
end

class Tagging < ActiveRecord::Base
belongs_to :taggable, :polymorphic => true

belongs_to :post, :foreign_key => "taggable_id"
belongs_to :post_category, :foreign_key => "tag_id"
end

class Post < ActiveRecord::Base
has_many :taggings, :as => :taggable
has_many :categories, :through => :taggings, :source => :post_category
end

I want to find Posts which category name may contain string like "eat".
e.g. @search = Post.search({:categories_name_contains=>"eat"})

It will return all the posts or none of the posts in database table, depending on whether the search string is contained in any of post category's name.

Is anything wrong with the way I named the search option or is this a Meta-Search limitation ?

Thanks Meta Search! It's a great gem!

Cameo

will_paginate compatibility

I'd like to use this with will_paginate. I found meta_search trying to find a replacement in rails3 for searchlogic. So far, I like it alot, but I need pagination.

Any plans for will_paginate compat? I'm thinking about taking a crack at a patch.

undefined method `amountfine_like' for #<MetaSearch::Searches::Fine:0x29b0d618>

Hello

I have this error when integrate meta_search in application
I using:
meta_search (1.0.6)
rails (3.0.10)
arel (2.0.10)

controller:
@search = Fine.search(params[:search])
@Fines = @search.all

views:
<%= form_for @search do |f| %>
<%= f.label :amountfine %>
<%= f.text_field :amountfine_like %>

<%= f.submit %>
<% end %>

Fine.arel_table
Arel::Table:0x2b519958 @name="fines", @engine=ActiveRecord::Base, @columns=nil, @Aliases=[], @table_alias=nil, @primary_key=nil

Customize sort_link text with arrow symbols

When the ASC and DESC symbols are added to my table headers, they are sometimes added under the header title because of wordwrap. I'd like to be able to join the symbol with a &nbsp so that it doesn't wrap.

Recommend Projects

  • React photo React

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

  • Vue.js photo Vue.js

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

  • Typescript photo Typescript

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

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

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

Recommend Topics

  • javascript

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

  • web

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

  • server

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

  • Machine learning

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

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

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

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.