def shortquery(query, order=None, limit=50, historize=False, fields = ()): """ Perform a short query and return a lazy Django result set If fields are specified, will fetch those fields from the index """ query = SeSQLQuery(query, order, fields) results = query.shortquery(limit) if historize: #suggest feature hook results.historize(query) return results
def shortquery(query, order=None, limit=50, historize=False, fields=()): """ Perform a short query and return a lazy Django result set If fields are specified, will fetch those fields from the index """ query = SeSQLQuery(query, order, fields) results = query.shortquery(limit) if historize: #suggest feature hook results.historize(query) return results
def longquery(query, order=None, limit=None, queryid=None, historize=False, fields=()): """ Perform a long query and return a lazy Django result set If queryid is provided, then the query will be loaded from the cache if possible, and redone else. Be careful, if the query is redone, results may have changed. If fields are specified, will fetch those fields from the index """ if queryid: _query_cache.lock.acquire() try: results = _query_cache[queryid] if results: return results log.warning('Cached query id %r expired, re-querying.' % queryid) finally: _query_cache.lock.release() query = SeSQLQuery(query, order, fields) results = query.longquery(limit) _query_cache.lock.acquire() try: # Generate a new query id, ensuring it's unique if not queryid: while True: letters = string.ascii_letters + string.digits queryid = ''.join([random.choice(letters) for i in range(32)]) if queryid not in _query_cache: break _query_cache[queryid] = results results.queryid = queryid finally: _query_cache.lock.release() if historize: # suggest feature hook results.historize(query) return results
def longquery(query, order=None, limit=None, queryid=None, historize=False, fields = ()): """ Perform a long query and return a lazy Django result set If queryid is provided, then the query will be loaded from the cache if possible, and redone else. Be careful, if the query is redone, results may have changed. If fields are specified, will fetch those fields from the index """ if queryid: _query_cache.lock.acquire() try: results = _query_cache[queryid] if results: return results log.warning('Cached query id %r expired, re-querying.' % queryid) finally: _query_cache.lock.release() query = SeSQLQuery(query, order, fields) results = query.longquery(limit) _query_cache.lock.acquire() try: # Generate a new query id, ensuring it's unique if not queryid: while True: letters = string.ascii_letters + string.digits queryid = ''.join([ random.choice(letters) for i in range(32) ]) if queryid not in _query_cache: break _query_cache[queryid] = results results.queryid = queryid finally: _query_cache.lock.release() if historize: # suggest feature hook results.historize(query) return results