Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Tidy up some methods #205

Merged
merged 9 commits into from

2 participants

Ben Woosley Ben Moss
Ben Woosley

Hey I was just poking around and I saw some t's to cross and so on.

Most significant changes were reworking control flow such that we don't need Scope::NONE, and removing unused arguments to DSL::FieldGroup and Search::FieldGroup.

Nothing I did should change the internal function of the library, and the tests run green except for an error related to posts_helper in sunspot-rails 2.3.14.

Ben Moss benmoss merged commit aad60f0 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
4 sunspot/lib/sunspot/dsl/field_group.rb
View
@@ -1,8 +1,8 @@
module Sunspot
module DSL
class FieldGroup
- def initialize(query, setup, group)
- @query, @setup, @group = query, setup, group
+ def initialize(setup, group)
+ @setup, @group = setup, group
end
#
2  sunspot/lib/sunspot/dsl/field_query.rb
View
@@ -79,7 +79,7 @@ def group(*field_names, &block)
if block
Sunspot::Util.instance_eval_or_call(
- FieldGroup.new(@query, @setup, group),
+ FieldGroup.new(@setup, group),
&block
)
end
19 sunspot/lib/sunspot/dsl/scope.rb
View
@@ -8,8 +8,6 @@ module DSL #:nodoc:
# allows operations on specific fields.
#
class Scope
- NONE = Object.new
-
def initialize(scope, setup) #:nodoc:
@scope, @setup = scope, setup
end
@@ -193,20 +191,19 @@ def add_restriction(negated, *args)
case args.first
when String, Symbol
raise ArgumentError if args.length > 2
- field_name = args[0]
- value = args.length > 1 ? args[1] : NONE
- if value == NONE
- DSL::Restriction.new(@setup.field(field_name.to_sym), @scope, negated)
- else
- @scope.add_shorthand_restriction(negated, @setup.field(field_name.to_sym), value)
+ field = @setup.field(args[0].to_sym)
+ if args.length > 1
+ value = args[1]
+ @scope.add_shorthand_restriction(negated, field, value)
+ else # NONE
+ DSL::Restriction.new(field, @scope, negated)
end
- else
- instances = args.flatten
+ else # args are instances
@scope.add_restriction(
negated,
IdField.instance,
Sunspot::Query::Restriction::AnyOf,
- instances.flatten.map { |instance|
+ args.flatten.map { |instance|
Sunspot::Adapters::InstanceAdapter.adapt(instance).index_id }
)
end
7 sunspot/lib/sunspot/dsl/standard_query.rb
View
@@ -108,10 +108,9 @@ def fulltext(keywords, options = {}, &block)
def with(*args)
case args.first
when String, Symbol
- field_name = args[0]
- value = args.length > 1 ? args[1] : Scope::NONE
- if value == Scope::NONE
- return DSL::RestrictionWithNear.new(@setup.field(field_name.to_sym), @scope, @query, false)
+ if args.length == 1 # NONE
+ field = @setup.field(args[0].to_sym)
+ return DSL::RestrictionWithNear.new(field, @scope, @query, false)
end
end
4 sunspot/lib/sunspot/search/abstract_search.rb
View
@@ -208,8 +208,8 @@ def inspect #:nodoc:
"<Sunspot::Search:#{query.to_params.inspect}>"
end
- def add_field_group(field, options = {}) #:nodoc:
- add_group(field.name, FieldGroup.new(field, self, options))
+ def add_field_group(field) #:nodoc:
+ add_group(field.name, FieldGroup.new(field, self))
end
def add_field_facet(field, options = {}) #:nodoc:
12 sunspot/lib/sunspot/search/field_group.rb
View
@@ -1,17 +1,15 @@
module Sunspot
module Search
class FieldGroup
- def initialize(field, search, options) #:nodoc:
- @field, @search, @options = field, search, options
+ def initialize(field, search) #:nodoc:
+ @field, @search = field, search
end
def groups
@groups ||=
- begin
- if solr_response
- solr_response['groups'].map do |group|
- Group.new(group['groupValue'], group['doclist'], @search)
- end
+ if solr_response
+ solr_response['groups'].map do |group|
+ Group.new(group['groupValue'], group['doclist'], @search)
end
end
end
Something went wrong with that request. Please try again.