susumu.yata
null+****@clear*****
Wed Sep 24 13:15:01 JST 2014
susumu.yata 2014-09-24 13:15:01 +0900 (Wed, 24 Sep 2014) New Revision: 926f9f8841875af54f5c563396655564e356e005 https://github.com/groonga/grnxx/commit/926f9f8841875af54f5c563396655564e356e005 Message: Fix a bug of OrMerger. (#66) Modified files: lib/grnxx/merger.cpp Modified: lib/grnxx/merger.cpp (+50 -12) =================================================================== --- lib/grnxx/merger.cpp 2014-09-24 12:39:09 +0900 (f975111) +++ lib/grnxx/merger.cpp 2014-09-24 13:15:01 +0900 (1b9e0cd) @@ -225,10 +225,10 @@ bool OrMerger::finish(Error *error) { const MergerOperatorType operator_type = operator_type_; const bool stream_is_1 = stream_records == input_records_1_; for (Int i = 0; i < stream_records->size(); ++i) { + Record record; + record.row_id = stream_records->get_row_id(i); auto it = filter.find(stream_records->get_row_id(i)); if (it == filter.end()) { - Record record; - record.row_id = stream_records->get_row_id(i); switch (operator_type) { case PLUS_MERGER_OPERATOR: { record.score = stream_records->get_score(i); @@ -267,47 +267,85 @@ bool OrMerger::finish(Error *error) { break; } } - if (!output_records_->push_back(error, record)) { - return false; - } } else { switch (operator_type) { case PLUS_MERGER_OPERATOR: { - it->second += stream_records->get_score(i); + record.score = it->second + stream_records->get_score(i); break; } case MINUS_MERGER_OPERATOR: { if (stream_is_1) { - it->second = stream_records->get_score(i) - it->second; + record.score = stream_records->get_score(i) - it->second; } else { - it->second -= stream_records->get_score(i); + record.score = it->second - stream_records->get_score(i); } + break; } case MULTIPLICATION_MERGER_OPERATOR: { - it->second *= stream_records->get_score(i); + record.score = it->second * stream_records->get_score(i); break; } case LHS_MERGER_OPERATOR: { if (stream_is_1) { - it->second = stream_records->get_score(i); + record.score = stream_records->get_score(i); + } else { + record.score = it->second; } break; } case RHS_MERGER_OPERATOR: { if (!stream_is_1) { - it->second = stream_records->get_score(i); + record.score = stream_records->get_score(i); + } else { + record.score = it->second; } break; } case ZERO_MERGER_OPERATOR: { - it->second = 0.0; + record.score = 0.0; break; } } + filter.erase(it); + } + if (!output_records_->push_back(error, record)) { + return false; } } for (auto it : filter) { + switch (operator_type) { + case PLUS_MERGER_OPERATOR: { + break; + } + case MINUS_MERGER_OPERATOR: { + if (stream_is_1) { + it.second = -it.second; + } + break; + } + case MULTIPLICATION_MERGER_OPERATOR: { + // TODO: I'm not sure if it.second should be used? + it.second = 0.0; + break; + } + case LHS_MERGER_OPERATOR: { + if (stream_is_1) { + it.second = 0.0; + } + break; + } + case RHS_MERGER_OPERATOR: { + if (!stream_is_1) { + it.second = 0.0; + } + break; + } + case ZERO_MERGER_OPERATOR: { + it.second = 0.0; + break; + } + } if (!output_records_->push_back(error, Record(it.first, it.second))) { return false; } -------------- next part -------------- HTML����������������������������...Download