Skip to content

Instantly share code, notes, and snippets.

@MattTheRed
Created November 22, 2013 17:23
Show Gist options
  • Save MattTheRed/7603642 to your computer and use it in GitHub Desktop.
Save MattTheRed/7603642 to your computer and use it in GitHub Desktop.
import boto
django_cache
cs_conn = boto.connect_cloudsearch(
aws_access_key_id=YOUR_KEY_ID,
aws_secret_access_key=YOUR_ACCESS_KEY,
)
search_kwargs = {}
search_kwargs['q'] = "Stuff to find"
try:
search_service = django_cache.get("cloudsearch_search_service")
# Need to try to execute something for it to fail
results = search_service.search(**search_kwargs)
except:
domain = cs_conn.lookup("domain-name")
document_service = domain.get_document_service()
search_service = document_service.get_search_service()
django_cache.set("cloudsearch_search_service", search_service, 300)
results = search_service.search(**search_kwargs)
print results.doc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment