<commit_before>class Venue < ActiveRecord::Base
  class SearchEngine
    Sql = Struct.new(:query, :opts) do
      def self.search(query, opts={})
        wifi = opts[:wifi]
        include_closed = opts[:include_closed] == true
        limit = opts[:limit] || 50

        scoped_venues = Venue.non_duplicates
        # Pick a subset of venues (we want in_business by default)
        unless include_closed
          scoped_venues = scoped_venues.in_business
        end

        scoped_venues = scoped_venues.with_public_wifi if wifi

        order = \
          case opts[:order].try(:to_sym)
          when nil, :name, :title
            'LOWER(venues.title) ASC'
          else
            raise ArgumentError, "Unknown order: #{order}"
          end

        keywords = query.split
        tag_conditions = Array.new(keywords.size, "LOWER(tags.name) = ?").join(" OR ")
        conditions = ["title LIKE ? OR description LIKE ? OR (#{tag_conditions})", *(["%#{query}%", "%#{query}%"] + keywords) ]
        scoped_venues = scoped_venues.where(conditions) if keywords.any?

        scoped_venues = scoped_venues.joins("LEFT OUTER JOIN taggings on taggings.taggable_id = venues.id AND taggings.taggable_type = 'Venue'",
                                   'LEFT OUTER JOIN tags ON tags.id = taggings.tag_id').order(order).group(Venue.columns.map(&:name).map{|attribute| "venues.#{attribute}"}.join(', ')).limit(limit)
      end
    end
  end
end
<commit_msg>postgres LIKEs are not case-insensitive.<commit_after>class Venue < ActiveRecord::Base
  class SearchEngine
    Sql = Struct.new(:query, :opts) do
      def self.search(query, opts={})
        wifi = opts[:wifi]
        include_closed = opts[:include_closed] == true
        limit = opts[:limit] || 50

        scoped_venues = Venue.non_duplicates
        # Pick a subset of venues (we want in_business by default)
        unless include_closed
          scoped_venues = scoped_venues.in_business
        end

        scoped_venues = scoped_venues.with_public_wifi if wifi

        order = \
          case opts[:order].try(:to_sym)
          when nil, :name, :title
            'LOWER(venues.title) ASC'
          else
            raise ArgumentError, "Unknown order: #{order}"
          end

        keywords = query.split
        like = "%#{query.downcase}%"
        tag_conditions = Array.new(keywords.size, "LOWER(tags.name) = ?").join(" OR ")
        conditions = ["LOWER(title) LIKE ? OR LOWER(description) LIKE ? OR (#{tag_conditions})", *([like, like] + keywords) ]
        scoped_venues = scoped_venues.where(conditions) if keywords.any?

        scoped_venues = scoped_venues.joins("LEFT OUTER JOIN taggings on taggings.taggable_id = venues.id AND taggings.taggable_type = 'Venue'",
                                   'LEFT OUTER JOIN tags ON tags.id = taggings.tag_id').order(order).group(Venue.columns.map(&:name).map{|attribute| "venues.#{attribute}"}.join(', ')).limit(limit)
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.1219758064516129, 'fraction_numerical': 0.0013440860215053765, 'mean_word_length': 2.5567502986857824, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '350368', 'n_tokens_mistral': 948, 'n_tokens_neox': 913, 'n_words': 212}