本文整理汇总了C++中StatusWithFTSLanguage::getStatus方法的典型用法代码示例。如果您正苦于以下问题:C++ StatusWithFTSLanguage::getStatus方法的具体用法?C++ StatusWithFTSLanguage::getStatus怎么用?C++ StatusWithFTSLanguage::getStatus使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StatusWithFTSLanguage
的用法示例。
在下文中一共展示了StatusWithFTSLanguage::getStatus方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ASSERT
TEST(FTSLanguageV2, UpperCaseLanguage) {
StatusWithFTSLanguage swl = FTSLanguage::make("SPANISH", TEXT_INDEX_VERSION_2);
ASSERT(swl.getStatus().isOK());
ASSERT_EQUALS(swl.getValue()->str(), "spanish");
}
示例2: parse
Status FTSQuery::parse(const string& query, StringData language,
TextIndexVersion textIndexVersion) {
_search = query;
StatusWithFTSLanguage swl = FTSLanguage::make( language, textIndexVersion );
if ( !swl.getStatus().isOK() ) {
return swl.getStatus();
}
_language = swl.getValue();
const StopWords* stopWords = StopWords::getStopWords( *_language );
Stemmer stemmer( *_language );
bool inNegation = false;
bool inPhrase = false;
unsigned quoteOffset = 0;
Tokenizer i( *_language, query );
while ( i.more() ) {
Token t = i.next();
if ( t.type == Token::TEXT ) {
string s = t.data.toString();
if ( inPhrase && inNegation ) {
// don't add term
}
else {
_addTerm( stopWords, stemmer, s, inNegation );
}
if ( inNegation && !inPhrase )
inNegation = false;
}
else if ( t.type == Token::DELIMITER ) {
char c = t.data[0];
if ( c == '-' ) {
if ( !inPhrase && t.previousWhiteSpace ) {
// phrases can be negated, and terms not in phrases can be negated.
// terms in phrases can not be negated.
inNegation = true;
}
}
else if ( c == '"' ) {
if ( inPhrase ) {
// end of a phrase
unsigned phraseStart = quoteOffset + 1;
unsigned phraseLength = t.offset - phraseStart;
StringData phrase = StringData( query ).substr( phraseStart,
phraseLength );
if ( inNegation )
_negatedPhrases.push_back( tolowerString( phrase ) );
else
_phrases.push_back( tolowerString( phrase ) );
inNegation = false;
inPhrase = false;
}
else {
// start of a phrase
inPhrase = true;
quoteOffset = t.offset;
}
}
}
else {
abort();
}
}
return Status::OK();
}
示例3: parse
Status FTSQueryImpl::parse(TextIndexVersion textIndexVersion) {
StatusWithFTSLanguage ftsLanguage = FTSLanguage::make(getLanguage(), textIndexVersion);
if (!ftsLanguage.getStatus().isOK()) {
return ftsLanguage.getStatus();
}
// Build a space delimited list of words to have the FtsTokenizer tokenize
string positiveTermSentence;
string negativeTermSentence;
bool inNegation = false;
bool inPhrase = false;
unsigned quoteOffset = 0;
FTSQueryParser i(getQuery());
while (i.more()) {
QueryToken t = i.next();
if (t.type == QueryToken::TEXT) {
string s = t.data.toString();
if (inPhrase && inNegation) {
// don't add term
} else {
// A negation should only continue until the next whitespace character. For example,
// "-foo" should negate "foo", "- foo" should not negate "foo", and "-foo-bar"
// should negate both "foo" and "bar".
if (inNegation && t.previousWhiteSpace) {
inNegation = false;
}
if (inNegation) {
negativeTermSentence.append(s);
negativeTermSentence.push_back(' ');
} else {
positiveTermSentence.append(s);
positiveTermSentence.push_back(' ');
}
}
} else if (t.type == QueryToken::DELIMITER) {
char c = t.data[0];
if (c == '-') {
if (!inPhrase && t.previousWhiteSpace) {
// phrases can be negated, and terms not in phrases can be negated.
// terms in phrases can not be negated.
inNegation = true;
}
} else if (c == '"') {
if (inPhrase) {
// end of a phrase
unsigned phraseStart = quoteOffset + 1;
unsigned phraseLength = t.offset - phraseStart;
StringData phrase = StringData(getQuery()).substr(phraseStart, phraseLength);
if (inNegation) {
_negatedPhrases.push_back(phrase.toString());
} else {
_positivePhrases.push_back(phrase.toString());
}
// Do not reset 'inNegation' here, since a negation should continue until the
// next whitespace character. For example, '-"foo bar"-"baz quux"' should negate
// both the phrase "foo bar" and the phrase "baz quux".
inPhrase = false;
} else {
// start of a phrase
inPhrase = true;
// A "-" should only be treated as a negation if there is no whitespace between
// the "-" and the start of the phrase.
if (inNegation && t.previousWhiteSpace) {
inNegation = false;
}
quoteOffset = t.offset;
}
}
} else {
MONGO_UNREACHABLE;
}
}
std::unique_ptr<FTSTokenizer> tokenizer(ftsLanguage.getValue()->createTokenizer());
_addTerms(tokenizer.get(), positiveTermSentence, false);
_addTerms(tokenizer.get(), negativeTermSentence, true);
return Status::OK();
}