Skip to content
Snippets Groups Projects
Commit 58191300 authored by Remi  PLANEL's avatar Remi PLANEL
Browse files

update package to load articles in ms

parent ea47dd60
No related branches found
No related tags found
1 merge request!224Resolve "Rework references"
Pipeline #123578 waiting for manual action
...@@ -237,6 +237,29 @@ def update_systems( ...@@ -237,6 +237,29 @@ def update_systems(
index.update_typo_tolerance({"enabled": False}) index.update_typo_tolerance({"enabled": False})
def update_articles(
host: str,
key: str,
file: Path,
document: str,
):
client = meilisearch.Client(host, key)
index = client.index(document.lower())
with open(file, "r") as jsonfile:
json_object = json.load(jsonfile)
for obj in json_object:
obj["ms_id"] = obj["id"].replace("/", "_")
tasks = index.add_documents_in_batches(json_object, primary_key="ms_id")
for task in tasks:
print(task)
pagination_settings_task = index.update_pagination_settings(
{"maxTotalHits": 100000}
)
print(pagination_settings_task)
def split_on_comma(str_val: str) -> List[str]: def split_on_comma(str_val: str) -> List[str]:
for val in str_val.split(","): for val in str_val.split(","):
yield val.strip() yield val.strip()
...@@ -2,7 +2,12 @@ import typer ...@@ -2,7 +2,12 @@ import typer
import meilisearch import meilisearch
from typing_extensions import Annotated from typing_extensions import Annotated
from pathlib import Path from pathlib import Path
from df_wiki_cli.meilisearch import update_refseq, update_structure, update_systems from df_wiki_cli.meilisearch import (
update_articles,
update_refseq,
update_structure,
update_systems,
)
from enum import Enum from enum import Enum
from types import SimpleNamespace from types import SimpleNamespace
from rich.console import Console from rich.console import Console
...@@ -17,6 +22,7 @@ class Documents(str, Enum): ...@@ -17,6 +22,7 @@ class Documents(str, Enum):
refseq = "refseq" refseq = "refseq"
structure = "structure" structure = "structure"
systems = "systems" systems = "systems"
article = "article"
@app.callback() @app.callback()
...@@ -61,6 +67,8 @@ def update( ...@@ -61,6 +67,8 @@ def update(
update_structure(ctx.obj.host, ctx.obj.key, file, document) update_structure(ctx.obj.host, ctx.obj.key, file, document)
if document == "systems": if document == "systems":
update_systems(ctx.obj.host, ctx.obj.key, file, document) update_systems(ctx.obj.host, ctx.obj.key, file, document)
if document == "article":
update_articles(ctx.obj.host, ctx.obj.key, file, document)
@app.command() @app.command()
......
[tool.poetry] [tool.poetry]
name = "df-wiki-cli" name = "df-wiki-cli"
version = "0.1.5" version = "0.1.6"
description = "" description = ""
authors = ["Remi PLANEL <rplanel@pasteur.fr>"] authors = ["Remi PLANEL <rplanel@pasteur.fr>"]
readme = "README.md" readme = "README.md"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment