Sha256: ee2251161afc9bc0b701cfa72aebabbd82ef8d0f69307f4fd4a66a6c3143e1c9

Contents?: true

Size: 913 Bytes

Versions: 9

Compression:

Stored size: 913 Bytes

Contents

module Thredded
  class PostSqlBuilder < TableSqlBuilder
    def build_text_search
      if text.present?
        search_text = text
        add_from('thredded_posts p')
        add_where('t.id = p.topic_id')
        add_where("to_tsvector('english', p.content) @@ plainto_tsquery('english', ?)", search_text.uniq.join(' '))

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

    def build_in_category
      if categories.present?
        add_from('thredded_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_from 'thredded_posts p'
        add_where('t.id = p.topic_id')
        add_where('p.user_id in (?)', users)
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

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