-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathset_settings.py
36 lines (29 loc) · 1.32 KB
/
set_settings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from algoliasearch.search_client import SearchClient
# Import the environment variables from the .env file
from dotenv import load_dotenv
import os
load_dotenv()
# Algolia client credentials
ALGOLIA_APP_ID = os.getenv('ALGOLIA_APP_ID')
ALGOLIA_API_KEY = os.getenv('ALGOLIA_API_KEY')
ALGOLIA_INDEX_NAME = os.getenv('ALGOLIA_INDEX_NAME')
# Initialize the client
# https://www.algolia.com/doc/api-client/getting-started/initialize/python/?client=python
client = SearchClient.create(ALGOLIA_APP_ID, ALGOLIA_API_KEY)
# Initialize the index
# https://www.algolia.com/doc/api-client/getting-started/initialize/python/?client=python
index = client.init_index(ALGOLIA_INDEX_NAME)
# Set your index settings
# attributesForFaceting
# https://www.algolia.com/doc/api-reference/api-parameters/attributesForFaceting/
# filterOnly : the attribute will be filterable only and not facetable.
# searchable : the attribute will be be searchable.
# customRanking : You can decide whether the order should be descending or ascending.
# https://www.algolia.com/doc/guides/managing-results/must-do/custom-ranking/
index.set_settings({
"searchableAttributes": ["name", "address"],
'attributesForFaceting': ["name", "filterOnly(address)","searchable(followers)"],
"customRanking": ["desc(followers)"]
})
# Get index configuration
print(index.get_settings())