本文整理汇总了C++中FTSQuery::parse方法的典型用法代码示例。如果您正苦于以下问题:C++ FTSQuery::parse方法的具体用法?C++ FTSQuery::parse怎么用?C++ FTSQuery::parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FTSQuery
的用法示例。
在下文中一共展示了FTSQuery::parse方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ASSERT
TEST(FTSQuery, Phrase2) {
FTSQuery q;
ASSERT(
q.parse("doing a \"phrase-test\" for fun", "english", false, TEXT_INDEX_VERSION_2).isOK());
ASSERT_EQUALS(1U, q.getPositivePhr().size());
ASSERT_EQUALS("phrase-test", q.getPositivePhr()[0]);
}
示例2: m
TEST( FTSMatcher, Phrase2 ) {
FTSQuery q;
q.parse( "foo \"table top\"", "english" );
FTSMatcher m( q,
FTSSpec( FTSSpec::fixSpec( BSON( "key" << BSON( "x" << "text" ) ) ) ) );
ASSERT( m.phraseMatch( "table top",
BSON( "x" << BSON_ARRAY( "table top" ) ) ) );
}
示例3: m
// Regression test for SERVER-11994.
TEST( FTSMatcher, NegWild2 ) {
FTSQuery q;
ASSERT_OK( q.parse( "pizza -restaurant", "english", TEXT_INDEX_VERSION_2 ) );
FTSMatcher m( q,
FTSSpec( FTSSpec::fixSpec( BSON( "key" << BSON( "$**" << "text" ) ) ) ) );
ASSERT( m.hasNegativeTerm( BSON( "x" << BSON( "y" << "pizza restaurant" ) ) ) );
ASSERT( m.hasNegativeTerm( BSON( "x" << BSON( "y" << "PIZZA RESTAURANT" ) ) ) );
}
示例4: TEST
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() );
}
示例5: ASSERT
// 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());
}
示例6: _run
/*
* Runs the command object cmdobj on the db with name dbname and puts result in result.
* @param dbname, name of db
* @param cmdobj, object that contains entire command
* @param options
* @param errmsg, reference to error message
* @param result, reference to builder for result
* @param fromRepl
* @return true if successful, false otherwise
*/
bool FTSCommand::_run(const string& dbname,
BSONObj& cmdObj,
int cmdOptions,
const string& ns,
const string& searchString,
string language, // "" for not-set
int limit,
BSONObj& filter,
BSONObj& projection,
string& errmsg,
BSONObjBuilder& result ) {
Timer comm;
scoped_ptr<Projection> pr;
if ( !projection.isEmpty() ) {
pr.reset( new Projection() );
pr->init( projection );
}
// priority queue for results
Results results;
Database* db = cc().database();
Collection* collection = db->getCollection( ns );
if ( !collection ) {
errmsg = "can't find ns";
return false;
}
vector<int> idxMatches;
collection->details()->findIndexByType( INDEX_NAME, idxMatches );
if ( idxMatches.size() == 0 ) {
errmsg = str::stream() << "no text index for: " << ns;
return false;
}
if ( idxMatches.size() > 1 ) {
errmsg = str::stream() << "too many text indexes for: " << ns;
return false;
}
BSONObj indexPrefix;
IndexDescriptor* descriptor = collection->getIndexCatalog()->getDescriptor(idxMatches[0]);
auto_ptr<FTSAccessMethod> fam(new FTSAccessMethod(descriptor));
if ( language == "" ) {
language = fam->getSpec().defaultLanguage().str();
}
Status s = fam->getSpec().getIndexPrefix( filter, &indexPrefix );
if ( !s.isOK() ) {
errmsg = s.toString();
return false;
}
FTSQuery query;
if ( !query.parse( searchString, language ).isOK() ) {
errmsg = "can't parse search";
return false;
}
result.append( "queryDebugString", query.debugString() );
result.append( "language", language );
FTSSearch search(descriptor, fam->getSpec(), indexPrefix, query, filter );
search.go( &results, limit );
// grab underlying container inside priority queue
vector<ScoredLocation> r( results.dangerous() );
// sort results by score (not always in correct order, especially w.r.t. multiterm)
sort( r.begin(), r.end() );
// build the results bson array shown to user
BSONArrayBuilder a( result.subarrayStart( "results" ) );
int tempSize = 1024 * 1024; // leave a mb for other things
long long numReturned = 0;
for ( unsigned n = 0; n < r.size(); n++ ) {
BSONObj obj = BSONObj::make(r[n].rec);
BSONObj toSendBack = obj;
if ( pr ) {
toSendBack = pr->transform(obj);
}
if ( ( tempSize + toSendBack.objsize() ) >= BSONObjMaxUserSize ) {
break;
}
//.........这里部分代码省略.........
示例7: buildStages
//.........这里部分代码省略.........
params.dedup = msn->dedup;
params.pattern = msn->sort;
auto_ptr<MergeSortStage> ret(new MergeSortStage(params, ws));
for (size_t i = 0; i < msn->children.size(); ++i) {
PlanStage* childStage = buildStages(qsol, msn->children[i], ws);
if (NULL == childStage) { return NULL; }
ret->addChild(childStage);
}
return ret.release();
}
else if (STAGE_GEO_2D == root->getType()) {
const Geo2DNode* node = static_cast<const Geo2DNode*>(root);
TwoDParams params;
params.gq = node->gq;
params.filter = node->filter.get();
params.indexKeyPattern = node->indexKeyPattern;
params.ns = qsol.ns;
return new TwoD(params, ws);
}
else if (STAGE_GEO_NEAR_2D == root->getType()) {
const GeoNear2DNode* node = static_cast<const GeoNear2DNode*>(root);
TwoDNearParams params;
params.nearQuery = node->nq;
params.ns = qsol.ns;
params.indexKeyPattern = node->indexKeyPattern;
params.filter = node->filter.get();
params.numWanted = node->numWanted;
params.addPointMeta = node->addPointMeta;
params.addDistMeta = node->addDistMeta;
return new TwoDNear(params, ws);
}
else if (STAGE_GEO_NEAR_2DSPHERE == root->getType()) {
const GeoNear2DSphereNode* node = static_cast<const GeoNear2DSphereNode*>(root);
S2NearParams params;
params.ns = qsol.ns;
params.indexKeyPattern = node->indexKeyPattern;
params.nearQuery = node->nq;
params.baseBounds = node->baseBounds;
params.filter = node->filter.get();
params.addPointMeta = node->addPointMeta;
params.addDistMeta = node->addDistMeta;
return new S2NearStage(params, ws);
}
else if (STAGE_TEXT == root->getType()) {
const TextNode* node = static_cast<const TextNode*>(root);
Database* db = cc().database();
Collection* collection = db ? db->getCollection(qsol.ns) : NULL;
if (NULL == collection) {
warning() << "null collection for text?";
return NULL;
}
vector<int> idxMatches;
collection->details()->findIndexByType("text", idxMatches);
if (1 != idxMatches.size()) {
warning() << "more than one text idx?";
return NULL;
}
IndexDescriptor* index = collection->getIndexCatalog()->getDescriptor(idxMatches[0]);
const FTSAccessMethod* fam =
static_cast<FTSAccessMethod*>( collection->getIndexCatalog()->getIndex( index ) );
TextStageParams params(fam->getSpec());
params.ns = qsol.ns;
params.index = index;
params.spec = fam->getSpec();
// XXX change getIndexPrefix to not look at BSONObj
Status s = fam->getSpec().getIndexPrefix(qsol.filterData, ¶ms.indexPrefix);
if (!s.isOK()) {
warning() << "can't get text index prefix??";
return NULL;
}
string language = ("" == node->_language
? fam->getSpec().defaultLanguage().str()
: node->_language);
FTSQuery ftsq;
Status parseStatus = ftsq.parse(node->_query, language);
if (!parseStatus.isOK()) {
warning() << "cant parse fts query";
return NULL;
}
params.query = ftsq;
return new TextStage(params, ws, node->filter.get());
}
else if (STAGE_SHARDING_FILTER == root->getType()) {
const ShardingFilterNode* fn = static_cast<const ShardingFilterNode*>(root);
PlanStage* childStage = buildStages(qsol, fn->children[0], ws);
if (NULL == childStage) { return NULL; }
return new ShardFilterStage(shardingState.getCollectionMetadata(qsol.ns), ws, childStage);
}
else {
stringstream ss;
root->appendToString(&ss, 0);
warning() << "Could not build exec tree for node " << ss.str() << endl;
return NULL;
}
}
示例8: buildStages
//.........这里部分代码省略.........
}
return ret.release();
}
else if (STAGE_OR == root->getType()) {
const OrNode * orn = static_cast<const OrNode*>(root);
auto_ptr<OrStage> ret(new OrStage(ws, orn->dedup, orn->filter.get()));
for (size_t i = 0; i < orn->children.size(); ++i) {
PlanStage* childStage = buildStages(ns, orn->children[i], ws);
if (NULL == childStage) { return NULL; }
ret->addChild(childStage);
}
return ret.release();
}
else if (STAGE_AND_SORTED == root->getType()) {
const AndSortedNode* asn = static_cast<const AndSortedNode*>(root);
auto_ptr<AndSortedStage> ret(new AndSortedStage(ws, asn->filter.get()));
for (size_t i = 0; i < asn->children.size(); ++i) {
PlanStage* childStage = buildStages(ns, asn->children[i], ws);
if (NULL == childStage) { return NULL; }
ret->addChild(childStage);
}
return ret.release();
}
else if (STAGE_SORT_MERGE == root->getType()) {
const MergeSortNode* msn = static_cast<const MergeSortNode*>(root);
MergeSortStageParams params;
params.dedup = msn->dedup;
params.pattern = msn->sort;
auto_ptr<MergeSortStage> ret(new MergeSortStage(params, ws));
for (size_t i = 0; i < msn->children.size(); ++i) {
PlanStage* childStage = buildStages(ns, msn->children[i], ws);
if (NULL == childStage) { return NULL; }
ret->addChild(childStage);
}
return ret.release();
}
else if (STAGE_GEO_2D == root->getType()) {
const Geo2DNode* node = static_cast<const Geo2DNode*>(root);
TwoDParams params;
params.gq = node->gq;
params.filter = node->filter.get();
params.indexKeyPattern = node->indexKeyPattern;
params.ns = ns;
return new TwoD(params, ws);
}
else if (STAGE_GEO_NEAR_2D == root->getType()) {
const GeoNear2DNode* node = static_cast<const GeoNear2DNode*>(root);
TwoDNearParams params;
params.nearQuery = node->nq;
params.ns = ns;
params.indexKeyPattern = node->indexKeyPattern;
params.filter = node->filter.get();
params.numWanted = node->numWanted;
// XXX XXX where do we grab this from?? the near query...modify geo parser... :(
params.uniqueDocs = false;
// XXX XXX where do we grab this from?? the near query...modify geo parser... :(
return new TwoDNear(params, ws);
}
else if (STAGE_GEO_NEAR_2DSPHERE == root->getType()) {
const GeoNear2DSphereNode* node = static_cast<const GeoNear2DSphereNode*>(root);
return new S2NearStage(ns, node->indexKeyPattern, node->nq, node->baseBounds,
node->filter.get(), ws);
}
else if (STAGE_TEXT == root->getType()) {
const TextNode* node = static_cast<const TextNode*>(root);
NamespaceDetails* nsd = nsdetails(ns.c_str());
if (NULL == nsd) { return NULL; }
vector<int> idxMatches;
nsd->findIndexByType("text", idxMatches);
if (1 != idxMatches.size()) { return NULL; }
IndexDescriptor* index = CatalogHack::getDescriptor(nsd, idxMatches[0]);
auto_ptr<FTSAccessMethod> fam(new FTSAccessMethod(index));
TextStageParams params(fam->getSpec());
params.ns = ns;
params.index = index;
params.spec = fam->getSpec();
params.limit = node->_numWanted;
Status s = fam->getSpec().getIndexPrefix(BSONObj(), ¶ms.indexPrefix);
if (!s.isOK()) { return NULL; }
string language = ("" == node->_language
? fam->getSpec().defaultLanguage()
: node->_language);
FTSQuery ftsq;
Status parseStatus = ftsq.parse(node->_query, language);
if (!parseStatus.isOK()) { return NULL; }
params.query = ftsq;
return new TextStage(params, ws, node->_filter.get());
}
else {
stringstream ss;
root->appendToString(&ss, 0);
warning() << "Could not build exec tree for node " << ss.str() << endl;
return NULL;
}
}