Class: Xapit::Query
- Inherits:
-
Object
- Object
- Xapit::Query
- Defined in:
- lib/xapit/query.rb
Overview
This class wraps a Xapian::Query for convenience purposes. You will likely not need to use this class unless you are trying to query the Xapian database directly. You may be looking for Xapit::Collection instead.
Instance Attribute Summary collapse
-
#default_options ⇒ Object
readonly
Returns the value of attribute default_options.
-
#xapian_query ⇒ Object
readonly
Returns the value of attribute xapian_query.
Instance Method Summary collapse
- #and_query(*args) ⇒ Object
- #count ⇒ Object
-
#initialize(*args) ⇒ Query
constructor
A new instance of Query.
- #matches(options = {}) ⇒ Object
- #matchset(options = {}) ⇒ Object
- #not_query(*args) ⇒ Object
- #or_query(*args) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Query
Returns a new instance of Query.
8 9 10 11 |
# File 'lib/xapit/query.rb', line 8 def initialize(*args) @xapian_query = build_xapian_query(*args) @default_options = { :offset => 0, :sort_descending => false } end |
Instance Attribute Details
#default_options ⇒ Object (readonly)
Returns the value of attribute default_options.
6 7 8 |
# File 'lib/xapit/query.rb', line 6 def @default_options end |
#xapian_query ⇒ Object (readonly)
Returns the value of attribute xapian_query.
6 7 8 |
# File 'lib/xapit/query.rb', line 6 def xapian_query @xapian_query end |
Instance Method Details
#and_query(*args) ⇒ Object
13 14 15 |
# File 'lib/xapit/query.rb', line 13 def and_query(*args) merge_query(:and, *args) end |
#count ⇒ Object
44 45 46 47 |
# File 'lib/xapit/query.rb', line 44 def count # a bit of a hack to get more accurate count estimate @count ||= matchset(:limit => Config.database.doccount).matches_estimated end |
#matches(options = {}) ⇒ Object
40 41 42 |
# File 'lib/xapit/query.rb', line 40 def matches( = {}) matchset().matches end |
#matchset(options = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/xapit/query.rb', line 25 def matchset( = {}) .reverse_merge!() enquire = Xapian::Enquire.new(Config.database) if [:sort_by_values] sorter = Xapian::MultiValueSorter.new [:sort_by_values].each do |sort_value| sorter.add(sort_value, !![:sort_descending]) end enquire.set_sort_by_key_then_relevance(sorter) end enquire.collapse_key = [:collapse_key] if [:collapse_key] enquire.query = @xapian_query enquire.mset([:offset], [:limit]) end |
#not_query(*args) ⇒ Object
21 22 23 |
# File 'lib/xapit/query.rb', line 21 def not_query(*args) merge_query(:not, *args) end |
#or_query(*args) ⇒ Object
17 18 19 |
# File 'lib/xapit/query.rb', line 17 def or_query(*args) merge_query(:or, *args) end |