changed simple search result

This commit is contained in:
rjawor 2015-08-18 12:23:22 +02:00
parent fa4d34ea5e
commit 2067d1042c
4 changed files with 25 additions and 18 deletions

View File

@ -24,8 +24,10 @@ void SearcherController::simpleSearch(rapidjson::Writer<rapidjson::StringBuffer>
jsonWriter.StartObject(); jsonWriter.StartObject();
jsonWriter.String("id"); jsonWriter.String("id");
jsonWriter.Int(result.getId()); jsonWriter.Int(result.getId());
jsonWriter.String("matchedFragment"); jsonWriter.String("matchedFragmentStart");
jsonWriter.String(result.getMatchedFragment().c_str()); jsonWriter.Int(result.getMatchedFragmentStart());
jsonWriter.String("matchedFragmentEnd");
jsonWriter.Int(result.getMatchedFragmentEnd());
jsonWriter.String("sourceSegment"); jsonWriter.String("sourceSegment");
jsonWriter.String(result.getSourceSegment().c_str()); jsonWriter.String(result.getSourceSegment().c_str());
jsonWriter.String("targetSegment"); jsonWriter.String("targetSegment");

View File

@ -2,11 +2,13 @@
SimpleSearchResult::SimpleSearchResult( SimpleSearchResult::SimpleSearchResult(
const int id, const int id,
const std::string & matchedFragment, const int matchedFragmentStart,
const int matchedFragmentEnd,
const std::string & sourceSegment, const std::string & sourceSegment,
const std::string & targetSegment): const std::string & targetSegment):
_id(id), _id(id),
_matchedFragment(matchedFragment), _matchedFragmentStart(matchedFragmentStart),
_matchedFragmentEnd(matchedFragmentEnd),
_sourceSegment(sourceSegment), _sourceSegment(sourceSegment),
_targetSegment(targetSegment) { _targetSegment(targetSegment) {
} }

View File

@ -8,7 +8,8 @@ public:
/*! Constructor. /*! Constructor.
*/ */
SimpleSearchResult(const int id, SimpleSearchResult(const int id,
const std::string & matchedFragment, const int matchedFragmentStart,
const int matchedFragmentEnd,
const std::string & sourceSegment, const std::string & sourceSegment,
const std::string & targetSegment const std::string & targetSegment
); );
@ -16,12 +17,16 @@ public:
*/ */
virtual ~SimpleSearchResult(); virtual ~SimpleSearchResult();
int & getId() { const int getId() {
return _id; return _id;
} }
const std::string & getMatchedFragment() { const int getMatchedFragmentStart() {
return _matchedFragment; return _matchedFragmentStart;
}
const int getMatchedFragmentEnd() {
return _matchedFragmentEnd;
} }
const std::string & getSourceSegment() { const std::string & getSourceSegment() {
@ -35,7 +40,9 @@ public:
private: private:
int _id; int _id;
std::string _matchedFragment; int _matchedFragmentStart;
int _matchedFragmentEnd;
std::string _sourceSegment; std::string _sourceSegment;

View File

@ -51,20 +51,16 @@ std::vector<SimpleSearchResult> UnitDAO::getSearchResults(std::vector<MatchedPat
connection.startTransaction(); connection.startTransaction();
BOOST_FOREACH(MatchedPatternFragment & fragment, concordiaResults) { BOOST_FOREACH(MatchedPatternFragment & fragment, concordiaResults) {
std::string query = "SELECT id, source_segment, target_segment, substring(source_segment,source_tokens[$1::integer*2+1]+1,source_tokens[$2::integer*2]-source_tokens[$1::integer*2+1]) as matched_fragment FROM unit WHERE id = $3::integer;"; std::string query = "SELECT id, source_segment, target_segment, source_tokens[$1::integer], source_tokens[$2::integer] FROM unit WHERE id = $3::integer;";
std::vector<QueryParam*> params; std::vector<QueryParam*> params;
params.push_back(new IntParam(fragment.getExampleOffset())); params.push_back(new IntParam(2*fragment.getExampleOffset()+1));
params.push_back(new IntParam(fragment.getExampleOffset()+fragment.getMatchedLength())); params.push_back(new IntParam(2*(fragment.getExampleOffset()+fragment.getMatchedLength())));
params.push_back(new IntParam(fragment.getExampleId())); params.push_back(new IntParam(fragment.getExampleId()));
std::stringstream ss;
ss << "example offset: " << fragment.getExampleOffset()
<< ", matched length: " << fragment.getMatchedLength()
<< ", example id: " << fragment.getExampleId();
Logger::log(ss.str());
PGresult * result = connection.execute(query, params); PGresult * result = connection.execute(query, params);
results.push_back(SimpleSearchResult(connection.getIntValue(result,0,0), results.push_back(SimpleSearchResult(connection.getIntValue(result,0,0),
connection.getStringValue(result,0,3), connection.getIntValue(result,0,3),
connection.getIntValue(result,0,4),
connection.getStringValue(result,0,1), connection.getStringValue(result,0,1),
connection.getStringValue(result,0,2))); connection.getStringValue(result,0,2)));
connection.clearResult(result); connection.clearResult(result);