|
4 | 4 | service = CloudantV1.new_instance()
|
5 | 5 |
|
6 | 6 | email_view_map_reduce = DesignDocumentViewsMapReduce(
|
7 |
| - map='function(doc) { if(doc.email_verified === true){\n emit(doc.email, [doc.name, doc.email_verified, doc.joined]) }}' |
| 7 | + map='function(doc) { if(doc.email_verified === true) { emit(doc.email, [doc.name, doc.email_verified, doc.joined]); }}' |
8 | 8 | )
|
9 | 9 |
|
10 | 10 | user_index = SearchIndexDefinition(
|
11 |
| - index='function (doc) { index("name", doc.name); index("active", doc.active); }', |
| 11 | + index='function(doc) { index("name", doc.name); index("active", doc.active); }', |
12 | 12 | analyzer=AnalyzerConfiguration(name="standard", fields={"email": Analyzer(name="email")}))
|
13 | 13 |
|
14 | 14 | design_document = DesignDocument(
|
|
27 | 27 | # Partitioned DesignDocument Example
|
28 | 28 |
|
29 | 29 | product_map = DesignDocumentViewsMapReduce(
|
30 |
| - map='function(doc) { emit(doc.productId, [doc.brand, doc.name, doc.description]) }' |
| 30 | + map='function(doc) { emit(doc.productId, [doc.date, doc.eventType, doc.userId]); }' |
31 | 31 | )
|
32 | 32 |
|
33 |
| -price_index = SearchIndexDefinition( |
34 |
| - index='function (doc) { index("price", doc.price);}', |
| 33 | +date_index = SearchIndexDefinition( |
| 34 | + index='function(doc) { index("date", doc.date); }', |
35 | 35 | analyzer=AnalyzerConfiguration(name="classic", fields={"description": Analyzer(name="english")})
|
36 | 36 | )
|
37 | 37 |
|
|
40 | 40 | )
|
41 | 41 |
|
42 | 42 | partitioned_design_doc = DesignDocument(
|
43 |
| - views={'byApplianceProdId': product_map}, |
44 |
| - indexes={'findByPrice': price_index}, |
| 43 | + views={'byProductId': product_map}, |
| 44 | + indexes={'findByDate': date_index}, |
45 | 45 | options=design_document_options
|
46 | 46 | )
|
47 | 47 |
|
48 | 48 | response = service.put_design_document(
|
49 |
| - db='products', |
| 49 | + db='events', |
50 | 50 | design_document=partitioned_design_doc,
|
51 |
| - ddoc='appliances' |
| 51 | + ddoc='checkout' |
52 | 52 | ).get_result()
|
53 | 53 |
|
54 | 54 | print(response)
|
55 | 55 | # section: markdown
|
56 |
| -# This example creates `allusers` design document in the `users` database and `appliances` design document in the partitioned `products` database. |
| 56 | +# This example creates `allusers` design document in the `users` database and `checkout` design document in the partitioned `events` database. |
0 commit comments