Skip to content
Browse files

Some cleanup in document and search service code. Remove debugging.

  • Loading branch information...
1 parent 38a14dc commit fc4936a4905bf768f28193ce756fa981cb172bfe @garnaat garnaat committed May 1, 2012
Showing with 46 additions and 50 deletions.
  1. +3 −8 boto/cloudsearch/document.py
  2. +4 −4 boto/cloudsearch/layer1.py
  3. +39 −38 boto/cloudsearch/search.py
View
11 boto/cloudsearch/document.py
@@ -39,20 +39,15 @@ class CommitMismatchError(Exception):
class DocumentServiceConnection(object):
- endpoint = None
def __init__(self, domain=None, endpoint=None):
- if endpoint:
- self.endpoint = endpoint
- else:
+ self.domain = domain
+ self.endpoint = endpoint
+ if not self.endpoint:
self.endpoint = domain.doc_service_endpoint
-
self.documents_batch = []
self._sdf = None
- if not self.endpoint.startswith('doc-'):
- self.endpoint = "doc-%s" % self.endpoint
-
def add(self, _id, version, fields, lang='en'):
d = {'type': 'add', 'id': _id, 'version': version, 'lang': lang,
'fields': fields}
View
8 boto/cloudsearch/layer1.py
@@ -26,7 +26,7 @@
from boto.connection import AWSQueryConnection
from boto.regioninfo import RegionInfo
-boto.set_stream_logger('cloudsearch')
+#boto.set_stream_logger('cloudsearch')
def do_bool(val):
return 'true' if val in [True, 1, '1', 'true'] else 'false'
@@ -42,7 +42,7 @@ class Layer1(AWSQueryConnection):
def __init__(self, aws_access_key_id=None, aws_secret_access_key=None,
is_secure=True, host=None, port=None,
proxy=None, proxy_port=None,
- proxy_user=None, proxy_pass=None, debug=2,
+ proxy_user=None, proxy_pass=None, debug=0,
https_connection_factory=None, region=None, path='/',
api_version=None, security_token=None):
if not region:
@@ -58,10 +58,10 @@ def __init__(self, aws_access_key_id=None, aws_secret_access_key=None,
security_token)
def _required_auth_capability(self):
- return ['ec2']
+ return ['sign-v2']
def get_response(self, doc_path, action, params, path='/',
- parent=None, verb='GET', list_marker=None):
+ parent=None, verb='GET', list_marker=None):
if not parent:
parent = self
response = self.make_request(action, params, path, verb)
View
77 boto/cloudsearch/search.py
@@ -35,7 +35,9 @@ class SearchServiceException(Exception):
class CommitMismatchError(Exception):
pass
+
class SearchResults(object):
+
def __init__(self, **attrs):
self.rid = attrs['info']['rid']
# self.doc_coverage_pct = attrs['info']['doc-coverage-pct']
@@ -72,23 +74,24 @@ def next_page(self):
class Query(object):
+
RESULTS_PER_PAGE = 500
- def __init__(self, q=None, bq=None, rank=[], return_fields=[], size=10,
- start=0, facet=[], facet_constraints={}, facet_sort={}, facet_top_n={},
- t={}):
+ def __init__(self, q=None, bq=None, rank=None,
+ return_fields=None, size=10,
+ start=0, facet=None, facet_constraints=None,
+ facet_sort=None, facet_top_n=None, t=None):
self.q = q
self.bq = bq
- self.rank = rank
- self.return_fields = return_fields
+ self.rank = rank or []
+ self.return_fields = return_fields or []
self.start = start
- self.facet = facet
- self.facet_constraints = facet_constraints
- self.facet_sort = facet_sort
- self.facet_top_n = facet_top_n
- self.t = t
-
+ self.facet = facet or []
+ self.facet_constraints = facet_constraints or {}
+ self.facet_sort = facet_sort or {}
+ self.facet_top_n = facet_top_n or {}
+ self.t = t or {}
self.page = 0
self.update_size(size)
@@ -139,27 +142,26 @@ def to_params(self):
class SearchConnection(object):
+
def __init__(self, domain=None, endpoint=None):
- if endpoint:
- self.endpoint = endpoint
- else:
+ self.domain = domain
+ self.endpoint = endpoint
+ if not endpoint:
self.endpoint = domain.search_service_endpoint
- if not self.endpoint.startswith('search-'):
- self.endpoint = "search-%s" % self.endpoint
-
- def build_query(self, q=None, bq=None, rank=[], return_fields=[], size=10,
- start=0, facet=[], facet_constraints={}, facet_sort={}, facet_top_n={},
- t={}):
+ def build_query(self, q=None, bq=None, rank=None, return_fields=None,
+ size=10, start=0, facet=None, facet_constraints=None,
+ facet_sort=None, facet_top_n=None, t=None):
return Query(q=q, bq=bq, rank=rank, return_fields=return_fields,
- size=size, start=start, facet=facet,
- facet_constraints=facet_constraints, facet_sort=facet_sort,
- facet_top_n=facet_top_n, t=t)
+ size=size, start=start, facet=facet,
+ facet_constraints=facet_constraints,
+ facet_sort=facet_sort, facet_top_n=facet_top_n, t=t)
- def search(self, q=None, bq=None, rank=[], return_fields=[], size=10,
- start=0, facet=[], facet_constraints={}, facet_sort={}, facet_top_n={},
- t={}):
- """Query Cloudsearch
+ def search(self, q=None, bq=None, rank=None, return_fields=None,
+ size=10, start=0, facet=None, facet_constraints=None,
+ facet_sort=None, facet_top_n=None, t=None):
+ """
+ Query Cloudsearch
:type q:
:param q:
@@ -198,11 +200,12 @@ def search(self, q=None, bq=None, rank=[], return_fields=[], size=10,
:return: A cloudsearch SearchResults object
"""
- query = self.build_query(q=q, bq=bq, rank=rank, return_fields=return_fields,
- size=size, start=start, facet=facet,
- facet_constraints=facet_constraints, facet_sort=facet_sort,
- facet_top_n=facet_top_n, t=t)
-
+ query = self.build_query(q=q, bq=bq, rank=rank,
+ return_fields=return_fields,
+ size=size, start=start, facet=facet,
+ facet_constraints=facet_constraints,
+ facet_sort=facet_sort,
+ facet_top_n=facet_top_n, t=t)
return self(query)
def __call__(self, query):
@@ -222,9 +225,6 @@ def __call__(self, query):
data['query'] = query
data['search_service'] = self
- # import urllib
- # print "%s?%s" % (url, urllib.urlencode(params))
-
if 'messages' in data and 'error' in data:
for m in data['messages']:
if m['severity'] == 'fatal':
@@ -261,9 +261,10 @@ def get_all_paged(self, query, per_page):
def get_all_hits(self, query):
"""Get a generator to iterate over all search results
- Transparently handles the results paging from Cloudsearch search results
- so even if you have many thousands of results you can iterate over all
- results in a reasonably efficient manner.
+ Transparently handles the results paging from Cloudsearch
+ search results so even if you have many thousands of results
+ you can iterate over all results in a reasonably efficient
+ manner.
:type query: :class:`exfm.cloudsearch.Query`
:param query: A fully specified Query instance

0 comments on commit fc4936a

Please sign in to comment.
Something went wrong with that request. Please try again.