Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
def parse_google query return unless query # alters google-style querystring into sphinx-style query = query.scan(/[^"\(\) ]*["\(][^"\)]*["\)]|[^"\(\) ]+/) # thanks chris2 query.each_with_index do |token, index| if token =~ /^(.*?)\((.*)\)(.*?$)/ token = query[index] = "#{$1}(#{parse_google $2})#{$3}" # recurse for parens end case token when "OR" query[index] = "|" when "NOT" query[index] = "-#{query[index+1]}" query[index+1] = "" when "AND" query[index] = "" when /:/ query[query.size] = "@" + query[index].sub(":", " ") query[index] = "" end end query.join(" ").squeeze(" ") end
This paste will be private.
From the Design Piracy series on my blog: