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

Skip to content

Update ref search #1462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ search_readme :

update_js_search :
@echo "Install algoliasearch python package:"
pip install --upgrade algoliasearch
pip install algoliasearch==1.20.0
@echo "Updating js_docs search index"
python update_js_docs_search.py

Expand All @@ -21,6 +21,6 @@ update_r_search :

update_ref_search :
@echo "Install algoliasearch python package:"
pip install --upgrade algoliasearch
pip install algoliasearch==1.20.0
@echo "Updating search for reference pages"
python update_ref_search.py
171 changes: 29 additions & 142 deletions update_ref_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
schema = []

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

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

## Data Level 2: Nested Attributes

for i in p['schema']['traces']:
for att1 in p['schema']['traces'][i]['attributes']:
if not any(value in att1 for value in ("src", "_deprecated", "impliedEdits", "uid", "editType")):
try:
attribute = {}
attribute ['name'] = i+' > '+att1
attribute ['permalink'] = 'reference/#'+i+'-'+att1
attribute ['description'] = (p['schema']['traces'][i]['attributes'][att1]['description']).replace('*', '"')
schema.append(attribute)
except:
attribute = {}
attribute ['name'] = i+' > '+att1
attribute ['permalink'] = 'reference/#'+i+'-'+att1
attribute ['description'] = 'Properties for '+att1
schema.append(attribute)
for att2 in p['schema']['traces'][i]['attributes'][att1]:
if not any(value in att2 for value in ("src", "_deprecated", "impliedEdits", "uid", "editType")):
try:
if isinstance(p['schema']['traces'][i]['attributes'][att1][att2], dict):
try:
attribute = {}
attribute ['name'] = i+' > '+att1+' > '+att2
attribute ['permalink'] = 'reference/#'+i+'-'+att1+'-'+att2
attribute ['description'] = (p['schema']['traces'][i]['attributes'][att1][att2]['description']).replace('*', '"')
schema.append(attribute)
except:
attribute = {}
attribute ['name'] = i+' > '+att1+' > '+att2
attribute ['permalink'] = 'reference/#'+i+'-'+att1+'-'+att2
attribute ['description'] = 'Properties for '+att2
schema.append(attribute)
except:
pass
try:
for att3 in p['schema']['traces'][i]['attributes'][att1][att2]:
if not any(value in att3 for value in ("src", "_deprecated", "impliedEdits", "uid", "editType")):
try:
if isinstance(p['schema']['traces'][i]['attributes'][att1][att2][att3], dict):
try:
attribute = {}
attribute ['name'] = i+' > '+att1+' > '+att2+' > '+att3
attribute ['permalink'] = 'reference/#'+i+'-'+att1+'-'+att2+'-'+att3
attribute ['description'] = (p['schema']['traces'][i]['attributes'][att1][att2][att3]['description']).replace('*', '"')
schema.append(attribute)
except:
attribute = {}
attribute ['name'] = i+' > '+att1+' > '+att2+' > '+att3
attribute ['permalink'] = 'reference/#'+i+'-'+att1+'-'+att2+'-'+att3
attribute ['description'] = 'Properties for '+att3
schema.append(attribute)
except:
pass
try:
for att4 in p['schema']['traces'][i]['attributes'][att1][att2][att3]:
if not any(value in att4 for value in ("src", "_deprecated", "impliedEdits", "uid", "editType")):
try:
if isinstance(p['schema']['traces'][i]['attributes'][att1][att2][att3][att4], dict):
try:
attribute = {}
attribute ['name'] = i+' > '+att1+' > '+att2+' > '+att3+' > '+att4
attribute ['permalink'] = 'reference/#'+i+'-'+att1+'-'+att2+'-'+att3+'-'+att4
attribute ['description'] = (p['schema']['traces'][i]['attributes'][att1][att2][att3][att4]['description']).replace('*', '"')
schema.append(attribute)
except:
attribute = {}
attribute ['name'] = i+' > '+att1+' > '+att2+' > '+att3+' > '+att4
attribute ['permalink'] = 'reference/#'+i+'-'+att1+'-'+att2+'-'+att3+'-'+att4
attribute ['description'] = 'Properties for '+att4
schema.append(attribute)
except:
pass
except:
pass
except:
pass

## Layout Attributes

for att1 in p['schema']['layout']['layoutAttributes']:
if not any(value in att1 for value in ("src", "_deprecated", "impliedEdits", "uid", "editType")):
def next_level(previous_level,chain_dict):
for sub_attr in previous_level:
try:
attribute = {}
attribute ['name'] = 'Layout > '+att1
attribute ['permalink'] = 'reference/#layout-'+att1
attribute ['description'] = (p['schema']['layout']['layoutAttributes'][att1]['description']).replace('*', '"')
schema.append(attribute)
except:
attribute = {}
attribute ['name'] = 'Layout > '+att1
attribute ['permalink'] = 'reference/#layout-'+att1
attribute ['description'] = 'Properties for '+att1
schema.append(attribute)
for att2 in p['schema']['layout']['layoutAttributes'][att1]:
if not any(value in att2 for value in ("src", "_deprecated", "impliedEdits", "uid", "editType")):
try:
if isinstance(p['schema']['layout']['layoutAttributes'][att1][att2], dict):
if isinstance(previous_level[sub_attr],dict):
if not any(value in sub_attr for value in ("src", "_deprecated", "impliedEdits", "uid", "editType")):
try:
attribute = {}
attribute ['name'] = 'Layout > '+att1+' > '+att2
attribute ['permalink'] = 'reference/#layout-'+att1+'-'+att2
attribute ['description'] = (p['schema']['layout']['layoutAttributes'][att1][att2]['description']).replace('*', '"')
attribute ['name'] = chain_dict['name']+' > '+sub_attr
attribute ['permalink'] = chain_dict['permalink']+'-'+sub_attr
attribute ['description'] = (previous_level[sub_attr]['description']).replace('*', '"')
schema.append(attribute)
next_level(previous_level[sub_attr],{'name':attribute['name'], 'permalink':attribute['permalink']})
except:
attribute = {}
attribute ['name'] = 'Layout > '+att1+' > '+att2
attribute ['permalink'] = 'reference/#layout-'+att1+'-'+att2
attribute ['description'] = 'Properties for '+att2
attribute ['name'] = chain_dict['name']+' > '+sub_attr
attribute ['permalink'] = chain_dict['permalink']+'-'+sub_attr
attribute ['description'] = 'Properties for '+sub_attr
schema.append(attribute)
except:
pass
try:
for att3 in p['schema']['layout']['layoutAttributes'][att1][att2]:
if not any(value in att3 for value in ("src", "_deprecated", "impliedEdits", "uid", "editType")):
if isinstance(p['schema']['layout']['layoutAttributes'][att1][att2][att3], dict):
try:
attribute = {}
attribute ['name'] = 'Layout > '+att1+' > '+att2+' > '+att3
attribute ['permalink'] = 'reference/#layout-'+att1+'-'+att2+'-'+att3
attribute ['description'] = (p['schema']['layout']['layoutAttributes'][att1][att2][att3]['description']).replace('*', '"')
schema.append(attribute)
except:
attribute = {}
attribute ['name'] = 'Layout > '+att1+' > '+att2+' > '+att3
attribute ['permalink'] = 'reference/#layout-'+att1+'-'+att2+'-'+att3
attribute ['description'] = 'Properties for '+att3
schema.append(attribute)
try:
for att4 in p['schema']['layout']['layoutAttributes'][att1][att2][att3]:
if not any(value in att4 for value in ("src", "_deprecated", "impliedEdits", "uid", "editType")):
if isinstance(p['schema']['layout']['layoutAttributes'][att1][att2][att3][att4], dict):
try:
attribute = {}
attribute ['name'] = 'Layout > '+att1+' > '+att2+' > '+att3+' > '+att4
attribute ['permalink'] = 'reference/#layout-'+att1+'-'+att2+'-'+att3+'-'+att4
attribute ['description'] = (p['schema']['layout']['layoutAttributes'][att1][att2][att3][att4]['description']).replace('*', '"')
schema.append(attribute)
except:
attribute = {}
attribute ['name'] = 'Layout > '+att1+' > '+att2+' > '+att3+' > '+att4
attribute ['permalink'] = 'reference/#layout-'+att1+'-'+att2+'-'+att3+'-'+att4
attribute ['description'] = 'Properties for '+att4
schema.append(attribute)
except:
pass
except:
pass
next_level(previous_level[sub_attr],{'name':attribute['name'], 'permalink':attribute['permalink']})
except:
pass

layout_chain_dict = {'name':'Layout', 'permalink':'reference/#layout'}

# recursively add trace attributes to schema
for i in p['schema']['traces']:
chain_dict = {'name':i, 'permalink':'reference/#'+i }
next_level(p['schema']['traces'][i]['attributes'], chain_dict)

# if there are layoutAttributes in the trace add them too.
if p['schema']['traces'][i].get('layoutAttributes'):
next_level(p['schema']['traces'][i]['layoutAttributes'], layout_chain_dict)

# recursively add layout attributes to schema
next_level(p['schema']['layout']['layoutAttributes'], layout_chain_dict)

## Send to Algolia

Expand Down