Skip to content

Commit

Permalink
Merge pull request #6325 from mzimandl/fullsearch
Browse files Browse the repository at this point in the history
corpus search + clean history results on changing to extended search
  • Loading branch information
tomachalek authored Oct 15, 2024
2 parents b68c02c + 951a0ac commit 84019e9
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 54 deletions.
1 change: 1 addition & 0 deletions lib/action/argmapping/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class FullSearchArgs:
structure_name: str
structattr_name: str
structattr_value: str
corpus: str
subcorpus: str
wl_pat: str
wl_attr: str
Expand Down
74 changes: 36 additions & 38 deletions lib/plugins/ucnk_query_history/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,8 @@ async def delete_old_records(self):
def _generate_query_string(
q_supertype: str,
user_id: int,
corpname: str,
archived_only: bool,
full_search_args: Optional[FullSearchArgs]
full_search_args: FullSearchArgs
) -> str:
parts = [f'+user_id:{user_id}']
if archived_only:
Expand All @@ -155,40 +154,39 @@ def _generate_query_string(
if q_supertype:
parts.append(make_bleve_field('query_supertype', q_supertype))

if corpname:
parts.append(make_bleve_field('corpora', corpname))

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

if full_search_args.any_property_value:
parts.append(make_bleve_field('_all', full_search_args.any_property_value))

else:
if q_supertype in ('conc', 'pquery'):
if full_search_args.posattr_name:
parts.append(make_bleve_field('pos_attr_names', full_search_args.posattr_name))
if full_search_args.posattr_value:
parts.append(make_bleve_field('pos_attr_values', full_search_args.posattr_value))
if full_search_args.structattr_name:
parts.append(make_bleve_field('struct_attr_names', full_search_args.structattr_name))
if full_search_args.structattr_value:
parts.append(make_bleve_field('struct_attr_values', full_search_args.structattr_value))

elif q_supertype == 'wlist':
if full_search_args.wl_pat:
parts.append(make_bleve_field('raw_query', full_search_args.wl_pat))
if full_search_args.wl_attr:
parts.append(make_bleve_field('pos_attr_names', full_search_args.wl_attr))
if full_search_args.wl_pfilter:
parts.append(make_bleve_field('pfilter_words', full_search_args.wl_pfilter))
if full_search_args.wl_nfilter:
parts.append(make_bleve_field('nfilter_words', full_search_args.wl_nfilter))

elif q_supertype == 'kwords':
if full_search_args.wl_attr:
parts.append(make_bleve_field('pos_attr_names', full_search_args.posattr_name))
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))

if full_search_args.any_property_value:
parts.append(make_bleve_field('_all', full_search_args.any_property_value))

else:
if q_supertype in ('conc', 'pquery'):
if full_search_args.posattr_name:
parts.append(make_bleve_field('pos_attr_names', full_search_args.posattr_name))
if full_search_args.posattr_value:
parts.append(make_bleve_field('pos_attr_values', full_search_args.posattr_value))
if full_search_args.structattr_name:
parts.append(make_bleve_field('struct_attr_names', full_search_args.structattr_name))
if full_search_args.structattr_value:
parts.append(make_bleve_field('struct_attr_values', full_search_args.structattr_value))

elif q_supertype == 'wlist':
if full_search_args.wl_pat:
parts.append(make_bleve_field('raw_query', full_search_args.wl_pat))
if full_search_args.wl_attr:
parts.append(make_bleve_field('pos_attr_names', full_search_args.wl_attr))
if full_search_args.wl_pfilter:
parts.append(make_bleve_field('pfilter_words', full_search_args.wl_pfilter))
if full_search_args.wl_nfilter:
parts.append(make_bleve_field('nfilter_words', full_search_args.wl_nfilter))

elif q_supertype == 'kwords':
if full_search_args.wl_attr:
parts.append(make_bleve_field('pos_attr_names', full_search_args.posattr_name))

return ' '.join(parts)

Expand All @@ -200,8 +198,8 @@ 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, corpname, archived_only, full_search_args),
'order': '-created' if full_search_args is None else '-_score,-created',
'q': self._generate_query_string(q_supertype, user_id, archived_only, full_search_args),
'order': '-_score,-created',
'limit': limit,
'fields': 'query_supertype,name',
}
Expand Down
4 changes: 3 additions & 1 deletion lib/views/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,15 @@ async def ajax_query_history(amodel: UserActionModel, req: KRequest, resp: KResp
corpname = req.args.get('corpname', None)
archived_only = bool(int(req.args.get('archived_only', '0')))

extended_search = bool(int(req.args.get('extended_search', '0')))
full_search_args = FullSearchArgs(
req.args.get('fsAnyPropertyValue', None),
req.args.get('fsPosattrName', None),
req.args.get('fsPosattrValue', None),
req.args.get('fsStructureName', None),
req.args.get('fsStructattrName', None),
req.args.get('fsStructattrValue', None),
req.args.get('fsCorpus', None),
req.args.get('fsSubcorpus', None),
req.args.get('fsWlpat', None),
req.args.get('fsWattr', None),
Expand All @@ -237,7 +239,7 @@ async def ajax_query_history(amodel: UserActionModel, req: KRequest, resp: KResp
rows = await _load_query_history(
amodel=amodel, q_supertype=query_supertype, corpname=corpname, from_date=None,
user_id=req.session_get('user', 'id'), to_date=None, archived_only=archived_only, offset=offset,
limit=limit, full_search_args=None if full_search_args.empty() else full_search_args)
limit=limit, full_search_args=full_search_args if extended_search else None)
return dict(
data=rows,
from_date=None,
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 @@ -139,6 +139,7 @@ export interface GetHistoryArgs {
query_supertype:Kontext.QuerySupertype;
corpname:string;
archived_only:boolean;
extended_search:boolean;
fsPosattrName?:string;
fsPosattrValue?:string;
fsStructureName?:string;
Expand Down Expand Up @@ -172,6 +173,7 @@ export interface WidgetProps {
}

export interface SearchHistoryModelState {
searched:boolean;
corpname:string;
data:Array<QueryHistoryItem>;
itemsToolbars:Array<[boolean, boolean]>;
Expand Down
33 changes: 21 additions & 12 deletions public/files/js/models/searchHistory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export class SearchHistoryModel extends StatefulModel<SearchHistoryModelState> {
super(
dispatcher,
{
searched: false,
corpname: pageModel.getCorpusIdent().id,
data: [],
itemsToolbars: [],
Expand Down Expand Up @@ -113,10 +114,10 @@ export class SearchHistoryModel extends StatefulModel<SearchHistoryModelState> {
Actions.HistorySetCurrentCorpusOnly,
action => {
this.changeState(state => {
state.isBusy = !this.isAdvancedSearch();
state.isBusy = !this.isExtendedSearch();
state.currentCorpusOnly = action.payload.value;
});
if (!this.isAdvancedSearch()) {
if (!this.isExtendedSearch()) {
this.performLoadAction();
}
}
Expand All @@ -126,10 +127,10 @@ export class SearchHistoryModel extends StatefulModel<SearchHistoryModelState> {
Actions.HistorySetArchivedOnly,
action => {
this.changeState(state => {
state.isBusy = !this.isAdvancedSearch();
state.isBusy = !this.isExtendedSearch();
state.archivedOnly = action.payload.value;
});
if (!this.isAdvancedSearch()) {
if (!this.isExtendedSearch()) {
this.performLoadAction();
}
}
Expand All @@ -139,10 +140,10 @@ export class SearchHistoryModel extends StatefulModel<SearchHistoryModelState> {
Actions.HistorySetQuerySupertype,
action => {
this.changeState(state => {
state.isBusy = !this.isAdvancedSearch();
state.isBusy = !this.isExtendedSearch();
state.querySupertype = action.payload.value;
});
if (!this.isAdvancedSearch()) {
if (!this.isExtendedSearch()) {
this.performLoadAction();
}
}
Expand Down Expand Up @@ -292,9 +293,15 @@ export class SearchHistoryModel extends StatefulModel<SearchHistoryModelState> {
action => {
this.changeState(
state => {
state.searched = false;
state.searchFormView = action.payload.value;
state.data = [];
state.isBusy = action.payload.value === 'quick';
}
)
);
if (action.payload.value === 'quick') {
this.performLoadAction();
}
}
);

Expand Down Expand Up @@ -474,12 +481,14 @@ export class SearchHistoryModel extends StatefulModel<SearchHistoryModelState> {
this.loadData(widgetMode).subscribe({
next: () => {
this.changeState(state => {
state.isBusy = false
state.isBusy = false;
state.searched = true;
});
},
error: (err) => {
this.changeState(state => {
state.isBusy = false
state.isBusy = false;
state.searched = true;
});
this.pageModel.showMessage('error', err);
},
Expand All @@ -495,9 +504,9 @@ export class SearchHistoryModel extends StatefulModel<SearchHistoryModelState> {
corpname: !widgetMode && this.state.currentCorpusOnly ?
this.pageModel.getCorpusIdent().id : undefined,
archived_only: !widgetMode && this.state.archivedOnly,
extended_search: !widgetMode && this.isExtendedSearch(),
};
if (!widgetMode && this.isAdvancedSearch()) {

if (!widgetMode && this.isExtendedSearch()) {
switch (this.state.querySupertype) {
case 'conc':
case 'pquery':
Expand Down Expand Up @@ -655,7 +664,7 @@ export class SearchHistoryModel extends StatefulModel<SearchHistoryModelState> {
);
}

private isAdvancedSearch():boolean {
private isExtendedSearch():boolean {
return this.state.searchFormView === 'extended';
}
}
13 changes: 10 additions & 3 deletions public/files/js/views/searchHistory/full/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ export function init(
dataLength:number;
hasMoreItems:boolean;
modelIsBusy:boolean;
searched:boolean;

}> = (props) => {
if (props.dataLength > 0) {
Expand All @@ -677,7 +678,11 @@ export function init(
}

} else {
return <NoDataBlock />;
if (props.searched) {
return <NoDataBlock />;
} else {
return null;
}
}
};

Expand All @@ -689,6 +694,7 @@ export function init(
modelIsBusy:boolean;
itemsToolbars:Array<[boolean, boolean]>;
data:Array<QueryHistoryItem>;
searched:boolean;

}> = (props) => {
return (
Expand All @@ -709,7 +715,7 @@ export function init(
)}
</ul>
<DataTableFooter dataLength={props.data.length} modelIsBusy={props.modelIsBusy}
hasMoreItems={props.hasMoreItems} />
hasMoreItems={props.hasMoreItems} searched={props.searched} />
</div>
);
};
Expand All @@ -731,7 +737,8 @@ export function init(
<DataTable data={props.data} offset={props.offset}
modelIsBusy={props.isBusy}
hasMoreItems={props.hasMoreItems}
itemsToolbars={props.itemsToolbars} />
itemsToolbars={props.itemsToolbars}
searched={props.searched} />
}
</S.RecentQueriesPageList>
);
Expand Down

0 comments on commit 84019e9

Please sign in to comment.