Class: SearchCop::Visitors::Mysql::FulltextQuery

Inherits:
Visitor
  • Object
show all
Defined in:
lib/search_cop/visitors/mysql.rb

Instance Attribute Summary

Attributes inherited from Visitor

#connection

Instance Method Summary collapse

Methods inherited from Visitor

#initialize, #quote, #quote_column_name, #quote_table_name, #visit, #visit_SearchCopGrammar_Nodes_And, #visit_SearchCopGrammar_Nodes_Equality, #visit_SearchCopGrammar_Nodes_Generator, #visit_SearchCopGrammar_Nodes_GreaterThan, #visit_SearchCopGrammar_Nodes_GreaterThanOrEqual, #visit_SearchCopGrammar_Nodes_LessThan, #visit_SearchCopGrammar_Nodes_LessThanOrEqual, #visit_SearchCopGrammar_Nodes_Matches, #visit_SearchCopGrammar_Nodes_Not, #visit_SearchCopGrammar_Nodes_NotEqual, #visit_SearchCopGrammar_Nodes_Or, #visit_attribute

Constructor Details

This class inherits a constructor from SearchCop::Visitors::Visitor

Instance Method Details

#visit_SearchCopGrammar_Nodes_And_Fulltext(node) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/search_cop/visitors/mysql.rb', line 21

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

#visit_SearchCopGrammar_Nodes_MatchesFulltext(node) ⇒ Object



15
16
17
18
19
# File 'lib/search_cop/visitors/mysql.rb', line 15

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

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

#visit_SearchCopGrammar_Nodes_MatchesFulltextNot(node) ⇒ Object



11
12
13
# File 'lib/search_cop/visitors/mysql.rb', line 11

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

#visit_SearchCopGrammar_Nodes_Or_Fulltext(node) ⇒ Object



33
34
35
# File 'lib/search_cop/visitors/mysql.rb', line 33

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