|
27 | 27 | @option("-A", "--auto_paginate", is_flag=True, help="Return all results. Will call Admin API multiple times.") |
28 | 28 | @option("-F", "--force", is_flag=True, help="Skip confirmation when running --auto-paginate.") |
29 | 29 | @option("-ff", "--filter_fields", multiple=True, help="Filter fields to return.") |
| 30 | +@option("-t", "--ttl", nargs=1, default=300, help="Set the Search URL TTL in seconds. Default: 300.") |
| 31 | +@option("-u", "--url", is_flag=True, help="Build a signed search URL.") |
30 | 32 | @option("--json", nargs=1, help="Save JSON output to a file. Usage: --json <filename>") |
31 | 33 | @option("--csv", nargs=1, help="Save CSV output to a file. Usage: --csv <filename>") |
32 | 34 | @option("-d", "--doc", is_flag=True, help="Open Search API documentation page.") |
33 | 35 | def search(query, with_field, sort_by, aggregate, max_results, next_cursor, |
34 | | - auto_paginate, force, filter_fields, json, csv, doc): |
| 36 | + auto_paginate, force, filter_fields, ttl, url, json, csv, doc): |
35 | 37 | if doc: |
36 | 38 | return launch("https://cloudinary.com/documentation/search_api") |
37 | 39 |
|
38 | 40 | fields_to_keep = [] |
39 | 41 | if filter_fields: |
40 | 42 | fields_to_keep = tuple(normalize_list_params(filter_fields)) + with_field |
41 | 43 |
|
42 | | - expression = cloudinary.search.Search().expression(" ".join(query)) |
| 44 | + search = cloudinary.search.Search().expression(" ".join(query)) |
43 | 45 |
|
44 | 46 | if auto_paginate: |
45 | 47 | max_results = DEFAULT_MAX_RESULTS |
46 | 48 | if with_field: |
47 | 49 | for f in with_field: |
48 | | - expression.with_field(f) |
| 50 | + search.with_field(f) |
49 | 51 | if sort_by: |
50 | | - expression.sort_by(*sort_by) |
| 52 | + search.sort_by(*sort_by) |
51 | 53 | if aggregate: |
52 | | - expression.aggregate(aggregate) |
| 54 | + search.aggregate(aggregate) |
53 | 55 | if next_cursor: |
54 | | - expression.next_cursor(next_cursor) |
| 56 | + search.next_cursor(next_cursor) |
| 57 | + if ttl: |
| 58 | + search.ttl(ttl) |
55 | 59 |
|
56 | | - expression.max_results(max_results) |
| 60 | + search.max_results(max_results) |
57 | 61 |
|
58 | | - res = execute_single_request(expression, fields_to_keep) |
| 62 | + if url: |
| 63 | + print(search.to_url()) |
| 64 | + return True |
| 65 | + |
| 66 | + res = execute_single_request(search, fields_to_keep) |
59 | 67 |
|
60 | 68 | if auto_paginate: |
61 | | - res = handle_auto_pagination(res, expression, force, fields_to_keep) |
| 69 | + res = handle_auto_pagination(res, search, force, fields_to_keep) |
62 | 70 |
|
63 | 71 | print_json(res) |
64 | 72 |
|
|
0 commit comments