Skip to content

Commit

Permalink
Merge pull request #789 from srs81/develop
Browse files Browse the repository at this point in the history
Fixed SimpleDB, CloudSearch docs
  • Loading branch information
garnaat committed Jun 5, 2012
2 parents 0d59816 + 6592784 commit 6c1aacd
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 43 deletions.
80 changes: 40 additions & 40 deletions docs/source/cloudsearch_tut.rst
Expand Up @@ -12,32 +12,32 @@ assumes that you have boto already downloaded and installed.
Creating a Domain Creating a Domain
----------------- -----------------


import boto >>> import boto


our_ip = '192.168.1.0' >>> our_ip = '192.168.1.0'


conn = boto.connect_cloudsearch() >>> conn = boto.connect_cloudsearch()
domain = conn.create_domain('demo') >>> domain = conn.create_domain('demo')


# Allow our IP address to access the document and search services >>> # Allow our IP address to access the document and search services
policy = domain.get_access_policies() >>> policy = domain.get_access_policies()
policy.allow_search_ip(our_ip) >>> policy.allow_search_ip(our_ip)
policy.allow_doc_ip(our_ip) >>> policy.allow_doc_ip(our_ip)


# Create an 'text' index field called 'username' >>> # Create an 'text' index field called 'username'
uname_field = domain.create_index_field('username', 'text') >>> uname_field = domain.create_index_field('username', 'text')


# But it would be neat to drill down into different countries >>> # But it would be neat to drill down into different countries
loc_field = domain.create_index_field('location', 'text', facet=True) >>> loc_field = domain.create_index_field('location', 'text', facet=True)


# Epoch time of when the user last did something >>> # Epoch time of when the user last did something
time_field = domain.create_index_field('last_activity', 'uint', default=0) >>> 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 Viewing and Adjusting Stemming for a Domain
-------------------------------------------- --------------------------------------------
Expand Down Expand Up @@ -182,10 +182,10 @@ Adding Documents to the Index


Now, we can add some documents to our new search domain. 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. >>> # Presumably get some users from your db of choice.
users = [ >>> users = [
{ {
'id': 1, 'id': 1,
'username': 'dan', 'username': 'dan',
Expand Down Expand Up @@ -216,10 +216,10 @@ Now, we can add some documents to our new search domain.
} }
] ]


for user in users: >>> for user in users:
doc_service.add(user['id'], user['last_activity'], user) >>> 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 The result is an instance of `cloudsearch.CommitResponse` which will
makes the plain dictionary response a nice object (ie result.adds, makes the plain dictionary response a nice object (ie result.adds,
Expand All @@ -232,33 +232,33 @@ Searching Documents


Now, let's try performing a search. Now, let's try performing a search.


# Get an instance of cloudsearch.SearchServiceConnection >>> # Get an instance of cloudsearch.SearchServiceConnection
search_service = domain.get_search_service() >>> search_service = domain.get_search_service()


# Horray wildcard search >>> # Horray wildcard search
query = "username:'dan*'" >>> 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 >>> # Results will give us back a nice cloudsearch.SearchResults object that looks as
# close as possible to pysolr.Results >>> # close as possible to pysolr.Results


print "Got %s results back." % results.hits >>> print "Got %s results back." % results.hits
print "User ids are:" >>> print "User ids are:"
for result in results: >>> for result in results:
print result['id'] >>> print result['id']




Deleting Documents Deleting Documents
------------------ ------------------


import time >>> import time
from datetime import datetime >>> 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()))) >>> doc_service.delete(4, int(time.mktime(datetime.utcnow().timetuple())))
service.commit() >>> service.commit()
6 changes: 3 additions & 3 deletions docs/source/simpledb_tut.rst
Expand Up @@ -109,11 +109,11 @@ Now let's check if it worked::


Batch Adding Items (and attributes) 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:: is a Dictionary-like object with your items and their respective attributes, as follows::


>>> items = {'item1':{'attr1':'val1'},'item2':{'attr2':'val2'}} >>> items = {'item1':{'attr1':'val1'},'item2':{'attr2':'val2'}}
>>> dom.batch_put_items(items) >>> dom.batch_put_attributes(items)
True True
>>> >>>


Expand All @@ -124,7 +124,7 @@ Now, let's check the item count once again::
3 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 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' 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. parameter.
Expand Down

0 comments on commit 6c1aacd

Please sign in to comment.