TEST( FTSQuery, Neg1 ) { FTSQuery q; ASSERT( q.parse( "this is -really fun", "english" ).isOK() ); ASSERT_EQUALS( 1U, q.getTerms().size() ); ASSERT_EQUALS( "fun", q.getTerms()[0] ); ASSERT_EQUALS( 1U, q.getNegatedTerms().size() ); ASSERT_EQUALS( "realli", *q.getNegatedTerms().begin() ); }
TEST(FTSQuery, Neg1) { FTSQuery q; ASSERT(q.parse("this is -really fun", "english", false, TEXT_INDEX_VERSION_2).isOK()); ASSERT_EQUALS(1U, q.getPositiveTerms().size()); ASSERT_EQUALS("fun", *q.getPositiveTerms().begin()); ASSERT_EQUALS(1U, q.getNegatedTerms().size()); ASSERT_EQUALS("realli", *q.getNegatedTerms().begin()); ASSERT_TRUE(q.getTermsForBounds() == q.getPositiveTerms()); }
TEST(FTSQuery, CaseSensitiveNegativeTerms) { FTSQuery q; ASSERT( q.parse("-This -is -Negatively -miserable", "english", true, TEXT_INDEX_VERSION_2).isOK()); ASSERT_EQUALS(0U, q.getPositiveTerms().size()); ASSERT_EQUALS(0U, q.getTermsForBounds().size()); ASSERT_EQUALS(2U, q.getNegatedTerms().size()); ASSERT_EQUALS(1, std::count(q.getNegatedTerms().begin(), q.getNegatedTerms().end(), "Negat")); ASSERT_EQUALS(1, std::count(q.getNegatedTerms().begin(), q.getNegatedTerms().end(), "miser")); ASSERT_EQUALS(0U, q.getPositivePhr().size()); ASSERT_EQUALS(0U, q.getNegatedPhr().size()); }
// Test textIndexVersion:1 query with language "english". This invokes the standard English // stemmer and stopword list. TEST(FTSQuery, TextIndexVersion1LanguageEnglish) { FTSQuery q; ASSERT(q.parse("the running", "english", false, TEXT_INDEX_VERSION_1).isOK()); ASSERT_EQUALS(1U, q.getPositiveTerms().size()); ASSERT_EQUALS("run", *q.getPositiveTerms().begin()); ASSERT_EQUALS(0U, q.getNegatedTerms().size()); ASSERT_EQUALS(0U, q.getPositivePhr().size()); ASSERT_EQUALS(0U, q.getNegatedPhr().size()); }
// Test textIndexVersion:1 query with language "eng". "eng" uses the English stemmer, and // no stopword list. TEST(FTSQuery, TextIndexVersion1LanguageEng) { FTSQuery q; ASSERT(q.parse("the running", "eng", false, TEXT_INDEX_VERSION_1).isOK()); 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")); ASSERT_EQUALS(0U, q.getNegatedTerms().size()); ASSERT_EQUALS(0U, q.getPositivePhr().size()); ASSERT_EQUALS(0U, q.getNegatedPhr().size()); }
TEST( FTSQuery, Basic1 ) { FTSQuery q; ASSERT( q.parse( "this is fun", "english" ).isOK() ); ASSERT_EQUALS( 1U, q.getTerms().size() ); ASSERT_EQUALS( "fun", q.getTerms()[0] ); ASSERT_EQUALS( 0U, q.getNegatedTerms().size() ); ASSERT_EQUALS( 0U, q.getPhr().size() ); ASSERT_EQUALS( 0U, q.getNegatedPhr().size() ); }
// Test textIndexVersion:1 query with language "invalid". No stemming will be performed, // and no stopword list will be used. TEST(FTSQuery, TextIndexVersion1LanguageInvalid) { FTSQuery q; ASSERT(q.parse("the running", "invalid", TEXT_INDEX_VERSION_1).isOK()); ASSERT_EQUALS(2U, q.getTerms().size()); ASSERT_EQUALS(1, std::count(q.getTerms().begin(), q.getTerms().end(), "the")); ASSERT_EQUALS(1, std::count(q.getTerms().begin(), q.getTerms().end(), "running")); ASSERT_EQUALS(0U, q.getNegatedTerms().size()); ASSERT_EQUALS(0U, q.getPhr().size()); ASSERT_EQUALS(0U, q.getNegatedPhr().size()); }
TEST(FTSQuery, Basic1) { FTSQuery q; ASSERT(q.parse("this is fun", "english", false, TEXT_INDEX_VERSION_2).isOK()); ASSERT_EQUALS(false, q.getCaseSensitive()); ASSERT_EQUALS(1U, q.getPositiveTerms().size()); ASSERT_EQUALS("fun", *q.getPositiveTerms().begin()); ASSERT_EQUALS(0U, q.getNegatedTerms().size()); ASSERT_EQUALS(0U, q.getPositivePhr().size()); ASSERT_EQUALS(0U, q.getNegatedPhr().size()); ASSERT_TRUE(q.getTermsForBounds() == q.getPositiveTerms()); }
TEST( FTSQuery, Phrase1 ) { FTSQuery q; ASSERT( q.parse( "doing a \"phrase test\" for fun", "english" ).isOK() ); ASSERT_EQUALS( 3U, q.getTerms().size() ); ASSERT_EQUALS( 0U, q.getNegatedTerms().size() ); ASSERT_EQUALS( 1U, q.getPhr().size() ); ASSERT_EQUALS( 0U, q.getNegatedPhr().size() ); ASSERT_EQUALS( "phrase test", q.getPhr()[0] ); ASSERT_EQUALS( "fun|phrase|test||||phrase test||", q.debugString() ); }
TEST(FTSQuery, ParsePunctuation) { FTSQuery q; ASSERT(q.parse("hello.world", "english", false, TEXT_INDEX_VERSION_2).isOK()); ASSERT_EQUALS(false, q.getCaseSensitive()); ASSERT_EQUALS(2U, q.getPositiveTerms().size()); ASSERT_EQUALS("hello", *q.getPositiveTerms().begin()); ASSERT_EQUALS("world", *(--q.getPositiveTerms().end())); ASSERT_EQUALS(0U, q.getNegatedTerms().size()); ASSERT_EQUALS(0U, q.getPositivePhr().size()); ASSERT_EQUALS(0U, q.getNegatedPhr().size()); ASSERT_TRUE(q.getTermsForBounds() == q.getPositiveTerms()); }
TEST(FTSQuery, Phrase1) { FTSQuery q; ASSERT( q.parse("doing a \"phrase test\" for fun", "english", false, TEXT_INDEX_VERSION_2).isOK()); ASSERT_EQUALS(3U, q.getPositiveTerms().size()); ASSERT_EQUALS(0U, q.getNegatedTerms().size()); ASSERT_EQUALS(1U, q.getPositivePhr().size()); ASSERT_EQUALS(0U, q.getNegatedPhr().size()); ASSERT_TRUE(q.getTermsForBounds() == q.getPositiveTerms()); ASSERT_EQUALS("phrase test", q.getPositivePhr()[0]); ASSERT_EQUALS("fun|phrase|test||||phrase test||", q.debugString()); }
TEST(FTSQuery, CaseSensitivePositiveTerms) { FTSQuery q; ASSERT(q.parse("This is Positively fun", "english", true, TEXT_INDEX_VERSION_2).isOK()); ASSERT_EQUALS(2U, q.getTermsForBounds().size()); ASSERT_EQUALS(1, std::count(q.getTermsForBounds().begin(), q.getTermsForBounds().end(), "posit")); ASSERT_EQUALS(1, std::count(q.getTermsForBounds().begin(), q.getTermsForBounds().end(), "fun")); ASSERT_EQUALS(2U, q.getPositiveTerms().size()); ASSERT_EQUALS(1, std::count(q.getPositiveTerms().begin(), q.getPositiveTerms().end(), "Posit")); ASSERT_EQUALS(1, std::count(q.getPositiveTerms().begin(), q.getPositiveTerms().end(), "fun")); ASSERT_EQUALS(0U, q.getNegatedTerms().size()); ASSERT_EQUALS(0U, q.getPositivePhr().size()); ASSERT_EQUALS(0U, q.getNegatedPhr().size()); }