Permalink
Browse files

Merge pull request #789 from srs81/develop

Fixed SimpleDB, CloudSearch docs
  • Loading branch information...
2 parents 0d59816 + 6592784 commit 6c1aacded84e9dbed49833468d18316ba9db45c3 @garnaat garnaat committed Jun 5, 2012
Showing with 43 additions and 43 deletions.
  1. +40 −40 docs/source/cloudsearch_tut.rst
  2. +3 −3 docs/source/simpledb_tut.rst
View
80 docs/source/cloudsearch_tut.rst
@@ -12,32 +12,32 @@ assumes that you have boto already downloaded and installed.
Creating a Domain
-----------------
- import boto
+ >>> import boto
- our_ip = '192.168.1.0'
+ >>> our_ip = '192.168.1.0'
- conn = boto.connect_cloudsearch()
- domain = conn.create_domain('demo')
+ >>> conn = boto.connect_cloudsearch()
+ >>> domain = conn.create_domain('demo')
- # Allow our IP address to access the document and search services
- policy = domain.get_access_policies()
- policy.allow_search_ip(our_ip)
- policy.allow_doc_ip(our_ip)
+ >>> # Allow our IP address to access the document and search services
+ >>> policy = domain.get_access_policies()
+ >>> policy.allow_search_ip(our_ip)
+ >>> policy.allow_doc_ip(our_ip)
- # Create an 'text' index field called 'username'
- uname_field = domain.create_index_field('username', 'text')
+ >>> # Create an 'text' index field called 'username'
+ >>> uname_field = domain.create_index_field('username', 'text')
- # But it would be neat to drill down into different countries
- loc_field = domain.create_index_field('location', 'text', facet=True)
+ >>> # But it would be neat to drill down into different countries
+ >>> loc_field = domain.create_index_field('location', 'text', facet=True)
- # Epoch time of when the user last did something
- time_field = domain.create_index_field('last_activity', 'uint', default=0)
+ >>> # Epoch time of when the user last did something
+ >>> time_field = domain.create_index_field('last_activity', 'uint', default=0)
- follower_field = domain.create_index_field('follower_count', 'uint', default=0)
+ >>> follower_field = domain.create_index_field('follower_count', 'uint', default=0)
- domain.create_rank_expression('recently_active', 'last_activity') # We'll want to be able to just show the most recently active users
+ >>> domain.create_rank_expression('recently_active', 'last_activity') # We'll want to be able to just show the most recently active users
- domain.create_rank_expression('activish', 'text_relevance + ((follower_count/(time() - last_activity))*1000)') # Let's get trickier and combine text relevance with a really dynamic expression
+ >>> domain.create_rank_expression('activish', 'text_relevance + ((follower_count/(time() - last_activity))*1000)') # Let's get trickier and combine text relevance with a really dynamic expression
Viewing and Adjusting Stemming for a Domain
--------------------------------------------
@@ -182,10 +182,10 @@ Adding Documents to the Index
Now, we can add some documents to our new search domain.
- doc_service = domain.get_document_service()
+ >>> doc_service = domain.get_document_service()
- # Presumably get some users from your db of choice.
- users = [
+ >>> # Presumably get some users from your db of choice.
+ >>> users = [
{
'id': 1,
'username': 'dan',
@@ -216,10 +216,10 @@ Now, we can add some documents to our new search domain.
}
]
- for user in users:
- doc_service.add(user['id'], user['last_activity'], user)
+ >>> for user in users:
+ >>> doc_service.add(user['id'], user['last_activity'], user)
- result = doc_service.commit() # Actually post the SDF to the document service
+ >>> result = doc_service.commit() # Actually post the SDF to the document service
The result is an instance of `cloudsearch.CommitResponse` which will
makes the plain dictionary response a nice object (ie result.adds,
@@ -232,33 +232,33 @@ Searching Documents
Now, let's try performing a search.
- # Get an instance of cloudsearch.SearchServiceConnection
- search_service = domain.get_search_service()
+ >>> # Get an instance of cloudsearch.SearchServiceConnection
+ >>> search_service = domain.get_search_service()
- # Horray wildcard search
- query = "username:'dan*'"
+ >>> # Horray wildcard search
+ >>> query = "username:'dan*'"
- results = search_service.search(bq=query, rank=['-recently_active'], start=0, size=10)
+ >>> results = search_service.search(bq=query, rank=['-recently_active'], start=0, size=10)
- # Results will give us back a nice cloudsearch.SearchResults object that looks as
- # close as possible to pysolr.Results
+ >>> # Results will give us back a nice cloudsearch.SearchResults object that looks as
+ >>> # close as possible to pysolr.Results
- print "Got %s results back." % results.hits
- print "User ids are:"
- for result in results:
- print result['id']
+ >>> print "Got %s results back." % results.hits
+ >>> print "User ids are:"
+ >>> for result in results:
+ >>> print result['id']
Deleting Documents
------------------
- import time
- from datetime import datetime
+ >>> import time
+ >>> from datetime import datetime
- doc_service = domain.get_document_service()
+ >>> doc_service = domain.get_document_service()
- # Again we'll cheat and use the current epoch time as our version number
+ >>> # Again we'll cheat and use the current epoch time as our version number
- doc_service.delete(4, int(time.mktime(datetime.utcnow().timetuple())))
- service.commit()
+ >>> doc_service.delete(4, int(time.mktime(datetime.utcnow().timetuple())))
+ >>> service.commit()
View
6 docs/source/simpledb_tut.rst
@@ -109,11 +109,11 @@ Now let's check if it worked::
Batch Adding Items (and attributes)
-----------------------------------
-You can also add a number of items at the same time in a similar fashion. All you have to provide to the batch_put_items() method
+You can also add a number of items at the same time in a similar fashion. All you have to provide to the batch_put_attributes() method
is a Dictionary-like object with your items and their respective attributes, as follows::
>>> items = {'item1':{'attr1':'val1'},'item2':{'attr2':'val2'}}
- >>> dom.batch_put_items(items)
+ >>> dom.batch_put_attributes(items)
True
>>>
@@ -124,7 +124,7 @@ Now, let's check the item count once again::
3
>>>
-A few words of warning: both batch_put_items() and put_item(), by default, will overwrite the values of the attributes if both
+A few words of warning: both batch_put_attributes() and put_item(), by default, will overwrite the values of the attributes if both
the item and attribute already exist. If the item exists, but not the attributes, it will append the new attributes to the
attribute list of that item. If you do not wish these methods to behave in that manner, simply supply them with a 'replace=False'
parameter.

0 comments on commit 6c1aacd

Please sign in to comment.