def autocomplete(request): q = request.GET.get('q') if not q: return [] conn = get_redis_connection('titles') search_index = RedisSearchIndex(conn) results = search_index.search(q, n=10) return results
def handle(self, *args, **options): now = utc_now() connection = get_redis_connection('titles') search_index = RedisSearchIndex(connection) query = u' '.join(args) print "QUERY:", repr(query) t0 = time.time() results = search_index.search(query) t1 = time.time() print "In", t1 - t0, "seconds" print "TERMS:", results['terms'] for id, score, title in results['results']: print "\t", id.ljust(4), score, repr(title)
def handle(self, *args, **options): now = utc_now() verbose = int(options['verbosity']) > 1 connection = get_redis_connection('titles') connection.flushdb() search_index = RedisSearchIndex(connection) for plog in models.BlogItem.objects.filter(pub_date__lte=now).order_by('?'): if verbose: print repr(plog.title), # print search_index.add_item(plog.id, plog.title, 1) try: hits = models.BlogItemHits.objects.get(oid=plog.oid).hits except models.BlogItemHits.DoesNotExist: hits = 1 result = search_index.add_item(plog.oid, plog.title, hits), hits if verbose: print result