Class: RSI::TermQuery

Inherits:
Query
  • Object
show all
Defined in:
lib/rsi/query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Query

#add_subquery

Methods included from Loggable

#logger

Constructor Details

#initialize(field, term) ⇒ TermQuery

Returns a new instance of TermQuery.



60
61
62
63
# File 'lib/rsi/query.rb', line 60

def initialize( field, term )
  @field = field
  @term = term
end

Instance Attribute Details

#fieldObject

Returns the value of attribute field.



59
60
61
# File 'lib/rsi/query.rb', line 59

def field
  @field
end

#termObject

Returns the value of attribute term.



59
60
61
# File 'lib/rsi/query.rb', line 59

def term
  @term
end

Instance Method Details

#evaluate(locator) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/rsi/query.rb', line 64

def evaluate( locator )
  logger.debug( "Getting dict for #@field" )
  dict = locator.get_dict_for_field( @field )
  # get all docids containing @field:@term -> []
  # return set
  unless dict.has_term?( term )
    logger.debug( "Dict has no such term #{term}" )
    return []
  else
    ret = []
    termid = dict.get_termid_for( term )
    logger.debug( "Getting entries for #{term}(#{termid})" )
    dict.get_entry_list( termid ).each do |termentry|
      logger.debug( termentry.to_s )
      ret << termentry.docid
    end
    return ret.uniq
  end
end

#to_sObject



83
84
85
# File 'lib/rsi/query.rb', line 83

def to_s
  return "#@field='#@term'"
end