Example #1
0
    def __init__(self):
        self.name = None
        self._indices = []
        self._textIndex = None
        self._textLanguage = None

        self.initialize()

        db_cfg = getDbConfig()
        db_connection = getDbConnection()
        dbName = db_cfg['database']
        self.database = db_connection[dbName]
        self.collection = self.database[self.name]

        for index in self._indices:
            if isinstance(index, (list, tuple)):
                self.collection.ensure_index(index[0], **index[1])
            else:
                self.collection.ensure_index(index)

        if type(self._textIndex) is dict:
            textIdx = [(k, 'text') for k in self._textIndex.keys()]
            try:
                self.collection.ensure_index(
                    textIdx,
                    weights=self._textIndex,
                    default_language=self._textLanguage)
            except pymongo.errors.OperationFailure:
                print(
                    TerminalColor.warning('WARNING: Text search not enabled.'))
Example #2
0
    def __init__(self):
        self.name = None
        self._indices = []
        self._textIndex = None

        self.initialize()

        assert type(self.name) == str

        db_cfg = getDbConfig()
        db_connection = getDbConnection()
        if cherrypy.config['server']['mode'] == 'testing':
            dbName = '%s_test' % db_cfg['database']
        else:
            dbName = db_cfg['database']  # pragma: no cover
        self.database = db_connection[dbName]
        self.collection = self.database[self.name]

        assert isinstance(self.collection, pymongo.collection.Collection)
        assert type(self._indices) == list

        for index in self._indices:
            self.collection.ensure_index(index)

        if type(self._textIndex) is dict:
            textIdx = [(k, 'text') for k in self._textIndex.keys()]
            self.collection.ensure_index(
                textIdx, weights=self._textIndex,
                default_language=self._textLanguage)
Example #3
0
    def __init__(self):
        self.name = None
        self._indices = []
        self._textIndex = None
        self._textLanguage = None

        self.initialize()

        db_cfg = getDbConfig()
        db_connection = getDbConnection()
        dbName = db_cfg['database']
        self.database = db_connection[dbName]
        self.collection = self.database[self.name]

        for index in self._indices:
            if isinstance(index, (list, tuple)):
                self.collection.ensure_index(index[0], **index[1])
            else:
                self.collection.ensure_index(index)

        if type(self._textIndex) is dict:
            textIdx = [(k, 'text') for k in self._textIndex.keys()]
            try:
                self.collection.ensure_index(
                    textIdx, weights=self._textIndex,
                    default_language=self._textLanguage)
            except pymongo.errors.OperationFailure:
                print(
                    TerminalColor.warning('WARNING: Text search not enabled.'))
Example #4
0
    def __init__(self):
        self.name = None
        self._indices = []
        self.initialize()

        assert type(self.name) == str

        db_cfg = getDbConfig()
        db_connection = getDbConnection()
        if cherrypy.config['server']['mode'] == 'testing':
            dbName = '%s_test' % db_cfg['database']
        else:
            dbName = db_cfg['database']  # pragma: no cover
        self.collection = db_connection[dbName][self.name]

        assert isinstance(self.collection, pymongo.collection.Collection)
        assert type(self._indices) == list

        for index in self._indices:
            self.collection.ensure_index(index)