#112 ✓ resolved
Adam Hooper

Search for empty string

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

If you place a restriction on a String field stipulating that it should be empty, a nasty Solr error comes back because the query includes 'fq=field_name_ss:'.

The solution: Make it say 'fq=field_name_ss:[*+TO+""]'

In my Rails project, I put the following monkey-patch in config/initializers/fix_sunspot_equal_to_empty_string:

module Sunspot

module Query
  module Restriction
    class EqualTo
      def to_positive_boolean_phrase
        if @value == ''
          "#{escape(@field.indexed_name)}:[* TO \"\"]"
        elsif !@value.nil?
          super
        else
          "#{escape(@field.indexed_name)}:[* TO *]"
        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

Tags

Referenced by

Pages