|
1 |
| -from os import environ |
2 |
| - |
3 |
| -from algoliasearch.search.client import SearchClientSync |
4 |
| -from algoliasearch.search.config import SearchConfig |
5 | 1 | from algoliasearch.search import __version__
|
| 2 | +from algoliasearch.search.client import SearchClientSync, SearchClient |
| 3 | +from algoliasearch.search.config import SearchConfig |
| 4 | +from asyncio import run |
6 | 5 | from dotenv import load_dotenv
|
| 6 | +from os import environ |
7 | 7 |
|
8 | 8 | load_dotenv("../.env")
|
9 | 9 |
|
10 | 10 |
|
11 |
| -def main(): |
12 |
| - print("SearchClient version", __version__) |
13 |
| - |
14 |
| - client = SearchClientSync( |
| 11 | +# def main(): |
| 12 | +# print("SearchClient version", __version__) |
| 13 | +# |
| 14 | +# client = SearchClientSync( |
| 15 | +# environ.get("ALGOLIA_APPLICATION_ID"), environ.get("ALGOLIA_ADMIN_KEY") |
| 16 | +# ) |
| 17 | +# client.add_user_agent("playground") |
| 18 | +# client.add_user_agent("bar", "baz") |
| 19 | +# |
| 20 | +# print("user_agent", client._config._user_agent.get()) |
| 21 | +# print("client initialized", client) |
| 22 | +# |
| 23 | +# try: |
| 24 | +# resp = client.search_single_index("poussing-RECORDS") |
| 25 | +# print(resp.to_dict()) |
| 26 | +# finally: |
| 27 | +# client.close() |
| 28 | +# |
| 29 | +# print("client closed") |
| 30 | + |
| 31 | + |
| 32 | +async def asyncmain(): |
| 33 | + client = SearchClient( |
15 | 34 | environ.get("ALGOLIA_APPLICATION_ID"), environ.get("ALGOLIA_ADMIN_KEY")
|
16 | 35 | )
|
17 |
| - client.add_user_agent("playground") |
18 |
| - client.add_user_agent("bar", "baz") |
19 | 36 |
|
20 |
| - print("user_agent", client._config._user_agent.get()) |
21 | 37 | print("client initialized", client)
|
22 | 38 |
|
23 | 39 | try:
|
24 |
| - resp = client.search_single_index("poussing-RECORDS") |
25 |
| - print(resp.to_dict()) |
| 40 | + await client.search_single_index("poussing-RECDS") |
| 41 | + print("resp ok") |
26 | 42 | finally:
|
27 |
| - client.close() |
28 |
| - |
29 |
| - print("client closed") |
30 |
| - |
31 |
| - # print("with transformations") |
32 |
| - # |
33 |
| - # config = SearchConfig( |
34 |
| - # environ.get("ALGOLIA_APPLICATION_ID"), environ.get("ALGOLIA_ADMIN_KEY") |
35 |
| - # ) |
36 |
| - # |
37 |
| - # config.set_transformation_region("eu") |
38 |
| - # |
39 |
| - # print("region in playground") |
40 |
| - # print(config.region) |
41 |
| - # |
42 |
| - # client = SearchClientSync.create_with_config(config) |
43 |
| - # client.add_user_agent("playground search with ingestion") |
44 |
| - # |
45 |
| - # print("user_agent", client._config._user_agent.get()) |
46 |
| - # |
47 |
| - # try: |
48 |
| - # resp = client.replace_all_objects_with_transformation( |
49 |
| - # "boyd", [{"objectID": "bar"},{"objectID": "bar"},{"objectID": "bar"},{"objectID": "bar"},{"objectID": "bar"}], 2 |
50 |
| - # ) |
51 |
| - # print(resp) |
52 |
| - # except Exception as e: |
53 |
| - # print(e) |
54 |
| - # finally: |
55 |
| - # client.close() |
56 |
| - # |
57 |
| - # print("client closed") |
| 43 | + await client.close() |
| 44 | + |
| 45 | + print("client closed", client) |
| 46 | + |
| 47 | + |
| 48 | +run(asyncmain()) |
0 commit comments