changed format for lexicon search result

This commit is contained in:
rjawor 2017-10-10 17:27:45 +02:00
parent 58406809e7
commit 2946cce274
3 changed files with 21 additions and 1 deletions

View File

@ -59,3 +59,19 @@ void JsonGenerator::writeSimpleSearchResult(rapidjson::Writer<rapidjson::StringB
jsonWriter.EndObject(); //simple search result
}
void JsonGenerator::writeLexiconSearchResult(rapidjson::Writer<rapidjson::StringBuffer> & jsonWriter,
const SimpleSearchResult & result) {
jsonWriter.StartArray();
BOOST_FOREACH(ExampleOccurence occurence, result.getOccurences()) {
jsonWriter.StartObject();
jsonWriter.String("sourceSegment");
jsonWriter.String(occurence.getSourceSegment().c_str());
jsonWriter.String("targetSegment");
jsonWriter.String(occurence.getTargetSegment().c_str());
jsonWriter.EndObject(); // occurence
}
jsonWriter.EndArray(); //simple search result
}

View File

@ -22,6 +22,10 @@ public:
static void writeSimpleSearchResult(rapidjson::Writer<rapidjson::StringBuffer> & jsonWriter,
const SimpleSearchResult & result);
static void writeLexiconSearchResult(rapidjson::Writer<rapidjson::StringBuffer> & jsonWriter,
const SimpleSearchResult & result);
private:
};

View File

@ -52,7 +52,7 @@ void SearcherController::lexiconSearch(rapidjson::Writer<rapidjson::StringBuffer
jsonWriter.String("status");
jsonWriter.String("success");
jsonWriter.String("result");
JsonGenerator::writeSimpleSearchResult(jsonWriter, result);
JsonGenerator::writeLexiconSearchResult(jsonWriter, result);
jsonWriter.EndObject();
} else {
JsonGenerator::signalError(jsonWriter, "no such tm!");