diff --git a/composables/useFetchArticle.ts b/composables/useFetchArticle.ts index 59c1e51851cd53369ccd27d4db85c17b86508d28..760b25c9f3b8f8523c732b9ad79f972dc7b0874c 100644 --- a/composables/useFetchArticle.ts +++ b/composables/useFetchArticle.ts @@ -1,48 +1,14 @@ -import { useArticlesStore, type CslJson } from '../stores/articles' +import { useArticlesStore } from '../stores/articles' import { ref, computed, watchEffect, toValue } from "vue" // import { useFetch } from '#app'; // import { useFetch } from "nuxt" import { type MaybeRef, useFetch } from '#imports' -import article from "@/public/articles.json" - -export interface CrossrefArticle { - DOI: string; - issue: number; - type: string; - title: string[]; - author: Array<{ family: string; given: string }>; - // "container-title-short": string; - "short-container-title": string; - "container-title": string; - abstract?: string; - published: { - "date-parts": string[]; - }; - issued: { - "date-parts": string[]; - }; -} +import type { CslJson, CrossrefArticle, SrcArticle } from '@/types/articles'; -export interface WikiArticle { - DOI: string - title: string - subtitle: string - author: Array<{ family: string; given: string }> - containerTitle: string - abstract: string - year: string - href: string - target: string - prependIcon: string -} -export interface RawArticle { - message: CrossrefArticle -} -type SrcArticle = CrossrefArticle | CslJson export function useFetchArticle(doi: MaybeRef<string> = ref("")) { // const article = ref<Article>() diff --git a/packages/df-wiki-cli/df_wiki_cli/meilisearch/__init__.py b/packages/df-wiki-cli/df_wiki_cli/meilisearch/__init__.py index 1111225625f07cbc4584ae571646350cbe00a998..c680483d34b4f66c519e4ed3084ecca8e5a5fa90 100644 --- a/packages/df-wiki-cli/df_wiki_cli/meilisearch/__init__.py +++ b/packages/df-wiki-cli/df_wiki_cli/meilisearch/__init__.py @@ -308,6 +308,29 @@ def update_systems( 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]: for val in str_val.split(","): yield val.strip() diff --git a/packages/df-wiki-cli/df_wiki_cli/meilisearch/main.py b/packages/df-wiki-cli/df_wiki_cli/meilisearch/main.py index f32ac8c3af221457efe03522b7e0bdf206f0c610..e6cb0e7b9c38fe0874f3efa988810e8494633c9f 100644 --- a/packages/df-wiki-cli/df_wiki_cli/meilisearch/main.py +++ b/packages/df-wiki-cli/df_wiki_cli/meilisearch/main.py @@ -3,10 +3,11 @@ import meilisearch from typing_extensions import Annotated from pathlib import Path from df_wiki_cli.meilisearch import ( + update_refseqtaxo, + update_articles, update_refseq, update_structure, update_systems, - update_refseqtaxo, ) from enum import Enum from types import SimpleNamespace @@ -23,6 +24,7 @@ class Documents(str, Enum): refseq = "refseq" structure = "structure" systems = "systems" + article = "article" @app.callback() @@ -69,6 +71,8 @@ def update( update_structure(ctx.obj.host, ctx.obj.key, file, document) if document == "systems": 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() diff --git a/stores/articles.ts b/stores/articles.ts index 1ba95fd2d0584f76814bd6818b4ab794bf0f534a..a28c03bc198d9a37f77cf10e1831765f45fcfc05 100644 --- a/stores/articles.ts +++ b/stores/articles.ts @@ -1,24 +1,8 @@ import { defineStore } from 'pinia' import { ref } from 'vue' // import jsonArticles from '@/assets/articles.json' +import type { CslJson } from "@/types/articles" -export interface CslJson { - // id: string - type: string - title: string - "container-title": string - // page: string, - // volume: string, - abstract: string - // URL: string - DOI: string - // journalAbbreviation: string - // language: string - author: Array<{ family: string, given: string }> - issued: { - "date-parts": Array<string> - }, -} export const useArticlesStore = defineStore('articles', () => { const articleMap = new Map([]) diff --git a/types/articles.ts b/types/articles.ts new file mode 100644 index 0000000000000000000000000000000000000000..92f2f10debb602df6ceac169d3b7cc74b202ebfe --- /dev/null +++ b/types/articles.ts @@ -0,0 +1,55 @@ +export interface WikiArticle { + DOI: string + title: string + subtitle: string + author: Array<{ family: string; given: string }> + containerTitle: string + abstract: string + year: string + href: string + target: string + prependIcon: string +} + +export interface CslJson { + // id: string + type: string + title: string + "container-title": string + // page: string, + // volume: string, + abstract: string + // URL: string + DOI: string + // journalAbbreviation: string + // language: string + author: Array<{ family: string, given: string }> + issued: { + "date-parts": Array<string> + }, +} + +export interface CrossrefArticle { + DOI: string; + issue: number; + type: string; + title: string[]; + author: Array<{ family: string; given: string }>; + // "container-title-short": string; + "short-container-title": string; + "container-title": string; + abstract?: string; + published: { + "date-parts": string[]; + }; + issued: { + "date-parts": string[]; + }; +} + +export interface RawArticle { + message: CrossrefArticle + +} + +export type SrcArticle = CrossrefArticle | CslJson