Sha256: 3ab726f1e466360a03ffc8e621863e01412aae1866fe4cd39f3be5dcb81bdcdc

Contents?: true

Size: 788 Bytes

Versions: 10

Compression:

Stored size: 788 Bytes

Contents

require 'thredded/table_sql_builder'

module Thredded
  class TopicSqlBuilder < TableSqlBuilder
    def build_text_search
      if text.present?
        search_text = text
        add_where("to_tsvector('english', t.title) @@ plainto_tsquery('english', ?)", search_text.uniq.join(' '))

        search_text.each do |term|
          if (is_quoted(term))
            add_where('t.title ILIKE ?', term.gsub('"', '%'))
          end
        end
      end
    end

    def build_in_category
      if categories.present?
        add_from('topic_categories tc')
        add_where('tc.topic_id = t.id')
        add_where('tc.category_id in (?)', categories)
      end
    end

    def build_by_user
      if users.present?
        add_where('t.user_id in (?)', users)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
thredded-0.0.12 lib/thredded/topic_sql_builder.rb
thredded-0.0.10 lib/thredded/topic_sql_builder.rb
thredded-0.0.9 lib/thredded/topic_sql_builder.rb
thredded-0.0.8 lib/thredded/topic_sql_builder.rb
thredded-0.0.7 lib/thredded/topic_sql_builder.rb
thredded-0.0.6 lib/thredded/topic_sql_builder.rb
thredded-0.0.5 lib/thredded/topic_sql_builder.rb
thredded-0.0.4 lib/thredded/topic_sql_builder.rb
thredded-0.0.3 lib/thredded/topic_sql_builder.rb
thredded-0.0.1 lib/thredded/topic_sql_builder.rb