lib/scoped_search/definition.rb in scoped_search-2.4.1 vs lib/scoped_search/definition.rb in scoped_search-2.5.0

- old
+ new

@@ -151,14 +151,12 @@ @fields = {} @unique_fields = [] @profile_fields = {:default => {}} @profile_unique_fields = {:default => []} - register_named_scope! unless klass.respond_to?(:search_for) register_complete_for! unless klass.respond_to?(:complete_for) - end attr_accessor :profile, :default_order def fields @@ -183,29 +181,29 @@ # this method is used by the syntax auto completer to suggest operators. def operator_by_field_name(name) field = field_by_name(name) return [] if field.nil? - return field.operators if field.operators - return ['= ', '!= '] if field.set? - return ['= ', '> ', '< ', '<= ', '>= ','!= ', '^ ', '!^ '] if field.numerical? - return ['= ', '!= ', '~ ', '!~ ', '^ ', '!^ '] if field.textual? - return ['= ', '> ', '< '] if field.temporal? + return field.operators if field.operators + return ['= ', '!= '] if field.set? + return ['= ', '> ', '< ', '<= ', '>= ','!= ', '^ ', '!^ '] if field.numerical? + return ['= ', '!= ', '~ ', '!~ ', '^ ', '!^ '] if field.textual? + return ['= ', '> ', '< '] if field.temporal? raise ScopedSearch::QueryNotSupported, "could not verify '#{name}' type, this can be a result of a definition error" end NUMERICAL_REGXP = /^\-?\d+(\.\d+)?$/ INTEGER_REGXP = /^\-?\d+$/ # Returns a list of appropriate fields to search in given a search keyword and operator. def default_fields_for(value, operator = nil) column_types = [] - column_types += [:string, :text] if [nil, :like, :unlike, :ne, :eq].include?(operator) - column_types += [:double, :float, :decimal] if value =~ NUMERICAL_REGXP - column_types += [:integer] if value =~ INTEGER_REGXP - column_types += [:datetime, :date, :timestamp] if (parse_temporal(value)) + column_types += [:string, :text] if [nil, :like, :unlike, :ne, :eq].include?(operator) + column_types += [:double, :float, :decimal] if value =~ NUMERICAL_REGXP + column_types += [:integer] if value =~ INTEGER_REGXP + column_types += [:datetime, :date, :timestamp] if (parse_temporal(value)) default_fields.select { |field| column_types.include?(field.type) && !field.set? } end # Try to parse a string as a datetime. @@ -244,9 +242,20 @@ @klass.scope(:search_for, lambda { |*args| find_options = ScopedSearch::QueryBuilder.build_query(self, args[0], args[1]) search_scope = @klass.scoped search_scope = search_scope.where(find_options[:conditions]) if find_options[:conditions] search_scope = search_scope.includes(find_options[:include]) if find_options[:include] + search_scope = search_scope.joins(find_options[:joins]) if find_options[:joins] + search_scope = search_scope.reorder(find_options[:order]) if find_options[:order] + search_scope + }) + when 4 + @klass.scope(:search_for, lambda { |*args| + find_options = ScopedSearch::QueryBuilder.build_query(self, args[0], args[1]) + search_scope = @klass.all + search_scope = search_scope.where(find_options[:conditions]) if find_options[:conditions] + search_scope = search_scope.includes(find_options[:include]) if find_options[:include] + search_scope = search_scope.references(find_options[:include]) if find_options[:include] search_scope = search_scope.joins(find_options[:joins]) if find_options[:joins] search_scope = search_scope.reorder(find_options[:order]) if find_options[:order] search_scope }) else