summaryrefslogtreecommitdiff
path: root/src/mongo/db/fts/fts_spec.cpp
diff options
context:
space:
mode:
authorBilly Donahue <billy.donahue@mongodb.com>2019-09-24 17:53:21 +0000
committerevergreen <evergreen@mongodb.com>2019-09-24 17:53:21 +0000
commit8e35b7bc673e3bddf7049a44884d79ffb862a77d (patch)
treeee6652569ba87506897f7fedc6f875a605c48034 /src/mongo/db/fts/fts_spec.cpp
parent60518c8920064b30df53129ea880dacfcb04be71 (diff)
downloadmongo-8e35b7bc673e3bddf7049a44884d79ffb862a77d.tar.gz
SERVER-43128 Simplify FTS language registry
Diffstat (limited to 'src/mongo/db/fts/fts_spec.cpp')
-rw-r--r--src/mongo/db/fts/fts_spec.cpp34
1 files changed, 19 insertions, 15 deletions
diff --git a/src/mongo/db/fts/fts_spec.cpp b/src/mongo/db/fts/fts_spec.cpp
index c358ba4b679..aeaacd08e21 100644
--- a/src/mongo/db/fts/fts_spec.cpp
+++ b/src/mongo/db/fts/fts_spec.cpp
@@ -97,17 +97,17 @@ FTSSpec::FTSSpec(const BSONObj& indexInfo) {
// Initialize _defaultLanguage. Note that the FTSLanguage constructor requires
// textIndexVersion, since language parsing is version-specific.
auto indexLanguage = indexInfo["default_language"].String();
- auto swl = FTSLanguage::make(indexLanguage, _textIndexVersion);
-
- // This can fail if the user originally created the text index under an instance of
- // MongoDB that supports different languages then the current instance
- // TODO: consder propagating the index ns to here to improve the error message
- uassert(28682,
- str::stream() << "Unrecognized language " << indexLanguage
- << " found for text index. Verify mongod was started with the"
- " correct options.",
- swl.getStatus().isOK());
- _defaultLanguage = swl.getValue();
+ try {
+ _defaultLanguage = &FTSLanguage::make(indexLanguage, _textIndexVersion);
+ } catch (const DBException& ex) {
+ // This can fail if the user originally created the text index under an instance of
+ // MongoDB that supports different languages then the current instance
+ // TODO: consder propagating the index ns to here to improve the error message
+ uasserted(28682,
+ str::stream() << "Unrecognized language " << indexLanguage
+ << " found for text index. Verify mongod was started with the"
+ " correct options.");
+ }
_languageOverrideField = indexInfo["language_override"].valuestrsafe();
@@ -163,9 +163,11 @@ const FTSLanguage* FTSSpec::_getLanguageToUseV2(const BSONObj& userDoc,
uassert(17261,
"found language override field in document with non-string type",
e.type() == mongo::String);
- StatusWithFTSLanguage swl = FTSLanguage::make(e.String(), getTextIndexVersion());
- uassert(17262, "language override unsupported: " + e.String(), swl.getStatus().isOK());
- return swl.getValue();
+ try {
+ return &FTSLanguage::make(e.String(), getTextIndexVersion());
+ } catch (DBException& ex) {
+ uasserted(17262, "language override unsupported: " + e.String());
+ }
}
void FTSSpec::scoreDocument(const BSONObj& obj, TermFrequencyMap* term_freqs) const {
@@ -439,7 +441,9 @@ StatusWith<BSONObj> FTSSpec::fixSpec(const BSONObj& spec) {
return {ErrorCodes::CannotCreateIndex, "default_language needs a string type"};
}
- if (!FTSLanguage::make(default_language, TEXT_INDEX_VERSION_3).getStatus().isOK()) {
+ try {
+ FTSLanguage::make(default_language, TEXT_INDEX_VERSION_3);
+ } catch (DBException& ex) {
return {ErrorCodes::CannotCreateIndex, "default_language is not valid"};
}