Class: Chef::SolrQuery::QueryTransform

Inherits:
Object
  • Object
show all
Defined in:
lib/chef/solr_query/query_transform.rb

Constant Summary collapse

@@base_path =
File.expand_path(File.dirname(__FILE__))
@@parser =
LuceneParser.new

Class Method Summary collapse

Class Method Details

.parse(data) ⇒ Object


35
36
37
38
39
40
41
42
# File 'lib/chef/solr_query/query_transform.rb', line 35

def self.parse(data)
  tree = @@parser.parse(data)
  msg = "Parse error at offset: #{@@parser.index}\n"
  msg += "Reason: #{@@parser.failure_reason}"
  raise Chef::Exceptions::QueryParseError, msg if tree.nil?
  self.clean_tree(tree)
  tree.to_array
end

.transform(data) ⇒ Object


44
45
46
47
48
49
50
51
52
# File 'lib/chef/solr_query/query_transform.rb', line 44

def self.transform(data)
  return "*:*" if data == "*:*"
  tree = @@parser.parse(data)
  msg = "Parse error at offset: #{@@parser.index}\n"
  msg += "Reason: #{@@parser.failure_reason}"
  raise Chef::Exceptions::QueryParseError, msg if tree.nil?
  self.clean_tree(tree)
  tree.transform
end