Class: IndexedSearch::Match::ResultList
- Inherits:
-
Array
- Object
- Array
- IndexedSearch::Match::ResultList
- Defined in:
- lib/indexed_search/match/result_list.rb
Overview
Group of result instances per match types, plus gather data for dealing with them as a group.
Instance Attribute Summary collapse
-
#counts_by_term ⇒ Object
Returns the value of attribute counts_by_term.
-
#counts_by_word ⇒ Object
Returns the value of attribute counts_by_word.
-
#limited_word_map ⇒ Object
Returns the value of attribute limited_word_map.
-
#unlimited_words ⇒ Object
Returns the value of attribute unlimited_words.
-
#word_ids ⇒ Object
Returns the value of attribute word_ids.
Instance Method Summary collapse
-
#initialize(terms, do_all = false) ⇒ ResultList
constructor
A new instance of ResultList.
Constructor Details
#initialize(terms, do_all = false) ⇒ ResultList
Returns a new instance of ResultList.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/indexed_search/match/result_list.rb', line 9 def initialize(terms, do_all=false) # terms left to process (all of them to start with, obviously) terms = Set.new(terms.dup) # result match counts so far per term (none of them to start with, obviously) self.counts_by_term = Hash.new { |hash,key| hash[key] = 0 } # ids that match so far, so we know which ones to skip later when we see them again self.word_ids = Set.new self.counts_by_word = {} self.limited_word_map = {} self.unlimited_words = [] word_scope = IndexedSearch::Word.order('entries_count') IndexedSearch::Match.perform_match_types.each do |match_type| match_klass = IndexedSearch::Match.match_class(match_type) match_klass.new(word_scope.limit(match_klass.matches_reduction_factor), terms).results(do_all).each do |result| if result.empty? self << result if do_all else result.find.each do |id, count, rank, *matches| if self.word_ids.include?(id) result.ignored_because_already_used << id elsif result.term_map[matches[result.matchidx]].any? { |term| self.counts_by_term[term] >= result.limit_reduction_factor } result.reduced_by_limit_reduction_factor = true else self.word_ids << id self.counts_by_word[id] = count self.limited_word_map[id] = rank if rank > 0 self.unlimited_words << id if rank == 0 result.term_map[matches[result.matchidx]].each do |term| result.list_map[term] << id self.counts_by_term[term] += count terms.delete(term) if counts_by_term[term] >= result.type_reduction_factor end end end self << result if do_all || result.list_map.present? return if terms.empty? && ! do_all end # if result not empty end # result loop end # match_type loop end |
Instance Attribute Details
#counts_by_term ⇒ Object
Returns the value of attribute counts_by_term.
8 9 10 |
# File 'lib/indexed_search/match/result_list.rb', line 8 def counts_by_term @counts_by_term end |
#counts_by_word ⇒ Object
Returns the value of attribute counts_by_word.
8 9 10 |
# File 'lib/indexed_search/match/result_list.rb', line 8 def counts_by_word @counts_by_word end |
#limited_word_map ⇒ Object
Returns the value of attribute limited_word_map.
8 9 10 |
# File 'lib/indexed_search/match/result_list.rb', line 8 def limited_word_map @limited_word_map end |
#unlimited_words ⇒ Object
Returns the value of attribute unlimited_words.
8 9 10 |
# File 'lib/indexed_search/match/result_list.rb', line 8 def unlimited_words @unlimited_words end |
#word_ids ⇒ Object
Returns the value of attribute word_ids.
8 9 10 |
# File 'lib/indexed_search/match/result_list.rb', line 8 def word_ids @word_ids end |