def search(self, cr, user, args, offset=0, limit=0, order=None, context=None, count=False): #Make a copy of args for working #Domain has to be list of lists tmp_args = [ isinstance(arg, tuple) and list(arg) or arg for arg in args ] collection = mdbpool.get_collection(self._table) self.search_trans_fields(tmp_args) new_args = mdbpool.translate_domain(tmp_args) if not context: context = {} self.pool.get('ir.model.access').check(cr, user, self._name, 'read', context=context) #Performance problems for counting in mongodb #Only count when forcing. Else return limit #https://jira.mongodb.org/browse/SERVER-1752 if not context.get('force_count', False) and count: return limit #In very large collections when no args #orders all documents prior to return a result #so when no filters, order by id that is sure that #has an individual index and works very fast if not args: order = 'id' if count: return collection.find(new_args, { 'id': 1 }, skip=int(offset), limit=int(limit), timeout=True, snapshot=False, tailable=False, sort=self._compute_order(cr, user, order)).count() mongo_cr = collection.find(new_args, {'id': 1}, skip=int(offset), limit=int(limit), timeout=True, snapshot=False, tailable=False, sort=self._compute_order(cr, user, order)) res = [x['id'] for x in mongo_cr] return res
def search(self, cr, user, args, offset=0, limit=0, order=None, context=None, count=False): #Make a copy of args for working #Domain has to be list of lists tmp_args = [isinstance(arg, tuple) and list(arg) or arg for arg in args] collection = mdbpool.get_collection(self._table) self.search_trans_fields(tmp_args) new_args = mdbpool.translate_domain(tmp_args) if not context: context = {} self.pool.get('ir.model.access').check(cr, user, self._name, 'read', context=context) #Performance problems for counting in mongodb #Only count when forcing. Else return limit #https://jira.mongodb.org/browse/SERVER-1752 if not context.get('force_count', False) and count: return limit #In very large collections when no args #orders all documents prior to return a result #so when no filters, order by id that is sure that #has an individual index and works very fast if not args: order = 'id' if count: return collection.find( new_args, {'id': 1}, skip=int(offset), limit=int(limit), timeout=True, snapshot=False, tailable=False, sort=self._compute_order(cr, user, order)).count() mongo_cr = collection.find( new_args, {'id': 1}, skip=int(offset), limit=int(limit), timeout=True, snapshot=False, tailable=False, sort=self._compute_order(cr, user, order)) res = [x['id'] for x in mongo_cr] return res
def search(self, cr, user, args, offset=0, limit=0, order=None, context=None, count=False): #Make a copy of args for working #Domain has to be list of lists tmp_args = [isinstance(arg, tuple) and list(arg) or arg for arg in args] collection = mdbpool.get_collection(self._table) self.search_trans_fields(tmp_args) new_args = mdbpool.translate_domain(tmp_args) # Implement exact match for fields char which defaults to ilike for k in new_args: field = self._columns.get(k) if not field: pass if getattr(field, 'exact_match', False): if isinstance(new_args[k], re._pattern_type): new_args[k] = new_args[k].pattern.lstrip('.*').rstrip('.*') if not context: context = {} self.pool.get('ir.model.access').check(cr, user, self._name, 'read', context=context) #In very large collections when no args #orders all documents prior to return a result #so when no filters, order by id that is sure that #has an individual index and works very fast if not args: order = 'id' if count: return collection.find( new_args, {'id': 1}, no_cursor_timeout=True, modifiers={"$snapshot": False}, ).count() mongo_cr = collection.find( new_args, {'id': 1}, skip=int(offset), limit=int(limit), no_cursor_timeout=True, modifiers={"$snapshot": False}, sort=self._compute_order(cr, user, order)) res = [x['id'] for x in mongo_cr] return res
def search(self, cr, user, args, offset=0, limit=0, order=None, context=None, count=False): #Make a copy of args for working #Domain has to be list of lists tmp_args = [ isinstance(arg, tuple) and list(arg) or arg for arg in args ] collection = mdbpool.get_collection(self._table) self.search_trans_fields(tmp_args) new_args = mdbpool.translate_domain(tmp_args) # Implement exact match for fields char which defaults to ilike for k in new_args: field = self._columns.get(k) if not field: pass if getattr(field, 'exact_match', False): if isinstance(new_args[k], re._pattern_type): new_args[k] = new_args[k].pattern.lstrip('.*').rstrip('.*') if not context: context = {} self.pool.get('ir.model.access').check(cr, user, self._name, 'read', context=context) #In very large collections when no args #orders all documents prior to return a result #so when no filters, order by id that is sure that #has an individual index and works very fast if not args: order = 'id' if count: return collection.find( new_args, { 'id': 1 }, no_cursor_timeout=True, modifiers={ "$snapshot": False }, ).count() mongo_cr = collection.find(new_args, {'id': 1}, skip=int(offset), limit=int(limit), no_cursor_timeout=True, modifiers={"$snapshot": False}, sort=self._compute_order(cr, user, order)) res = [x['id'] for x in mongo_cr] return res