Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Fixed SimpleDB, CloudSearch docs #789

Merged
merged 2 commits into from
Jun 5, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 40 additions & 40 deletions docs/source/cloudsearch_tut.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------------------------------------------
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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,
Expand All @@ -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()
6 changes: 3 additions & 3 deletions docs/source/simpledb_tut.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
>>>

Expand All @@ -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.
Expand Down