diff options
Diffstat (limited to 'db/indexkey.h')
-rw-r--r-- | db/indexkey.h | 67 |
1 files changed, 43 insertions, 24 deletions
diff --git a/db/indexkey.h b/db/indexkey.h index e73d9de..be73171 100644 --- a/db/indexkey.h +++ b/db/indexkey.h @@ -46,16 +46,16 @@ namespace mongo { virtual void getKeys( const BSONObj &obj, BSONObjSetDefaultOrder &keys ) const = 0; virtual shared_ptr<Cursor> newCursor( const BSONObj& query , const BSONObj& order , int numWanted ) const = 0; - + /** optional op : changes query to match what's in the index */ virtual BSONObj fixKey( const BSONObj& in ) { return in; } /** optional op : compare 2 objects with regards to this index */ - virtual int compare( const BSONObj& l , const BSONObj& r ) const; + virtual int compare( const BSONObj& l , const BSONObj& r ) const; /** @return plugin */ const IndexPlugin * getPlugin() const { return _plugin; } - + const BSONObj& keyPattern() const; virtual IndexSuitability suitability( const BSONObj& query , const BSONObj& order ) const ; @@ -66,7 +66,7 @@ namespace mongo { const IndexPlugin * _plugin; const IndexSpec * _spec; }; - + /** * this represents a plugin * a plugin could be something like full text search, sparse index, etc... @@ -76,11 +76,21 @@ namespace mongo { class IndexPlugin : boost::noncopyable { public: IndexPlugin( const string& name ); - virtual ~IndexPlugin(){} - + virtual ~IndexPlugin() {} + virtual IndexType* generate( const IndexSpec * spec ) const = 0; - static IndexPlugin* get( const string& name ){ + string getName() const { return _name; } + + /** + * @return new keyPattern + * if nothing changes, should return keyPattern + */ + virtual BSONObj adjustIndexSpec( const BSONObj& spec ) const { return spec; } + + // ------- static below ------- + + static IndexPlugin* get( const string& name ) { if ( ! _plugins ) return 0; map<string,IndexPlugin*>::iterator i = _plugins->find( name ); @@ -89,7 +99,12 @@ namespace mongo { return i->second; } - string getName() const { return _name; } + /** + * @param keyPattern { x : "fts" } + * @return "" or the name + */ + static string findPluginName( const BSONObj& keyPattern ); + private: string _name; static map<string,IndexPlugin*> * _plugins; @@ -102,31 +117,31 @@ namespace mongo { public: BSONObj keyPattern; // e.g., { name : 1 } BSONObj info; // this is the same as IndexDetails::info.obj() - + IndexSpec() - : _details(0) , _finishedInit(false){ + : _details(0) , _finishedInit(false) { } IndexSpec( const BSONObj& k , const BSONObj& m = BSONObj() ) - : keyPattern(k) , info(m) , _details(0) , _finishedInit(false){ + : keyPattern(k) , info(m) , _details(0) , _finishedInit(false) { _init(); } - + /** this is a DiscLoc of an IndexDetails info - should have a key field + should have a key field */ - IndexSpec( const DiskLoc& loc ){ + IndexSpec( const DiskLoc& loc ) { reset( loc ); } - + void reset( const DiskLoc& loc ); void reset( const IndexDetails * details ); - + void getKeys( const BSONObj &obj, BSONObjSetDefaultOrder &keys ) const; BSONElement missingField() const { return _nullElt; } - + string getTypeName() const { if ( _indexType.get() ) return _indexType->getPlugin()->getName(); @@ -148,20 +163,24 @@ namespace mongo { IndexSuitability _suitability( const BSONObj& query , const BSONObj& order ) const ; void _getKeys( vector<const char*> fieldNames , vector<BSONElement> fixed , const BSONObj &obj, BSONObjSetDefaultOrder &keys ) const; - + BSONSizeTracker _sizeTracker; vector<const char*> _fieldNames; vector<BSONElement> _fixed; - BSONObj _nullKey; - - BSONObj _nullObj; - BSONElement _nullElt; - + + BSONObj _nullKey; // a full key with all fields null + + BSONObj _nullObj; // only used for _nullElt + BSONElement _nullElt; // jstNull + + int _nFields; // number of fields in the index + bool _sparse; // if the index is sparse + shared_ptr<IndexType> _indexType; const IndexDetails * _details; - + void _init(); public: |