#113 ✓resolved
Adam Hooper

nested, empty connectives lead to invalid Solr queries

Reported by Adam Hooper | April 29th, 2010 @ 03:30 AM | in Bugs

I'm so strapped for time I can't even produce a valid test case here, but you'll have to trust that This Happens, and from my monkey-patch you should be able to see why. If you need a test case, give me a few days.

I think the problem occurs when creating a search such as "any_of { all_of { any_of { } }; all_of { any_of { } } }", with empty contents. The inner Connectives' "to_boolean_phrase" return nil, but the outer one returns an empty string, since @components.length == 2.

I believe the solution is to eliminate nils before testing @components.length, so that if every component is nil, to_boolean_phrase still returns nil.

Here's my monkey-patch:

module Sunspot
  module Query
    module Connective
      class Abstract
        def to_boolean_phrase #:nodoc:
          unless @components.empty?
            phrase =
              if @components.length == 1
                @components.first.to_boolean_phrase
              else
                component_phrases = @components.map do |component|
                  component.to_boolean_phrase
                end
                component_phrases.compact!
                unless component_phrases.empty?
                  "(#{component_phrases.join(" #{connector} ")})"
                end
              end
            if negated?
              phrase && "-#{phrase}"
            else
              phrase
            end
          end
        end
      end
    end
  end
end

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Awesome Solr interaction for Ruby

People watching this ticket

Referenced by

Pages