Sha256: 7db6784ff18c459ce9c988b3e27e96b390c95b924baf8edd06df3b932c321fc4
Contents?: true
Size: 1.29 KB
Versions: 4
Compression:
Stored size: 1.29 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 |node| if node.is_a?(SearchCopGrammar::Nodes::MatchesFulltextNot) visit node else node.nodes.size > 1 ? "+(#{visit node})" : "+#{visit node}" end end res.join " " end def visit_SearchCopGrammar_Nodes_Or_Fulltext(node) node.nodes.collect { |node| "(#{visit 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