class Polecat::IndexSearcher

interface for searching an index

Build on top of an Polecat::IndexReader, this class let’s you search through all documents stored in an index.

Attributes

default_field[R]
reader[R]

Public Class Methods

new(options) click to toggle source

creates a new Polecat::IndexSearcher

Create a new Polecat::IndexSearcher to search documents. Either a path to a directory or a Polecat::IndexReader has to be given, to make this searcher work. @example

# the following has the same meaning
IndexSearcher.new 'index_dir'
IndexSearcher.new(IndexReader.new 'index_dir')
# File lib/polecat/index_searcher.rb, line 19
def initialize options
  if options.has_key? :path
    @reader = Polecat::IndexReader.new(options[:path])
  elsif options.has_key? :reader 
    @reader = options[:reader]
    raise ArgumentError, 'no reader' unless @reader.kind_of?(Polecat::IndexReader)
  end

  if options.has_key? :default_field
    @default_field = options[:default_field]
  end
end

Public Instance Methods

path() click to toggle source

returns the path of the index directory @return [String] path of the index directory

# File lib/polecat/index_searcher.rb, line 34
def path
  @reader.path
end

Private Instance Methods

compare(ival, op, tval) click to toggle source

compare the document value with the searched value

This compares the two values with the operator @return [Any] trueish for matches or falsey @private

# File lib/polecat/index_searcher.rb, line 67
def compare ival, op, tval
  if op == :eq
    if tval.class == Regexp
      ival.match tval
    else
      ival == tval
    end
  elsif op == :gt
    ival < tval
  elsif op == :lt
    ival > tval
  else
    false
  end
end