Skip to content

Commit 60a2d6f

Browse files
committed
Initial commit of Cloud Search API.
1 parent baf58f2 commit 60a2d6f

21 files changed

+3077
-5
lines changed

docs/_static/js/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ $('.headerlink').parent().each(function() {
1616
$('.side-nav').children('ul:nth-child(2)').children().each(function() {
1717
var itemName = $(this).text();
1818
if (itemName !== 'Datastore' && itemName !== 'Storage' &&
19-
itemName !== 'Pub/Sub') {
19+
itemName !== 'Pub/Sub' && itemName !== 'Search') {
2020
$(this).css('padding-left','2em');
2121
}
2222
});

docs/index.rst

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,20 @@
99
datastore-queries
1010
datastore-transactions
1111
datastore-batches
12-
storage-api
13-
storage-blobs
14-
storage-buckets
15-
storage-acl
12+
datastore-dataset
1613
pubsub-api
1714
pubsub-usage
1815
pubsub-subscription
1916
pubsub-topic
17+
search-api
18+
search-client
19+
search-index
20+
search-document
21+
search-field
22+
storage-api
23+
storage-blobs
24+
storage-buckets
25+
storage-acl
2026

2127

2228
Getting started

docs/search-api.rst

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
.. toctree::
2+
:maxdepth: 1
3+
:hidden:
4+
5+
Search
6+
------
7+
8+
Overview
9+
~~~~~~~~
10+
11+
Cloud Search allows you to quickly perform full-text and geospatial searches
12+
against your data without having to spin up your own instances
13+
and without the hassle of managing and maintaining a search service.
14+
15+
Cloud Search provides a model for indexing your documents
16+
that contain structured data,
17+
with documents and indexes saved to a separate persistent store
18+
optimized for search operations.
19+
You can search an index, and organize and present your search results.
20+
The API supports full text matching on string fields
21+
and allows you to index any number of documents in any number of indexes.
22+
23+
Indexes
24+
~~~~~~~
25+
26+
Here's an example of how you might deal with indexes::
27+
28+
>>> from gcloud import search
29+
>>> client = search.Client()
30+
31+
>>> # List all indexes in your project
32+
>>> for index in client.list_indexes():
33+
... print index
34+
35+
>>> # Create a new index
36+
>>> new_index = client.index('index-id-here')
37+
>>> new_index.name = 'My new index'
38+
>>> new_index.create()
39+
40+
>>> # Update an existing index
41+
>>> index = client.get_index('existing-index-id')
42+
>>> print index
43+
<Index: Existing Index (existing-index-id)>
44+
>>> index.name = 'Modified name'
45+
>>> index.update()
46+
>>> print index
47+
<Index: Modified name (existing-index-id)>
48+
49+
>>> # Delete an index
50+
>>> index = client.get_index('existing-index-id')
51+
>>> index.delete()
52+
53+
Documents
54+
~~~~~~~~~
55+
56+
Documents are the things that you search for.
57+
The typical process is:
58+
59+
#. Create a document
60+
#. Add fields to the document
61+
#. Add the document to an index to be searched for later
62+
63+
Here's an example of how you might deal with documents::
64+
65+
>>> from gcloud import search
66+
>>> client = search.Client()
67+
68+
>>> # Create a document
69+
>>> document = search.Document('document-id')
70+
71+
>>> # Add a field to the document
72+
>>> field = search.Field('fieldname')
73+
>>> field.add_value('string')
74+
>>> document.add_field(field)
75+
76+
>>> # Add the document to an index
77+
>>> index = client.get_index('existing-index-id')
78+
>>> index.add_document(document)
79+
80+
Fields
81+
~~~~~~
82+
83+
Fields belong to documents and are the data that actually gets searched.
84+
Each field can have multiple values,
85+
and there are three different types of tokenization for string values:
86+
87+
- **Atom** (``atom``) means "don't tokenize this string", treat it as one thing
88+
to compare against.
89+
- **Text** (``text``) means "treat this string as normal text" and split words
90+
apart to be compared against.
91+
- **HTML** (``html``) means "treat this string as HTML", understanding the
92+
tags, and treating the rest of the content like Text.
93+
94+
You can set this using the ``tokenization`` paramater when adding a field
95+
value::
96+
97+
>>> from gcloud import search
98+
>>> document = search.Document('document-id')
99+
>>> document.add_field(search.Field('field-name', values=[
100+
... search.Value('britney spears', tokenization='atom'),
101+
... search.Value('<h1>Britney Spears</h1>', tokenization='html'),
102+
... ]))
103+
104+
Searching
105+
~~~~~~~~~
106+
107+
Once you have indexes full of documents, you can search through them by
108+
issuing a search query.
109+
110+
Here's a simple example of how you might start searching::
111+
112+
>>> from gcloud import search
113+
>>> client = search.Client()
114+
115+
>>> index = client.get_index('existing-index-id')
116+
>>> query = search.Query('britney spears')
117+
>>> matching_documents = index.search(query)
118+
>>> for document in matching_documents:
119+
... print document
120+
121+
By default, all queries are sorted by the ``rank`` value you set
122+
when the documented was created.
123+
If you want to sort differently, use the ``order_by`` parameter::
124+
125+
>>> from gcloud import search
126+
>>> query = search.Query('britney spears', order_by=['field1', '-field2'])
127+
128+
Note that the ``-`` character before ``field2`` means that
129+
this query will be sorted ascending by ``field1``
130+
and then descending by ``field2``.
131+
132+
If you want only want certain fields to be returned in the match,
133+
you can use the ``fields`` paramater::
134+
135+
>>> from gcloud import search
136+
>>> query = search.Query('britney spears', fields=['field1', 'field2'])
137+

docs/search-client.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.. toctree::
2+
:maxdepth: 0
3+
:hidden:
4+
5+
Client
6+
------
7+
8+
.. automodule:: gcloud.search.client
9+
:members:
10+
:undoc-members:
11+
:show-inheritance:
12+
13+
Connection
14+
~~~~~~~~~~
15+
16+
.. automodule:: gcloud.search.connection
17+
:members:
18+
:undoc-members:
19+
:show-inheritance:

docs/search-document.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.. toctree::
2+
:maxdepth: 0
3+
:hidden:
4+
5+
Document
6+
--------
7+
8+
.. automodule:: gcloud.search.document
9+
:members:
10+
:undoc-members:
11+
:show-inheritance:

docs/search-field.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.. toctree::
2+
:maxdepth: 0
3+
:hidden:
4+
5+
Field
6+
-----
7+
8+
.. automodule:: gcloud.search.field
9+
:members:
10+
:undoc-members:
11+
:show-inheritance:
12+
13+
Value
14+
~~~~~
15+
16+
.. automodule:: gcloud.search.value
17+
:members:
18+
:undoc-members:
19+
:show-inheritance:

docs/search-index.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.. toctree::
2+
:maxdepth: 0
3+
:hidden:
4+
5+
Index
6+
-----
7+
8+
.. automodule:: gcloud.search.index
9+
:members:
10+
:undoc-members:
11+
:show-inheritance:

0 commit comments

Comments
 (0)