summaryrefslogtreecommitdiff
path: root/src/mongo/db/fts
diff options
context:
space:
mode:
authorMark Benvenuto <mark.benvenuto@mongodb.com>2015-10-12 18:50:25 -0400
committerMark Benvenuto <mark.benvenuto@mongodb.com>2015-10-22 20:18:00 -0400
commit4c38ff13739e60d33d52b0c944d55249e7d9cc68 (patch)
tree418c999e71a795cebf5fd10eb49e9f36d7dece41 /src/mongo/db/fts
parentd10f7021460e8166a7294170451d91da42b5cc70 (diff)
downloadmongo-4c38ff13739e60d33d52b0c944d55249e7d9cc68.tar.gz
SERVER-20888: Defer $language check to FTSQuery::Parse
Diffstat (limited to 'src/mongo/db/fts')
-rw-r--r--src/mongo/db/fts/fts_matcher_test.cpp22
-rw-r--r--src/mongo/db/fts/fts_query.cpp17
-rw-r--r--src/mongo/db/fts/fts_query.h10
-rw-r--r--src/mongo/db/fts/fts_query_test.cpp51
4 files changed, 44 insertions, 56 deletions
diff --git a/src/mongo/db/fts/fts_matcher_test.cpp b/src/mongo/db/fts/fts_matcher_test.cpp
index 246510a9e70..7694732e2e1 100644
--- a/src/mongo/db/fts/fts_matcher_test.cpp
+++ b/src/mongo/db/fts/fts_matcher_test.cpp
@@ -38,7 +38,7 @@ namespace fts {
TEST(FTSMatcher, NegWild1) {
FTSQuery q;
- ASSERT_OK(q.parse("foo -bar", "english", false, false, TEXT_INDEX_VERSION_3));
+ q.parse("foo -bar", "english", false, false, TEXT_INDEX_VERSION_3);
FTSMatcher m(q,
FTSSpec(FTSSpec::fixSpec(BSON("key" << BSON("$**"
<< "text")))));
@@ -52,7 +52,7 @@ TEST(FTSMatcher, NegWild1) {
// Regression test for SERVER-11994.
TEST(FTSMatcher, NegWild2) {
FTSQuery q;
- ASSERT_OK(q.parse("pizza -restaurant", "english", false, false, TEXT_INDEX_VERSION_3));
+ q.parse("pizza -restaurant", "english", false, false, TEXT_INDEX_VERSION_3);
FTSMatcher m(q,
FTSSpec(FTSSpec::fixSpec(BSON("key" << BSON("$**"
<< "text")))));
@@ -65,7 +65,7 @@ TEST(FTSMatcher, NegWild2) {
TEST(FTSMatcher, Phrase1) {
FTSQuery q;
- ASSERT_OK(q.parse("foo \"table top\"", "english", false, false, TEXT_INDEX_VERSION_3));
+ q.parse("foo \"table top\"", "english", false, false, TEXT_INDEX_VERSION_3);
FTSMatcher m(q,
FTSSpec(FTSSpec::fixSpec(BSON("key" << BSON("$**"
<< "text")))));
@@ -87,7 +87,7 @@ TEST(FTSMatcher, Phrase1) {
TEST(FTSMatcher, Phrase2) {
FTSQuery q;
- ASSERT_OK(q.parse("foo \"table top\"", "english", false, false, TEXT_INDEX_VERSION_3));
+ q.parse("foo \"table top\"", "english", false, false, TEXT_INDEX_VERSION_3);
FTSMatcher m(q,
FTSSpec(FTSSpec::fixSpec(BSON("key" << BSON("x"
<< "text")))));
@@ -98,7 +98,7 @@ TEST(FTSMatcher, Phrase2) {
// language.
TEST(FTSMatcher, ParsesUsingDocLanguage) {
FTSQuery q;
- ASSERT_OK(q.parse("-glad", "none", false, false, TEXT_INDEX_VERSION_3));
+ q.parse("-glad", "none", false, false, TEXT_INDEX_VERSION_3);
FTSMatcher m(q,
FTSSpec(FTSSpec::fixSpec(BSON("key" << BSON("x"
<< "text")))));
@@ -112,7 +112,7 @@ TEST(FTSMatcher, ParsesUsingDocLanguage) {
// Test the matcher does not filter out stop words from positive terms
TEST(FTSMatcher, MatcherDoesNotFilterStopWordsNeg) {
FTSQuery q;
- ASSERT_OK(q.parse("-the", "none", false, false, TEXT_INDEX_VERSION_3));
+ q.parse("-the", "none", false, false, TEXT_INDEX_VERSION_3);
FTSMatcher m(q,
FTSSpec(FTSSpec::fixSpec(BSON("key" << BSON("x"
<< "text")))));
@@ -124,7 +124,7 @@ TEST(FTSMatcher, MatcherDoesNotFilterStopWordsNeg) {
// Test the matcher does not filter out stop words from negative terms
TEST(FTSMatcher, MatcherDoesNotFilterStopWordsPos) {
FTSQuery q;
- ASSERT_OK(q.parse("the", "none", false, false, TEXT_INDEX_VERSION_3));
+ q.parse("the", "none", false, false, TEXT_INDEX_VERSION_3);
FTSMatcher m(q,
FTSSpec(FTSSpec::fixSpec(BSON("key" << BSON("x"
<< "text")))));
@@ -137,7 +137,7 @@ TEST(FTSMatcher, MatcherDoesNotFilterStopWordsPos) {
// case-sensitive text query 'search'.
static bool docHasPositiveTermWithCase(const std::string& doc, const std::string& search) {
FTSQuery q;
- ASSERT_OK(q.parse(search, "english", true, false, TEXT_INDEX_VERSION_3));
+ q.parse(search, "english", true, false, TEXT_INDEX_VERSION_3);
FTSMatcher m(q,
FTSSpec(FTSSpec::fixSpec(BSON("key" << BSON("x"
<< "text")))));
@@ -164,7 +164,7 @@ TEST(FTSMatcher, HasPositiveTermCaseSensitive) {
// case-sensitive text query 'search'.
static bool docHasNegativeTermWithCase(const std::string& doc, const std::string& search) {
FTSQuery q;
- ASSERT_OK(q.parse(search, "english", true, false, TEXT_INDEX_VERSION_3));
+ q.parse(search, "english", true, false, TEXT_INDEX_VERSION_3);
FTSMatcher m(q,
FTSSpec(FTSSpec::fixSpec(BSON("key" << BSON("x"
<< "text")))));
@@ -191,7 +191,7 @@ TEST(FTSMatcher, HasNegativeTermCaseSensitive) {
// from case-sensitive text query 'search'.
static bool docPositivePhrasesMatchWithCase(const std::string& doc, const std::string& search) {
FTSQuery q;
- ASSERT_OK(q.parse(search, "english", true, false, TEXT_INDEX_VERSION_3));
+ q.parse(search, "english", true, false, TEXT_INDEX_VERSION_3);
FTSMatcher m(q,
FTSSpec(FTSSpec::fixSpec(BSON("key" << BSON("x"
<< "text")))));
@@ -214,7 +214,7 @@ TEST(FTSMatcher, PositivePhrasesMatchWithCase) {
// from case-sensitive text query 'search'.
static bool docNegativePhrasesMatchWithCase(const std::string& doc, const std::string& search) {
FTSQuery q;
- ASSERT_OK(q.parse(search, "english", true, false, TEXT_INDEX_VERSION_3));
+ q.parse(search, "english", true, false, TEXT_INDEX_VERSION_3);
FTSMatcher m(q,
FTSSpec(FTSSpec::fixSpec(BSON("key" << BSON("x"
<< "text")))));
diff --git a/src/mongo/db/fts/fts_query.cpp b/src/mongo/db/fts/fts_query.cpp
index f162481066b..2dc9b222d3a 100644
--- a/src/mongo/db/fts/fts_query.cpp
+++ b/src/mongo/db/fts/fts_query.cpp
@@ -52,15 +52,14 @@ using std::vector;
const bool FTSQuery::caseSensitiveDefault = false;
const bool FTSQuery::diacriticSensitiveDefault = false;
-Status FTSQuery::parse(const string& query,
- StringData language,
- bool caseSensitive,
- bool diacriticSensitive,
- TextIndexVersion textIndexVersion) {
+void FTSQuery::parse(const string& query,
+ StringData language,
+ bool caseSensitive,
+ bool diacriticSensitive,
+ TextIndexVersion textIndexVersion) {
StatusWithFTSLanguage swl = FTSLanguage::make(language, textIndexVersion);
- if (!swl.getStatus().isOK()) {
- return swl.getStatus();
- }
+ uassertStatusOK(swl.getStatus());
+
_language = swl.getValue();
_caseSensitive = caseSensitive;
_diacriticSensitive = diacriticSensitive;
@@ -131,8 +130,6 @@ Status FTSQuery::parse(const string& query,
_addTerms(tokenizer.get(), positiveTermSentence, false);
_addTerms(tokenizer.get(), negativeTermSentence, true);
-
- return Status::OK();
}
void FTSQuery::_addTerms(FTSTokenizer* tokenizer, const string& sentence, bool negated) {
diff --git a/src/mongo/db/fts/fts_query.h b/src/mongo/db/fts/fts_query.h
index ea1882e4baf..3b7fbaa16f3 100644
--- a/src/mongo/db/fts/fts_query.h
+++ b/src/mongo/db/fts/fts_query.h
@@ -50,11 +50,11 @@ public:
// version 1 (see fts_language.cpp for a list of language strings specific to version
// 1). Note that the diacritic sensitive option has no effect on FTS queries below index version
// 3.
- Status parse(const std::string& query,
- StringData language,
- bool caseSensitive,
- bool diacriticSensitive,
- TextIndexVersion textIndexVersion);
+ void parse(const std::string& query,
+ StringData language,
+ bool caseSensitive,
+ bool diacriticSensitive,
+ TextIndexVersion textIndexVersion);
const std::set<std::string>& getPositiveTerms() const {
return _positiveTerms;
diff --git a/src/mongo/db/fts/fts_query_test.cpp b/src/mongo/db/fts/fts_query_test.cpp
index bcf9e537142..dfdeeba68e7 100644
--- a/src/mongo/db/fts/fts_query_test.cpp
+++ b/src/mongo/db/fts/fts_query_test.cpp
@@ -37,7 +37,7 @@ namespace fts {
TEST(FTSQuery, Basic1) {
FTSQuery q;
- ASSERT(q.parse("this is fun", "english", false, false, TEXT_INDEX_VERSION_3).isOK());
+ q.parse("this is fun", "english", false, false, TEXT_INDEX_VERSION_3);
ASSERT_EQUALS(false, q.getCaseSensitive());
ASSERT_EQUALS(1U, q.getPositiveTerms().size());
@@ -50,7 +50,7 @@ TEST(FTSQuery, Basic1) {
TEST(FTSQuery, ParsePunctuation) {
FTSQuery q;
- ASSERT(q.parse("hello.world", "english", false, false, TEXT_INDEX_VERSION_3).isOK());
+ q.parse("hello.world", "english", false, false, TEXT_INDEX_VERSION_3);
ASSERT_EQUALS(false, q.getCaseSensitive());
ASSERT_EQUALS(2U, q.getPositiveTerms().size());
@@ -64,7 +64,7 @@ TEST(FTSQuery, ParsePunctuation) {
TEST(FTSQuery, Neg1) {
FTSQuery q;
- ASSERT(q.parse("this is -really fun", "english", false, false, TEXT_INDEX_VERSION_3).isOK());
+ q.parse("this is -really fun", "english", false, false, TEXT_INDEX_VERSION_3);
ASSERT_EQUALS(1U, q.getPositiveTerms().size());
ASSERT_EQUALS("fun", *q.getPositiveTerms().begin());
@@ -75,8 +75,7 @@ TEST(FTSQuery, Neg1) {
TEST(FTSQuery, Phrase1) {
FTSQuery q;
- ASSERT(q.parse("doing a \"phrase test\" for fun", "english", false, false, TEXT_INDEX_VERSION_3)
- .isOK());
+ q.parse("doing a \"phrase test\" for fun", "english", false, false, TEXT_INDEX_VERSION_3);
ASSERT_EQUALS(3U, q.getPositiveTerms().size());
ASSERT_EQUALS(0U, q.getNegatedTerms().size());
@@ -90,29 +89,26 @@ TEST(FTSQuery, Phrase1) {
TEST(FTSQuery, Phrase2) {
FTSQuery q;
- ASSERT(q.parse("doing a \"phrase-test\" for fun", "english", false, false, TEXT_INDEX_VERSION_3)
- .isOK());
+ q.parse("doing a \"phrase-test\" for fun", "english", false, false, TEXT_INDEX_VERSION_3);
ASSERT_EQUALS(1U, q.getPositivePhr().size());
ASSERT_EQUALS("phrase-test", q.getPositivePhr()[0]);
}
TEST(FTSQuery, NegPhrase1) {
FTSQuery q;
- ASSERT(
- q.parse("doing a -\"phrase test\" for fun", "english", false, false, TEXT_INDEX_VERSION_3)
- .isOK());
+ q.parse("doing a -\"phrase test\" for fun", "english", false, false, TEXT_INDEX_VERSION_3);
ASSERT_EQUALS("fun||||||phrase test", q.debugString());
}
TEST(FTSQuery, CaseSensitiveOption) {
FTSQuery q;
- ASSERT(q.parse("this is fun", "english", true, false, TEXT_INDEX_VERSION_3).isOK());
+ q.parse("this is fun", "english", true, false, TEXT_INDEX_VERSION_3);
ASSERT_EQUALS(true, q.getCaseSensitive());
}
TEST(FTSQuery, CaseSensitivePositiveTerms) {
FTSQuery q;
- ASSERT(q.parse("This is Positively fun", "english", true, false, TEXT_INDEX_VERSION_3).isOK());
+ q.parse("This is Positively fun", "english", true, false, TEXT_INDEX_VERSION_3);
ASSERT_EQUALS(2U, q.getTermsForBounds().size());
ASSERT_EQUALS(1,
@@ -128,8 +124,7 @@ TEST(FTSQuery, CaseSensitivePositiveTerms) {
TEST(FTSQuery, CaseSensitiveNegativeTerms) {
FTSQuery q;
- ASSERT(q.parse("-This -is -Negatively -miserable", "english", true, false, TEXT_INDEX_VERSION_3)
- .isOK());
+ q.parse("-This -is -Negatively -miserable", "english", true, false, TEXT_INDEX_VERSION_3);
ASSERT_EQUALS(0U, q.getPositiveTerms().size());
ASSERT_EQUALS(0U, q.getTermsForBounds().size());
@@ -142,8 +137,7 @@ TEST(FTSQuery, CaseSensitiveNegativeTerms) {
TEST(FTSQuery, CaseSensitivePositivePhrases) {
FTSQuery q;
- ASSERT(q.parse("doing a \"Phrase Test\" for fun", "english", true, false, TEXT_INDEX_VERSION_3)
- .isOK());
+ q.parse("doing a \"Phrase Test\" for fun", "english", true, false, TEXT_INDEX_VERSION_3);
ASSERT_EQUALS(1U, q.getPositivePhr().size());
ASSERT_EQUALS(0U, q.getNegatedPhr().size());
@@ -152,8 +146,7 @@ TEST(FTSQuery, CaseSensitivePositivePhrases) {
TEST(FTSQuery, CaseSensitiveNegativePhrases) {
FTSQuery q;
- ASSERT(q.parse("doing a -\"Phrase Test\" for fun", "english", true, false, TEXT_INDEX_VERSION_3)
- .isOK());
+ q.parse("doing a -\"Phrase Test\" for fun", "english", true, false, TEXT_INDEX_VERSION_3);
ASSERT_EQUALS(0U, q.getPositivePhr().size());
ASSERT_EQUALS(1U, q.getNegatedPhr().size());
@@ -162,17 +155,15 @@ TEST(FTSQuery, CaseSensitiveNegativePhrases) {
TEST(FTSQuery, Mix1) {
FTSQuery q;
- ASSERT(
- q.parse("\"industry\" -Melbourne -Physics", "english", false, false, TEXT_INDEX_VERSION_3)
- .isOK());
+ q.parse("\"industry\" -Melbourne -Physics", "english", false, false, TEXT_INDEX_VERSION_3);
ASSERT_EQUALS("industri||melbourn|physic||industry||", q.debugString());
}
TEST(FTSQuery, NegPhrase2) {
FTSQuery q1, q2, q3;
- ASSERT(q1.parse("foo \"bar\"", "english", false, false, TEXT_INDEX_VERSION_3).isOK());
- ASSERT(q2.parse("foo \"-bar\"", "english", false, false, TEXT_INDEX_VERSION_3).isOK());
- ASSERT(q3.parse("foo \" -bar\"", "english", false, false, TEXT_INDEX_VERSION_3).isOK());
+ q1.parse("foo \"bar\"", "english", false, false, TEXT_INDEX_VERSION_3);
+ q2.parse("foo \"-bar\"", "english", false, false, TEXT_INDEX_VERSION_3);
+ q3.parse("foo \" -bar\"", "english", false, false, TEXT_INDEX_VERSION_3);
ASSERT_EQUALS(2U, q1.getPositiveTerms().size());
ASSERT_EQUALS(2U, q2.getPositiveTerms().size());
@@ -193,9 +184,9 @@ TEST(FTSQuery, NegPhrase2) {
TEST(FTSQuery, NegPhrase3) {
FTSQuery q1, q2, q3;
- ASSERT(q1.parse("foo -\"bar\"", "english", false, false, TEXT_INDEX_VERSION_3).isOK());
- ASSERT(q2.parse("foo -\"-bar\"", "english", false, false, TEXT_INDEX_VERSION_3).isOK());
- ASSERT(q3.parse("foo -\" -bar\"", "english", false, false, TEXT_INDEX_VERSION_3).isOK());
+ q1.parse("foo -\"bar\"", "english", false, false, TEXT_INDEX_VERSION_3);
+ q2.parse("foo -\"-bar\"", "english", false, false, TEXT_INDEX_VERSION_3);
+ q3.parse("foo -\" -bar\"", "english", false, false, TEXT_INDEX_VERSION_3);
ASSERT_EQUALS(1U, q1.getPositiveTerms().size());
ASSERT_EQUALS(1U, q2.getPositiveTerms().size());
@@ -218,7 +209,7 @@ TEST(FTSQuery, NegPhrase3) {
// stemmer and stopword list.
TEST(FTSQuery, TextIndexVersion1LanguageEnglish) {
FTSQuery q;
- ASSERT(q.parse("the running", "english", false, false, TEXT_INDEX_VERSION_1).isOK());
+ q.parse("the running", "english", false, false, TEXT_INDEX_VERSION_1);
ASSERT_EQUALS(1U, q.getPositiveTerms().size());
ASSERT_EQUALS("run", *q.getPositiveTerms().begin());
ASSERT_EQUALS(0U, q.getNegatedTerms().size());
@@ -230,7 +221,7 @@ TEST(FTSQuery, TextIndexVersion1LanguageEnglish) {
// no stopword list.
TEST(FTSQuery, TextIndexVersion1LanguageEng) {
FTSQuery q;
- ASSERT(q.parse("the running", "eng", false, false, TEXT_INDEX_VERSION_1).isOK());
+ q.parse("the running", "eng", false, false, TEXT_INDEX_VERSION_1);
ASSERT_EQUALS(2U, q.getPositiveTerms().size());
ASSERT_EQUALS(1, std::count(q.getPositiveTerms().begin(), q.getPositiveTerms().end(), "the"));
ASSERT_EQUALS(1, std::count(q.getPositiveTerms().begin(), q.getPositiveTerms().end(), "run"));
@@ -243,7 +234,7 @@ TEST(FTSQuery, TextIndexVersion1LanguageEng) {
// and no stopword list will be used.
TEST(FTSQuery, TextIndexVersion1LanguageInvalid) {
FTSQuery q;
- ASSERT(q.parse("the running", "invalid", false, false, TEXT_INDEX_VERSION_1).isOK());
+ q.parse("the running", "invalid", false, false, TEXT_INDEX_VERSION_1);
ASSERT_EQUALS(2U, q.getPositiveTerms().size());
ASSERT_EQUALS(1, std::count(q.getPositiveTerms().begin(), q.getPositiveTerms().end(), "the"));
ASSERT_EQUALS(1,