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.String("id");
jsonWriter.Int(result.getId());
jsonWriter.String("matchedFragment");
jsonWriter.String(result.getMatchedFragment().c_str());
jsonWriter.String("matchedFragmentStart");
jsonWriter.Int(result.getMatchedFragmentStart());
jsonWriter.String("matchedFragmentEnd");
jsonWriter.Int(result.getMatchedFragmentEnd());
jsonWriter.String("sourceSegment");
jsonWriter.String(result.getSourceSegment().c_str());
jsonWriter.String("targetSegment");

View File

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

View File

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

View File

@ -51,20 +51,16 @@ std::vector<SimpleSearchResult> UnitDAO::getSearchResults(std::vector<MatchedPat
connection.startTransaction();
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;
params.push_back(new IntParam(fragment.getExampleOffset()));
params.push_back(new IntParam(fragment.getExampleOffset()+fragment.getMatchedLength()));
params.push_back(new IntParam(2*fragment.getExampleOffset()+1));
params.push_back(new IntParam(2*(fragment.getExampleOffset()+fragment.getMatchedLength())));
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);
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,2)));
connection.clearResult(result);