Sha256: e3a4662c7c820f2ef95087b385a757cd592e8d5d923417f54b37a962be4b60a4

Contents?: true

Size: 1.34 KB

Versions: 4

Compression:

Stored size: 1.34 KB

Contents

module SearchCop
  module Visitors
    module Mysql
      class FulltextQuery < Visitor
        def visit_SearchCopGrammar_Nodes_MatchesFulltextNot(node)
          node.right.split(/[\s+'"<>()~-]+/).collect { |word| "-#{word}" }.join(" ")
        end

        def visit_SearchCopGrammar_Nodes_MatchesFulltext(node)
          words = node.right.split(/[\s+'"<>()~-]+/)

          words.size > 1 ? "\"#{words.join " "}\"" : words.first
        end

        def visit_SearchCopGrammar_Nodes_And_Fulltext(node)
          res = node.nodes.collect do |child_node|
            if child_node.is_a?(SearchCopGrammar::Nodes::MatchesFulltextNot)
              visit child_node
            else
              child_node.nodes.size > 1 ? "+(#{visit child_node})" : "+#{visit child_node}"
            end
          end

          res.join " "
        end

        def visit_SearchCopGrammar_Nodes_Or_Fulltext(node)
          node.nodes.collect { |child_node| "(#{visit child_node})" }.join(" ")
        end
      end

      def visit_SearchCopGrammar_Attributes_Collection(node)
        node.attributes.collect { |attribute| visit attribute }.join(", ")
      end

      def visit_SearchCopGrammar_Nodes_FulltextExpression(node)
        "MATCH(#{visit node.collection}) AGAINST(#{visit FulltextQuery.new(connection).visit(node.node)} IN BOOLEAN MODE)"
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
search_cop-1.1.0 lib/search_cop/visitors/mysql.rb
search_cop-1.0.9 lib/search_cop/visitors/mysql.rb
search_cop-1.0.8 lib/search_cop/visitors/mysql.rb
search_cop-1.0.7 lib/search_cop/visitors/mysql.rb