lib/scoped_search.rb in wvanbergen-scoped_search-0.1.2 vs lib/scoped_search.rb in wvanbergen-scoped_search-0.1.3
- old
+ new
@@ -1,11 +1,13 @@
-
-
module ScopedSearch
module ClassMethods
+ def self.extended(base)
+ require 'scoped_search/query_language_parser'
+ end
+
# Creates a named scope in the class it was called upon
def searchable_on(*fields)
self.cattr_accessor :scoped_search_fields
self.scoped_search_fields = fields
self.named_scope :search_for, lambda { |keywords| self.build_scoped_search_conditions(keywords) }
@@ -18,13 +20,12 @@
if search_string.nil? || search_string.strip.blank?
return { :conditions => nil }
else
conditions = []
query_params = {}
- class << search_string; include ScopedSearch::QueryStringParser; end # TODO: fix me!
-
- search_string.to_search_query.each_with_index do |search_condition, index|
+
+ QueryLanguageParser.parse(search_string).each_with_index do |search_condition, index|
keyword_name = "keyword_#{index}".to_sym
query_params[keyword_name] = "%#{search_condition.first}%"
# a keyword may be found in any of the provided fields, so join the conitions with OR
if search_condition.length == 2 && search_condition.last == :not
@@ -47,7 +48,6 @@
end
end
end
end
-require 'scoped_search/query_string_parser'
ActiveRecord::Base.send(:extend, ScopedSearch::ClassMethods)
\ No newline at end of file