Skip to content

Commit

Permalink
Merge pull request #6326 from tomachalek/qhist_updates3
Browse files Browse the repository at this point in the history
Qhist updates3
  • Loading branch information
tomachalek authored Oct 16, 2024
2 parents 84019e9 + ba8e876 commit df04c04
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 51 deletions.
34 changes: 11 additions & 23 deletions lib/plugins/ucnk_query_history/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ async def make_transient(self, plugin_ctx, user_id, query_id, created, name) ->
done = await super().make_transient(plugin_ctx, user_id, query_id, created, name)
await self._update_indexed_name(plugin_ctx, query_id, user_id, created)
return done

async def delete(self, plugin_ctx, user_id, query_id, created):
done = await super().delete(plugin_ctx, user_id, query_id, created)
await self._delete_indexed_item(plugin_ctx, query_id, user_id, created)
Expand Down Expand Up @@ -143,11 +143,10 @@ async def delete_old_records(self):
@staticmethod
def _generate_query_string(
q_supertype: str,
user_id: int,
archived_only: bool,
full_search_args: FullSearchArgs
) -> str:
parts = [f'+user_id:{user_id}']
parts = []
if archived_only:
parts.append('+name:/.*/')

Expand All @@ -156,7 +155,7 @@ def _generate_query_string(

if full_search_args.corpus:
parts.append(make_bleve_field('corpora', full_search_args.corpus))

if full_search_args.subcorpus:
parts.append(make_bleve_field('subcorpus', full_search_args.subcorpus))

Expand Down Expand Up @@ -198,14 +197,14 @@ async def get_user_queries(
return await super().get_user_queries(plugin_ctx, user_id, corpus_factory, from_date, to_date, q_supertype, corpname, archived_only, offset, limit, full_search_args)

params = {
'q': self._generate_query_string(q_supertype, user_id, archived_only, full_search_args),
'q': self._generate_query_string(q_supertype, archived_only, full_search_args),
'order': '-_score,-created',
'limit': limit,
'fields': 'query_supertype,name',
}

url_query = urlencode(list(params.items()))
url = urljoin(self._fulltext_service_url, f'/indexer/search?{url_query}')
url = urljoin(self._fulltext_service_url, f'/user-query-history/{user_id}?{url_query}')
async with plugin_ctx.request.ctx.http_client.get(url) as resp:
index_data = await resp.json()

Expand All @@ -218,36 +217,25 @@ async def get_user_queries(
'q_supertype': hit['fields']['query_supertype'],
'name': hit['fields']['name'],
})

full_data = await self._process_rows(plugin_ctx, corpus_factory, rows)
for i, item in enumerate(full_data):
item['idx'] = i
return full_data

async def _update_indexed_name(self, plugin_ctx, query_id, user_id, created, new_name = ""):
params = {
'queryId': query_id,
'userId': user_id,
'created': created,
'name': new_name,
}

url_query = urlencode(list(params.items()))
url = urljoin(self._fulltext_service_url, f'/indexer/update?{url_query}')
async with plugin_ctx.request.ctx.http_client.get(url) as resp:
url = urljoin(self._fulltext_service_url, f'/user-query-history/{user_id}/{query_id}/{created}?{url_query}')
async with plugin_ctx.request.ctx.http_client.post(url) as resp:
if not resp.ok:
data = await resp.json()
raise Exception(f'Failed to update query in index: {data}')

async def _delete_indexed_item(self, plugin_ctx, query_id, user_id, created):
params = {
'queryId': query_id,
'userId': user_id,
'created': created,
}

url_query = urlencode(list(params.items()))
url = urljoin(self._fulltext_service_url, f'/indexer/delete?{url_query}')
async def _delete_indexed_item(self, plugin_ctx, query_id, user_id, created):
url = urljoin(self._fulltext_service_url, f'/user-query-history/{user_id}/{query_id}/{created}')
async with plugin_ctx.request.ctx.http_client.get(url) as resp:
if not resp.ok:
data = await resp.json()
Expand Down
6 changes: 6 additions & 0 deletions public/files/js/models/searchHistory/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ export class Actions {
name: 'QUERY_HISTORY_SET_ARCHIVED_ONLY'
};

static HistorySetArchivedAs:Action<{
value:string;
}> = {
name: 'QUERY_HISTORY_SET_ARCHIVED_AS'
};

static HistorySetEditedItem:Action<{
itemIdx:number;
}> = {
Expand Down
2 changes: 2 additions & 0 deletions public/files/js/models/searchHistory/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export interface GetHistoryArgs {
fsStructattrValue?:string;
fsCorpus?:string;
fsSubcorpus?:string;
fsArchivedAs?:string;
fsWlpat?:string;
fsWlattr?:string;
fsWlPfilter?:string;
Expand Down Expand Up @@ -197,6 +198,7 @@ export interface SearchHistoryModelState {
fsAnyPropertyValue:string;
fsCorpus:string;
fsSubcorpus:string;
fsArchAs:string;
fsWlAttr:string;
fsWlPat:string;
fsWlPFilter:string;
Expand Down
17 changes: 17 additions & 0 deletions public/files/js/models/searchHistory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export class SearchHistoryModel extends StatefulModel<SearchHistoryModelState> {
fsQueryCQLProps: true,
fsCorpus: pageModel.getCorpusIdent().id,
fsSubcorpus: '',
fsArchAs: '',
fsWlAttr: '',
fsWlPat: '',
fsWlNFilter: '',
Expand Down Expand Up @@ -136,6 +137,15 @@ export class SearchHistoryModel extends StatefulModel<SearchHistoryModelState> {
}
);

this.addActionHandler(
Actions.HistorySetArchivedAs,
action => {
this.changeState(state => {
state.fsArchAs = action.payload.value
});
}
);

this.addActionHandler(
Actions.HistorySetQuerySupertype,
action => {
Expand Down Expand Up @@ -518,17 +528,20 @@ export class SearchHistoryModel extends StatefulModel<SearchHistoryModelState> {
args.fsStructureName = this.state.fsStructureName;
args.fsCorpus = this.state.fsCorpus;
args.fsSubcorpus = this.state.fsSubcorpus;
args.fsArchivedAs = this.state.fsArchAs;

} else {
args.fsCorpus = this.state.fsCorpus;
args.fsSubcorpus = this.state.fsSubcorpus;
args.fsArchivedAs = this.state.fsArchAs;
args.fsAnyPropertyValue = this.state.fsAnyPropertyValue;
}
break;
case 'wlist':
if (this.state.fsQueryCQLProps) {
args.fsCorpus = this.state.fsCorpus;
args.fsSubcorpus = this.state.fsSubcorpus;
args.fsArchivedAs = this.state.fsArchAs;
args.fsWlpat = this.state.fsWlPat;
args.fsWlattr = this.state.fsWlAttr;
args.fsWlPfilter = this.state.fsWlPFilter;
Expand All @@ -537,24 +550,28 @@ export class SearchHistoryModel extends StatefulModel<SearchHistoryModelState> {
} else {
args.fsCorpus = this.state.fsCorpus;
args.fsSubcorpus = this.state.fsSubcorpus;
args.fsArchivedAs = this.state.fsArchAs;
args.fsAnyPropertyValue = this.state.fsAnyPropertyValue;
}
break;
case 'kwords':
if (this.state.fsQueryCQLProps) {
args.fsSubcorpus = this.state.fsSubcorpus;
args.fsSubcorpus = this.state.fsSubcorpus;
args.fsArchivedAs = this.state.fsArchAs;
args.fsPosattrName = this.state.fsPosattrName;

} else {
args.fsCorpus = this.state.fsCorpus;
args.fsSubcorpus = this.state.fsSubcorpus;
args.fsArchivedAs = this.state.fsArchAs;
args.fsAnyPropertyValue = this.state.fsAnyPropertyValue;
}
break;
default:
args.fsCorpus = this.state.fsCorpus;
args.fsSubcorpus = this.state.fsSubcorpus;
args.fsArchivedAs = this.state.fsArchAs;
args.fsAnyPropertyValue = this.state.fsAnyPropertyValue;
break;
}
Expand Down
1 change: 1 addition & 0 deletions public/files/js/translations/messages.cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@
"qhistory__used_pfilter": "Slova pozitivního filtru",
"qhistory__used_nfilter": "Slova negativního filtru",
"qhistory__any_search_note": "Pro podrobnější výběr parametrů zvolte ve filtru konkrétní typ dotazu.",
"qhistory__archived_as_label": "Archivováno jako",
"concview__invalid_page_num_err": "Neplatné číslo stránky",
"concview__click_for_details": "Klikněte pro zobrazení detailů",
"concview__sort_jump_to": "Přejít na",
Expand Down
1 change: 1 addition & 0 deletions public/files/js/translations/messages.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@
"qhistory__used_pfilter": "Positive filter words",
"qhistory__used_nfilter": "Negative filter words",
"qhistory__any_search_note": "For a more detailed selection of parameters, select a specific query type in the filter.",
"qhistory__archived_as_label": "Archived as",
"concview__invalid_page_num_err": "Invalid page number",
"concview__click_for_details": "Click to see details",
"concview__sort_jump_to": "Jump to",
Expand Down
1 change: 1 addition & 0 deletions public/files/js/translations/messages.sl.json
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@
"qhistory__remove_from_list": "Odstrani s seznama",
"qhistory__item_removed": "Odstranjeno s seznama",
"qhistory__blank_query": "prazno",
"qhistory__archived_as_label": "Archived as UNTRANSLATED",
"concview__ipm_rel_to_the_whole_corp": "se nanaša na celoten korpus",
"concview__click_to_play_audio": "Kliknite za predvajanje zvočnega posnetka",
"concview__detail_default_mode_menu": "Privzeti prikaz",
Expand Down
1 change: 1 addition & 0 deletions public/files/js/translations/messages.szl.json
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@
"qhistory__used_pfilter": "Positive filter words UNTRANSLATED",
"qhistory__used_nfilter": "Negative filter words UNTRANSLATED",
"qhistory__any_search_note": "For a more detailed selection of parameters, select a specific query type in the filter. UNTRANSLATED",
"qhistory__archived_as_label": "Archived as UNTRANSLATED",
"concview__invalid_page_num_err": "Niynŏleżyn numer strōny",
"concview__click_for_details": "Kliknij, żeby ôbejzdrzeć szczegōły",
"concview__sort_jump_to": "Skocz do",
Expand Down
24 changes: 8 additions & 16 deletions public/files/js/views/searchHistory/full/fulltextForms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -285,19 +285,17 @@ export function init(
}> = (props) => {

return <>
<UsedCorpus value={props.fsCorpus} />
<UsedSubcorpus value={props.fsSubcorpus} />
<QueryCQLProps isAdvancedQuery={props.fsQueryCQLProps} />
{props.fsQueryCQLProps ?
<>
<UsedCorpus value={props.fsCorpus} />
<UsedSubcorpus value={props.fsSubcorpus} />
<UsedPosattrs attr={props.fsPosattrName} value={props.fsPosattrValue} />
<UsedStructattrs attr={props.fsStructattrName} value={props.fsStructattrValue} />
<UsedStructures attr={props.fsStructureName} />
<div />
</> :
<>
<UsedCorpus value={props.fsCorpus} />
<UsedSubcorpus value={props.fsSubcorpus} />
<AnyPropertyValue value={props.fsAnyPropertyValue} />
</>
}
Expand All @@ -319,18 +317,16 @@ export function init(
}> = (props) => {

return <>
<UsedCorpus value={props.fsCorpus} />
<UsedSubcorpus value={props.fsSubcorpus} />
<QueryCQLProps isAdvancedQuery={props.fsQueryCQLProps} />
{props.fsQueryCQLProps ?
<>
<UsedCorpus value={props.fsCorpus} />
<UsedSubcorpus value={props.fsSubcorpus} />
<UsedPosattrs attr={props.fsPosattrName} value={props.fsPosattrValue} />
<UsedStructures attr={props.fsStructureName} />
<UsedStructattrs attr={props.fsStructattrName} value={props.fsStructattrValue} />
</> :
<>
<UsedCorpus value={props.fsCorpus} />
<UsedSubcorpus value={props.fsSubcorpus} />
<AnyPropertyValue value={props.fsAnyPropertyValue} />
</>
}
Expand Down Expand Up @@ -387,11 +383,11 @@ export function init(
};

return <>
<UsedCorpus value={props.fsCorpus} />
<UsedSubcorpus value={props.fsSubcorpus} />
<QueryCQLProps isAdvancedQuery={props.fsQueryCQLProps} />
{props.fsQueryCQLProps ?
<>
<UsedCorpus value={props.fsCorpus} />
<UsedSubcorpus value={props.fsSubcorpus} />
<label>{he.translate('qhistory__used_wlattr')}</label>
<input type="text" value={props.wlattr} onChange={handleWlattrChange} />
<label>{he.translate('qhistory__used_wlpat')}</label>
Expand All @@ -402,8 +398,6 @@ export function init(
<input type="text" value={props.nfilter} onChange={handleNFilterChange} />
</> :
<>
<UsedCorpus value={props.fsCorpus} />
<UsedSubcorpus value={props.fsSubcorpus} />
<AnyPropertyValue value={props.fsAnyPropertyValue} />
</>
}
Expand All @@ -430,20 +424,18 @@ export function init(
};

return <>
<UsedCorpus value={props.fsCorpus} />
<UsedSubcorpus value={props.fsSubcorpus} />
<QueryCQLProps isAdvancedQuery={props.fsQueryCQLProps} />
{props.fsQueryCQLProps ?
<>
<UsedCorpus value={props.fsCorpus} />
<UsedSubcorpus value={props.fsSubcorpus} />
<div className="prop-query">
<label>{he.translate('qhistory__used_posattrs_label')}</label>
{'\u00a0'}
<input type="text" value={props.fsPosattrName} onChange={handleAttrChange} />
</div>
</> :
<>
<UsedCorpus value={props.fsCorpus} />
<UsedSubcorpus value={props.fsSubcorpus} />
<AnyPropertyValue value={props.fsAnyPropertyValue} />
</>
}
Expand Down
4 changes: 2 additions & 2 deletions public/files/js/views/searchHistory/full/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export function init(
{he.translate('qhistory__filter_legend')}
</legend>
<div className="grid-inputs">
<srchFields.BasicFields corpusSel={true} />
<srchFields.BasicFields corpusSel={true} archivedAsEnable={false} />
</div>
</fieldset>
</S.FilterForm>
Expand All @@ -124,7 +124,7 @@ export function init(
{he.translate('qhistory__search_legend')}
</legend>
<div className="grid-inputs">
<srchFields.BasicFields corpusSel={false} />
<srchFields.BasicFields corpusSel={false} archivedAsEnable={true} />
<srchFields.ExtendedFields />
</div>
{!props.querySupertype ?
Expand Down
Loading

0 comments on commit df04c04

Please sign in to comment.