Class: Xapit::SimpleQueryParser

Inherits:
AbstractQueryParser show all
Defined in:
lib/xapit/query_parsers/simple_query_parser.rb

Instance Attribute Summary

Attributes inherited from AbstractQueryParser

#base_query, #member_class

Instance Method Summary collapse

Methods inherited from AbstractQueryParser

#classes, #condition_terms, #current_page, #facet_identifiers, #facet_terms, #initial_query, #initial_query_strings, #initialize, #not_condition_terms, #offset, #per_page, #query, #sort_by_values, #spelling_suggestion, #term_suggestion

Constructor Details

This class inherits a constructor from Xapit::AbstractQueryParser

Instance Method Details

#parsedObject



25
26
27
# File 'lib/xapit/query_parsers/simple_query_parser.rb', line 25

def parsed
  parse(@search_text.downcase)
end

#xapian_query(instructions = nil) ⇒ Object

REFACTORME this is a bit complex for one method…



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/xapit/query_parsers/simple_query_parser.rb', line 4

def xapian_query(instructions = nil)
  instructions ||= parsed
  instructions = [:add, instructions] if instructions.kind_of? String
  operator = (instructions.first == :or ? Xapian::Query::OP_OR : Xapian::Query::OP_AND)
  words = instructions[1..-1].select { |i| i.kind_of? String }
  query = Xapian::Query.new(operator, words) unless words.empty?
  instructions[1..-1].select { |i| i.kind_of? Array }.each do |sub_instructions|
    if sub_instructions.first == :not
      sub_operator = Xapian::Query::OP_AND_NOT
    else
      sub_operator = operator
    end
    if query
      query = Xapian::Query.new(sub_operator, query, xapian_query(sub_instructions))
    else
      query = xapian_query(sub_instructions)
    end
  end
  query
end

#xapian_query_from_text(text) ⇒ Object



29
30
31
# File 'lib/xapit/query_parsers/simple_query_parser.rb', line 29

def xapian_query_from_text(text)
  xapian_query(parse(text.downcase))
end