Class: Ferret::Search::MultiPhraseQuery::MultiPhraseWeight
- Includes:
- Index
- Defined in:
- lib/ferret/search/multi_phrase_query.rb
Instance Attribute Summary collapse
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #explain(reader, doc) ⇒ Object
-
#initialize(query, searcher) ⇒ MultiPhraseWeight
constructor
A new instance of MultiPhraseWeight.
- #normalize(query_norm) ⇒ Object
- #scorer(reader) ⇒ Object
- #sum_of_squared_weights ⇒ Object
Constructor Details
#initialize(query, searcher) ⇒ MultiPhraseWeight
Returns a new instance of MultiPhraseWeight.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/ferret/search/multi_phrase_query.rb', line 60 def initialize(query, searcher) @query = query @term_arrays = query.term_arrays @positions = query.positions @similarity = query.similarity(searcher) @idf = 0.0 # compute idf query.term_arrays.each do |terms| terms.each do |term| @idf += @similarity.idf_term(term, searcher) end end end |
Instance Attribute Details
#query ⇒ Object (readonly)
Returns the value of attribute query.
58 59 60 |
# File 'lib/ferret/search/multi_phrase_query.rb', line 58 def query @query end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
58 59 60 |
# File 'lib/ferret/search/multi_phrase_query.rb', line 58 def value @value end |
Instance Method Details
#explain(reader, doc) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/ferret/search/multi_phrase_query.rb', line 111 def explain(reader, doc) result = Explanation.new() result.description = "weight(#{@query} in #{doc}), product of:" idf_expl = Explanation.new(@idf, "idf(#{@query})") # explain query weight query_expl = Explanation.new() query_expl.description = "query_weight(#{@query}), product of:" boost_expl = Explanation.new(@query.boost(), "boost") (query_expl << boost_expl) if (@query.boost() != 1.0) query_expl << idf_expl query_norm_expl = Explanation.new(@query_norm,"query_norm") query_expl << query_norm_expl query_expl.value = boost_expl.value * idf_expl.value * query_norm_expl.value result << query_expl # explain field weight field_expl = Explanation.new() field_expl.description = "field_weight(#{@query} in #{doc}), product of:" tf_expl = scorer(reader).explain(doc) field_expl << tf_expl field_expl << idf_expl field_norm_expl = Explanation.new() field_norms = reader.get_norms(@query.field) field_norm = field_norms ? Similarity.decode_norm(field_norms[doc]) : 0.0 field_norm_expl.value = field_norm field_norm_expl.description = "field_norm(field=#{@query.field}, doc=#{doc})" field_expl << field_norm_expl field_expl.value = tf_expl.value * idf_expl.value * field_norm_expl.value result << field_expl if (query_expl.value == 1.0) return field_expl else result.value = query_expl.value * field_expl.value return result end end |
#normalize(query_norm) ⇒ Object
80 81 82 83 84 |
# File 'lib/ferret/search/multi_phrase_query.rb', line 80 def normalize(query_norm) @query_norm = query_norm @query_weight *= query_norm # normalize query weight @value = @query_weight * @idf # idf for document end |
#scorer(reader) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/ferret/search/multi_phrase_query.rb', line 86 def scorer(reader) return nil if (@term_arrays.size == 0) # optimize zero-term case tps = [] @term_arrays.each do |terms| p = [] if (terms.length > 1) p = MultipleTermDocPosEnum.new(reader, terms) else p = reader.term_positions_for(terms[0]) end return nil if (p == nil) tps << p end if (@query.slop == 0) return ExactPhraseScorer.new(self, tps, @positions, @similarity, reader.get_norms(@query.field)) else return SloppyPhraseScorer.new(self, tps, @positions, @similarity, @query.slop, reader.get_norms(@query.field)) end end |
#sum_of_squared_weights ⇒ Object
75 76 77 78 |
# File 'lib/ferret/search/multi_phrase_query.rb', line 75 def sum_of_squared_weights() @query_weight = @idf * @query.boost() # compute query weight return @query_weight * @query_weight # square it end |