Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 76d65f1

Browse files
authored
Merge pull request plotly#1462 from plotly/update_ref_search
Update ref search
2 parents 18a8949 + cad5dd2 commit 76d65f1

File tree

2 files changed

+31
-144
lines changed

2 files changed

+31
-144
lines changed

makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ search_readme :
77

88
update_js_search :
99
@echo "Install algoliasearch python package:"
10-
pip install --upgrade algoliasearch
10+
pip install algoliasearch==1.20.0
1111
@echo "Updating js_docs search index"
1212
python update_js_docs_search.py
1313

@@ -21,6 +21,6 @@ update_r_search :
2121

2222
update_ref_search :
2323
@echo "Install algoliasearch python package:"
24-
pip install --upgrade algoliasearch
24+
pip install algoliasearch==1.20.0
2525
@echo "Updating search for reference pages"
2626
python update_ref_search.py

update_ref_search.py

Lines changed: 29 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
schema = []
1616

1717
## Data Level 1: Traces
18-
# Add trace dictionaries to schema array.
18+
# Add dictionaries to schema array.
1919
# The trace dictionary include name: trace name, permalink: reference/#trace-name, and description if applicable.
2020

2121
for i in p['schema']['traces']:
@@ -27,154 +27,41 @@
2727
else: pass
2828
schema.append(trace)
2929

30-
## Data Level 2: Nested Attributes
31-
32-
for i in p['schema']['traces']:
33-
for att1 in p['schema']['traces'][i]['attributes']:
34-
if not any(value in att1 for value in ("src", "_deprecated", "impliedEdits", "uid", "editType")):
35-
try:
36-
attribute = {}
37-
attribute ['name'] = i+' > '+att1
38-
attribute ['permalink'] = 'reference/#'+i+'-'+att1
39-
attribute ['description'] = (p['schema']['traces'][i]['attributes'][att1]['description']).replace('*', '"')
40-
schema.append(attribute)
41-
except:
42-
attribute = {}
43-
attribute ['name'] = i+' > '+att1
44-
attribute ['permalink'] = 'reference/#'+i+'-'+att1
45-
attribute ['description'] = 'Properties for '+att1
46-
schema.append(attribute)
47-
for att2 in p['schema']['traces'][i]['attributes'][att1]:
48-
if not any(value in att2 for value in ("src", "_deprecated", "impliedEdits", "uid", "editType")):
49-
try:
50-
if isinstance(p['schema']['traces'][i]['attributes'][att1][att2], dict):
51-
try:
52-
attribute = {}
53-
attribute ['name'] = i+' > '+att1+' > '+att2
54-
attribute ['permalink'] = 'reference/#'+i+'-'+att1+'-'+att2
55-
attribute ['description'] = (p['schema']['traces'][i]['attributes'][att1][att2]['description']).replace('*', '"')
56-
schema.append(attribute)
57-
except:
58-
attribute = {}
59-
attribute ['name'] = i+' > '+att1+' > '+att2
60-
attribute ['permalink'] = 'reference/#'+i+'-'+att1+'-'+att2
61-
attribute ['description'] = 'Properties for '+att2
62-
schema.append(attribute)
63-
except:
64-
pass
65-
try:
66-
for att3 in p['schema']['traces'][i]['attributes'][att1][att2]:
67-
if not any(value in att3 for value in ("src", "_deprecated", "impliedEdits", "uid", "editType")):
68-
try:
69-
if isinstance(p['schema']['traces'][i]['attributes'][att1][att2][att3], dict):
70-
try:
71-
attribute = {}
72-
attribute ['name'] = i+' > '+att1+' > '+att2+' > '+att3
73-
attribute ['permalink'] = 'reference/#'+i+'-'+att1+'-'+att2+'-'+att3
74-
attribute ['description'] = (p['schema']['traces'][i]['attributes'][att1][att2][att3]['description']).replace('*', '"')
75-
schema.append(attribute)
76-
except:
77-
attribute = {}
78-
attribute ['name'] = i+' > '+att1+' > '+att2+' > '+att3
79-
attribute ['permalink'] = 'reference/#'+i+'-'+att1+'-'+att2+'-'+att3
80-
attribute ['description'] = 'Properties for '+att3
81-
schema.append(attribute)
82-
except:
83-
pass
84-
try:
85-
for att4 in p['schema']['traces'][i]['attributes'][att1][att2][att3]:
86-
if not any(value in att4 for value in ("src", "_deprecated", "impliedEdits", "uid", "editType")):
87-
try:
88-
if isinstance(p['schema']['traces'][i]['attributes'][att1][att2][att3][att4], dict):
89-
try:
90-
attribute = {}
91-
attribute ['name'] = i+' > '+att1+' > '+att2+' > '+att3+' > '+att4
92-
attribute ['permalink'] = 'reference/#'+i+'-'+att1+'-'+att2+'-'+att3+'-'+att4
93-
attribute ['description'] = (p['schema']['traces'][i]['attributes'][att1][att2][att3][att4]['description']).replace('*', '"')
94-
schema.append(attribute)
95-
except:
96-
attribute = {}
97-
attribute ['name'] = i+' > '+att1+' > '+att2+' > '+att3+' > '+att4
98-
attribute ['permalink'] = 'reference/#'+i+'-'+att1+'-'+att2+'-'+att3+'-'+att4
99-
attribute ['description'] = 'Properties for '+att4
100-
schema.append(attribute)
101-
except:
102-
pass
103-
except:
104-
pass
105-
except:
106-
pass
107-
108-
## Layout Attributes
109-
110-
for att1 in p['schema']['layout']['layoutAttributes']:
111-
if not any(value in att1 for value in ("src", "_deprecated", "impliedEdits", "uid", "editType")):
30+
def next_level(previous_level,chain_dict):
31+
for sub_attr in previous_level:
11232
try:
113-
attribute = {}
114-
attribute ['name'] = 'Layout > '+att1
115-
attribute ['permalink'] = 'reference/#layout-'+att1
116-
attribute ['description'] = (p['schema']['layout']['layoutAttributes'][att1]['description']).replace('*', '"')
117-
schema.append(attribute)
118-
except:
119-
attribute = {}
120-
attribute ['name'] = 'Layout > '+att1
121-
attribute ['permalink'] = 'reference/#layout-'+att1
122-
attribute ['description'] = 'Properties for '+att1
123-
schema.append(attribute)
124-
for att2 in p['schema']['layout']['layoutAttributes'][att1]:
125-
if not any(value in att2 for value in ("src", "_deprecated", "impliedEdits", "uid", "editType")):
126-
try:
127-
if isinstance(p['schema']['layout']['layoutAttributes'][att1][att2], dict):
33+
if isinstance(previous_level[sub_attr],dict):
34+
if not any(value in sub_attr for value in ("src", "_deprecated", "impliedEdits", "uid", "editType")):
12835
try:
12936
attribute = {}
130-
attribute ['name'] = 'Layout > '+att1+' > '+att2
131-
attribute ['permalink'] = 'reference/#layout-'+att1+'-'+att2
132-
attribute ['description'] = (p['schema']['layout']['layoutAttributes'][att1][att2]['description']).replace('*', '"')
37+
attribute ['name'] = chain_dict['name']+' > '+sub_attr
38+
attribute ['permalink'] = chain_dict['permalink']+'-'+sub_attr
39+
attribute ['description'] = (previous_level[sub_attr]['description']).replace('*', '"')
13340
schema.append(attribute)
41+
next_level(previous_level[sub_attr],{'name':attribute['name'], 'permalink':attribute['permalink']})
13442
except:
13543
attribute = {}
136-
attribute ['name'] = 'Layout > '+att1+' > '+att2
137-
attribute ['permalink'] = 'reference/#layout-'+att1+'-'+att2
138-
attribute ['description'] = 'Properties for '+att2
44+
attribute ['name'] = chain_dict['name']+' > '+sub_attr
45+
attribute ['permalink'] = chain_dict['permalink']+'-'+sub_attr
46+
attribute ['description'] = 'Properties for '+sub_attr
13947
schema.append(attribute)
140-
except:
141-
pass
142-
try:
143-
for att3 in p['schema']['layout']['layoutAttributes'][att1][att2]:
144-
if not any(value in att3 for value in ("src", "_deprecated", "impliedEdits", "uid", "editType")):
145-
if isinstance(p['schema']['layout']['layoutAttributes'][att1][att2][att3], dict):
146-
try:
147-
attribute = {}
148-
attribute ['name'] = 'Layout > '+att1+' > '+att2+' > '+att3
149-
attribute ['permalink'] = 'reference/#layout-'+att1+'-'+att2+'-'+att3
150-
attribute ['description'] = (p['schema']['layout']['layoutAttributes'][att1][att2][att3]['description']).replace('*', '"')
151-
schema.append(attribute)
152-
except:
153-
attribute = {}
154-
attribute ['name'] = 'Layout > '+att1+' > '+att2+' > '+att3
155-
attribute ['permalink'] = 'reference/#layout-'+att1+'-'+att2+'-'+att3
156-
attribute ['description'] = 'Properties for '+att3
157-
schema.append(attribute)
158-
try:
159-
for att4 in p['schema']['layout']['layoutAttributes'][att1][att2][att3]:
160-
if not any(value in att4 for value in ("src", "_deprecated", "impliedEdits", "uid", "editType")):
161-
if isinstance(p['schema']['layout']['layoutAttributes'][att1][att2][att3][att4], dict):
162-
try:
163-
attribute = {}
164-
attribute ['name'] = 'Layout > '+att1+' > '+att2+' > '+att3+' > '+att4
165-
attribute ['permalink'] = 'reference/#layout-'+att1+'-'+att2+'-'+att3+'-'+att4
166-
attribute ['description'] = (p['schema']['layout']['layoutAttributes'][att1][att2][att3][att4]['description']).replace('*', '"')
167-
schema.append(attribute)
168-
except:
169-
attribute = {}
170-
attribute ['name'] = 'Layout > '+att1+' > '+att2+' > '+att3+' > '+att4
171-
attribute ['permalink'] = 'reference/#layout-'+att1+'-'+att2+'-'+att3+'-'+att4
172-
attribute ['description'] = 'Properties for '+att4
173-
schema.append(attribute)
174-
except:
175-
pass
176-
except:
177-
pass
48+
next_level(previous_level[sub_attr],{'name':attribute['name'], 'permalink':attribute['permalink']})
49+
except:
50+
pass
51+
52+
layout_chain_dict = {'name':'Layout', 'permalink':'reference/#layout'}
53+
54+
# recursively add trace attributes to schema
55+
for i in p['schema']['traces']:
56+
chain_dict = {'name':i, 'permalink':'reference/#'+i }
57+
next_level(p['schema']['traces'][i]['attributes'], chain_dict)
58+
59+
# if there are layoutAttributes in the trace add them too.
60+
if p['schema']['traces'][i].get('layoutAttributes'):
61+
next_level(p['schema']['traces'][i]['layoutAttributes'], layout_chain_dict)
62+
63+
# recursively add layout attributes to schema
64+
next_level(p['schema']['layout']['layoutAttributes'], layout_chain_dict)
17865

17966
## Send to Algolia
18067

0 commit comments

Comments
 (0)