def mergeindex(path): """Merge searchindex files in subdirectories of `path` and create a searchindex files under `path` """ merger = SearchIndexMerger() for entry in os.listdir(path): index_path = os.path.join(path, entry, "searchindex.js") if not os.path.exists(index_path): continue key = os.path.basename(os.path.dirname(index_path)) merger.load_index(key, index_path) with open(os.path.join(path, "searchindex.js"), "wb") as h: output = merger.merge() h.write(js_index.dumps(output))
def mergeindex(path): """Merge searchindex files in subdirectories of `path` and create a searchindex files under `path` """ merger = SearchIndexMerger() for entry in os.listdir(path): index_path = os.path.join(path, entry, "searchindex.js") if not os.path.exists(index_path): continue key = os.path.basename(os.path.dirname(index_path)) merger.load_index(key, index_path) with io.open(os.path.join(path, "searchindex.js"), "w", encoding="utf-8") as h: output = merger.merge() h.write(js_index.dumps(output))
def merge(path, include_terms=False, exclude_old=True): """Merge searchindex files in subdirectories of `path` and create a searchindex files under `path` """ groups = {} merger = SearchIndexMerger() for entry in os.listdir(path): index_path = os.path.join(path, entry, "searchindex.js") if not os.path.exists(index_path): continue namespace, version = os.path.basename( os.path.dirname(index_path)).split("-") with open(index_path, "rb") as h: data = h.read() mod = js_index.loads(data) groups.setdefault(namespace, []).append((version, mod)) def sort_version_key(version): return tuple(map(int, version.split("."))) for namespace, entries in sorted(groups.items()): # newest first, for name clashes entries.sort(key=lambda x: sort_version_key(x[0]), reverse=True) if exclude_old: entries for i, (version, mod) in enumerate(entries): key = namespace + "-" + version if exclude_old and i > 0: merger.add_index(key, None) continue fixup_props_signals(mod) if not include_terms: mod["terms"].clear() mod["titleterms"].clear() merger.add_index(key, mod) with open(os.path.join(path, "searchindex.js"), "wb") as h: output = merger.merge() h.write(js_index.dumps(output))