diff --git a/lib/action/model/fcs.py b/lib/action/model/fcs.py index da67742862..65881f56d2 100644 --- a/lib/action/model/fcs.py +++ b/lib/action/model/fcs.py @@ -40,6 +40,10 @@ @dataclass class FCSResourceInfo: + pid: str + """ + pid should be a universaly accepted persistent identifier (Handle.Net, DOI etc.) + """ title: str landing_page_uri: Optional[str] = None language: Optional[str] = None @@ -100,6 +104,7 @@ async def corpora_info(self, value: str, max_items: int) -> List[FCSResourceInfo lang_code = get_lang_code(a2=cinfo.collator_locale.split('_')[0]) resources.append( FCSResourceInfo( + pid=corpus_id, # TODO we need something like an ID from Handle.Net or DOI title=corpus_id, description=cinfo.localized_desc('en'), landing_page_uri=cinfo.web, @@ -148,7 +153,13 @@ async def fcs_scan(self, corpname: str, scan_query: str, max_ter: int, start: in wl = await wordlist(corp, args, max_ter) return [(d['str'], d['freq']) for d in wl][start:][:max_ter] - async def fcs_search(self, corp: AbstractKCorpus, corpname: str, fcs_query: str, max_rec: int, start: int) -> Tuple[FCSSearchResult, str]: + async def fcs_search( + self, + corp: AbstractKCorpus, + fcs_query: str, + max_rec: int, + start: int + ) -> Tuple[FCSSearchResult, str]: """ aux function for federated content search: operation=searchRetrieve """ @@ -209,7 +220,7 @@ async def fcs_search(self, corp: AbstractKCorpus, corpname: str, fcs_query: str, try: with plugins.runtime.AUTH as auth: anon_id = auth.anonymous_user(self.plugin_ctx)['id'] - q = ['q' + rq] + q = ('q' + rq,) # try to locate concordance in cache lock = asyncio.Lock() diff --git a/lib/plugin_types/corparch/corpus.py b/lib/plugin_types/corparch/corpus.py index e2e27d99c9..08cc2b7d41 100644 --- a/lib/plugin_types/corparch/corpus.py +++ b/lib/plugin_types/corparch/corpus.py @@ -197,6 +197,7 @@ class CorpusInfo: """ id: Optional[str] = None + pid: Optional[str] = None # TODO see https://github.com/czcorpus/kontext/issues/6039 name: Optional[str] = None description: Optional[str] = None # filled in during localization _description_cs: Optional[str] = None diff --git a/lib/views/fcs.py b/lib/views/fcs.py index 43529d6633..1e64c68087 100644 --- a/lib/views/fcs.py +++ b/lib/views/fcs.py @@ -17,8 +17,8 @@ from collections import defaultdict from dataclasses import asdict, dataclass, field from typing import Any, Dict, List, Optional, Tuple +import random -import aiofiles import plugins import settings from action.argmapping.conc import QueryFormArgs @@ -78,6 +78,7 @@ async def op_explain(amodel: FCSActionModel, req: KRequest, resp_common: FCSResp lang_code = get_lang_code(a2=cinfo.collator_locale.split('_')[0]) resp['resources'].append( FCSResourceInfo( + pid=corp, # TODO we need something like an ID from Handle.Net or DOI title=corp, description=cinfo.localized_desc('en'), landing_page_uri=cinfo.web, @@ -151,7 +152,6 @@ async def op_search_retrieve(amodel: FCSActionModel, req: KRequest, resp_common: tasks = [ amodel.fcs_search( await amodel.cf.get_corpus(corp), - amodel.args.corpname, query, resp_common.maximumRecords, resp_common.startRecord, @@ -160,9 +160,12 @@ async def op_search_retrieve(amodel: FCSActionModel, req: KRequest, resp_common: ] results: List[List[FCSSearchResult], str] = await asyncio.gather(*tasks) # merging results + merged_rows = [row for result, _ in results for row in result.rows] + if len(merged_rows) > resp_common.maximumRecords: + merged_rows = random.sample(merged_rows, k=resp_common.maximumRecords) merged_results = FCSSearchResult( - rows=[row for result, _ in results for row in result.rows], - size=sum(r.size for r, _ in results), + rows=merged_rows, + size=len(merged_rows), ) cql_query = results[0][1] diff --git a/templates/fcs/v1_complete.html b/templates/fcs/v1_complete.html index 8479b68a69..57c8af7f5f 100644 --- a/templates/fcs/v1_complete.html +++ b/templates/fcs/v1_complete.html @@ -64,7 +64,7 @@ {% for resource in resources %} - + {{ resource.title }} {% if resource.description %} {{ resource.description }} @@ -134,7 +134,8 @@ http://clarin.eu/fcs/resource {{ recordPacking }} - + {{ left|xmle }}{{ word|xmle }} {{ right|xmle }}