summaryrefslogtreecommitdiff
path: root/src/mongo/db/exec/text.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/exec/text.h')
-rw-r--r--src/mongo/db/exec/text.h230
1 files changed, 116 insertions, 114 deletions
diff --git a/src/mongo/db/exec/text.h b/src/mongo/db/exec/text.h
index 96f5c67bc4d..9e64621cbb7 100644
--- a/src/mongo/db/exec/text.h
+++ b/src/mongo/db/exec/text.h
@@ -46,157 +46,159 @@
namespace mongo {
- using fts::FTSIndexFormat;
- using fts::FTSMatcher;
- using fts::FTSQuery;
- using fts::FTSSpec;
- using fts::MAX_WEIGHT;
+using fts::FTSIndexFormat;
+using fts::FTSMatcher;
+using fts::FTSQuery;
+using fts::FTSSpec;
+using fts::MAX_WEIGHT;
- class OperationContext;
+class OperationContext;
- struct TextStageParams {
- TextStageParams(const FTSSpec& s) : spec(s) {}
+struct TextStageParams {
+ TextStageParams(const FTSSpec& s) : spec(s) {}
- // Text index descriptor. IndexCatalog owns this.
- IndexDescriptor* index;
+ // Text index descriptor. IndexCatalog owns this.
+ IndexDescriptor* index;
- // Index spec.
- FTSSpec spec;
+ // Index spec.
+ FTSSpec spec;
- // Index keys that precede the "text" index key.
- BSONObj indexPrefix;
+ // Index keys that precede the "text" index key.
+ BSONObj indexPrefix;
- // The text query.
- FTSQuery query;
- };
+ // The text query.
+ FTSQuery query;
+};
+/**
+ * Implements a blocking stage that returns text search results.
+ *
+ * Prerequisites: None; is a leaf node.
+ * Output type: LOC_AND_OBJ_UNOWNED.
+ *
+ * TODO: Should the TextStage ever generate NEED_YIELD requests for fetching MMAP v1 records?
+ * Right now this stage could reduce concurrency by failing to request a yield during fetch.
+ */
+class TextStage : public PlanStage {
+public:
/**
- * Implements a blocking stage that returns text search results.
- *
- * Prerequisites: None; is a leaf node.
- * Output type: LOC_AND_OBJ_UNOWNED.
- *
- * TODO: Should the TextStage ever generate NEED_YIELD requests for fetching MMAP v1 records?
- * Right now this stage could reduce concurrency by failing to request a yield during fetch.
+ * The text stage has a few 'states' it transitions between.
*/
- class TextStage : public PlanStage {
- public:
- /**
- * The text stage has a few 'states' it transitions between.
- */
- enum State {
- // 1. Initialize the index scans we use to retrieve term/score info.
- INIT_SCANS,
+ enum State {
+ // 1. Initialize the index scans we use to retrieve term/score info.
+ INIT_SCANS,
- // 2. Read the terms/scores from the text index.
- READING_TERMS,
+ // 2. Read the terms/scores from the text index.
+ READING_TERMS,
- // 3. Return results to our parent.
- RETURNING_RESULTS,
+ // 3. Return results to our parent.
+ RETURNING_RESULTS,
- // 4. Done.
- DONE,
- };
+ // 4. Done.
+ DONE,
+ };
- TextStage(OperationContext* txn,
- const TextStageParams& params,
- WorkingSet* ws,
- const MatchExpression* filter);
+ TextStage(OperationContext* txn,
+ const TextStageParams& params,
+ WorkingSet* ws,
+ const MatchExpression* filter);
- virtual ~TextStage();
+ virtual ~TextStage();
- virtual StageState work(WorkingSetID* out);
- virtual bool isEOF();
+ virtual StageState work(WorkingSetID* out);
+ virtual bool isEOF();
- virtual void saveState();
- virtual void restoreState(OperationContext* opCtx);
- virtual void invalidate(OperationContext* txn, const RecordId& dl, InvalidationType type);
+ virtual void saveState();
+ virtual void restoreState(OperationContext* opCtx);
+ virtual void invalidate(OperationContext* txn, const RecordId& dl, InvalidationType type);
- virtual std::vector<PlanStage*> getChildren() const;
+ virtual std::vector<PlanStage*> getChildren() const;
- virtual StageType stageType() const { return STAGE_TEXT; }
+ virtual StageType stageType() const {
+ return STAGE_TEXT;
+ }
- PlanStageStats* getStats();
+ PlanStageStats* getStats();
- virtual const CommonStats* getCommonStats() const;
+ virtual const CommonStats* getCommonStats() const;
- virtual const SpecificStats* getSpecificStats() const;
+ virtual const SpecificStats* getSpecificStats() const;
- static const char* kStageType;
+ static const char* kStageType;
- private:
- /**
- * Initializes sub-scanners.
- */
- StageState initScans(WorkingSetID* out);
+private:
+ /**
+ * Initializes sub-scanners.
+ */
+ StageState initScans(WorkingSetID* out);
- /**
- * Helper for buffering results array. Returns NEED_TIME (if any results were produced),
- * IS_EOF, or FAILURE.
- */
- StageState readFromSubScanners(WorkingSetID* out);
+ /**
+ * Helper for buffering results array. Returns NEED_TIME (if any results were produced),
+ * IS_EOF, or FAILURE.
+ */
+ StageState readFromSubScanners(WorkingSetID* out);
- /**
- * Helper called from readFromSubScanners to update aggregate score with a new-found (term,
- * score) pair for this document. Also rejects documents that don't match this stage's
- * filter.
- */
- StageState addTerm(WorkingSetID wsid, WorkingSetID* out);
+ /**
+ * Helper called from readFromSubScanners to update aggregate score with a new-found (term,
+ * score) pair for this document. Also rejects documents that don't match this stage's
+ * filter.
+ */
+ StageState addTerm(WorkingSetID wsid, WorkingSetID* out);
- /**
- * Possibly return a result. FYI, this may perform a fetch directly if it is needed to
- * evaluate all filters.
- */
- StageState returnResults(WorkingSetID* out);
+ /**
+ * Possibly return a result. FYI, this may perform a fetch directly if it is needed to
+ * evaluate all filters.
+ */
+ StageState returnResults(WorkingSetID* out);
- // transactional context for read locks. Not owned by us
- OperationContext* _txn;
+ // transactional context for read locks. Not owned by us
+ OperationContext* _txn;
- // Parameters of this text stage.
- TextStageParams _params;
+ // Parameters of this text stage.
+ TextStageParams _params;
- // Text-specific phrase and negated term matcher.
- FTSMatcher _ftsMatcher;
+ // Text-specific phrase and negated term matcher.
+ FTSMatcher _ftsMatcher;
- // Working set. Not owned by us.
- WorkingSet* _ws;
+ // Working set. Not owned by us.
+ WorkingSet* _ws;
- // Filter. Not owned by us.
- const MatchExpression* _filter;
+ // Filter. Not owned by us.
+ const MatchExpression* _filter;
- // Stats.
- CommonStats _commonStats;
- TextStats _specificStats;
+ // Stats.
+ CommonStats _commonStats;
+ TextStats _specificStats;
- // What state are we in? See the State enum above.
- State _internalState;
+ // What state are we in? See the State enum above.
+ State _internalState;
- // Used in INIT_SCANS and READING_TERMS. The index scans we're using to retrieve text
- // terms.
- OwnedPointerVector<PlanStage> _scanners;
+ // Used in INIT_SCANS and READING_TERMS. The index scans we're using to retrieve text
+ // terms.
+ OwnedPointerVector<PlanStage> _scanners;
- // Which _scanners are we currently reading from?
- size_t _currentIndexScanner;
+ // Which _scanners are we currently reading from?
+ size_t _currentIndexScanner;
- // If not Null, we use this rather than asking our child what to do next.
- WorkingSetID _idRetrying;
+ // If not Null, we use this rather than asking our child what to do next.
+ WorkingSetID _idRetrying;
- // Map each buffered record id to this data.
- struct TextRecordData {
- TextRecordData() : wsid(WorkingSet::INVALID_ID), score(0.0) { }
- WorkingSetID wsid;
- double score;
- };
+ // Map each buffered record id to this data.
+ struct TextRecordData {
+ TextRecordData() : wsid(WorkingSet::INVALID_ID), score(0.0) {}
+ WorkingSetID wsid;
+ double score;
+ };
- // Temporary score data filled out by sub-scans. Used in READING_TERMS and
- // RETURNING_RESULTS.
- // Maps from diskloc -> (aggregate score for doc, wsid).
- typedef unordered_map<RecordId, TextRecordData, RecordId::Hasher> ScoreMap;
- ScoreMap _scores;
- ScoreMap::const_iterator _scoreIterator;
+ // Temporary score data filled out by sub-scans. Used in READING_TERMS and
+ // RETURNING_RESULTS.
+ // Maps from diskloc -> (aggregate score for doc, wsid).
+ typedef unordered_map<RecordId, TextRecordData, RecordId::Hasher> ScoreMap;
+ ScoreMap _scores;
+ ScoreMap::const_iterator _scoreIterator;
- // Used for fetching records from the collection.
- std::unique_ptr<RecordCursor> _recordCursor;
- };
+ // Used for fetching records from the collection.
+ std::unique_ptr<RecordCursor> _recordCursor;
+};
-} // namespace mongo
+} // namespace mongo