Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix search service issues #2844

Merged
merged 5 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<div *ngIf="currentFilters.value.meetingFilter !== 'meetings'" class="filter-section">
<ng-container *ngFor="let filter of currentlyAvailableFilters">
<mat-checkbox *osPerms="getPermissionByFilter(filter)" formControlName="{{ filter }}" class="filter">
<mat-checkbox *ngIf="hasFilterPermission(filter)" formControlName="{{ filter }}" class="filter">
{{ availableFilters[filter] | translate }}
</mat-checkbox>
</ng-container>
Expand All @@ -31,6 +31,12 @@

<mat-dialog-content class="search-results">
<ng-container *ngIf="searching === null">
<div *ngIf="resultCount" class="info result-info">
<span>{{ 'Total results' | translate }}: {{ resultCount }}</span>
<span *ngIf="resultCount !== filteredResultCount">
{{ 'Filtered' | translate }}: {{ filteredResultCount }}
</span>
</div>
<section class="search-results-category alternating-list">
<div *ngFor="let result of filteredResults" class="search-results-entry">
<div class="breadcrumb">
Expand Down Expand Up @@ -60,7 +66,7 @@ <h3 *ngIf="result.title">
</h3>
<div class="info">
<span *ngIf="result.obj?.submitter_ids?.length">
{{ 'Submitter' | translate }}:
{{ 'From' | translate }}:
<os-comma-separated-listing
[list]="getNamesBySubmitters(result.obj.submitter_ids)"
></os-comma-separated-listing>
Expand All @@ -77,10 +83,6 @@ <h3 *ngIf="result.title" [innerHtml]="result.title"></h3>
</div>
</section>
<h3 *ngIf="noResults" class="search-no-results">{{ 'No results found' | translate }}</h3>
<div *ngIf="resultCount" class="info result-info">
<span>{{ 'Total' | translate }}: {{ resultCount }}</span>
<span>{{ 'Filtered' | translate }}: {{ filteredResultCount }}</span>
</div>
</ng-container>
<ng-container *ngIf="searching !== null">
<div class="spinner-container">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,19 @@ export class GlobalSearchComponent implements OnDestroy {
this.updateCurrentlyAvailableFilters();
this.filterChangeSubscription = this.currentFilters.valueChanges
.pipe(startWith(this.currentFilters.value), pairwise())
.subscribe(([last, next]) => {
if (last.meetingFilter !== next.meetingFilter) {
.subscribe(() => {
if (this.searchTerm) {
this.searchChange();
}

this.updateFilteredResults();
});
}

ngOnDestroy(): void {
this.filterChangeSubscription.unsubscribe();
}

public getPermissionByFilter(filter: string): Permission {
if (filter === `topic`) {
return Permission.agendaItemCanSee;
}

return (filter + `.can_see`) as Permission;
public hasFilterPermission(filter: string): boolean {
return !this.activeMeeting.meetingId || this.operator.hasPerms(this.getPermissionByFilter(filter));
}

public async searchChange(): Promise<void> {
Expand All @@ -96,8 +90,13 @@ export class GlobalSearchComponent implements OnDestroy {
this.cd.markForCheck();

try {
const filters =
this.currentFilters.get(`meetingFilter`).getRawValue() === `meetings`
? [`meeting`]
: this.selectedFilters();
const search = await this.globalSearchService.searchChange(
this.searchTerm,
filters,
this.currentlyAvailableFilters,
searchMeeting
);
Expand Down Expand Up @@ -179,6 +178,24 @@ export class GlobalSearchComponent implements OnDestroy {
return resultText;
}

private getPermissionByFilter(filter: string): Permission {
if (filter === `topic`) {
return Permission.agendaItemCanSee;
}

return (filter + `.can_see`) as Permission;
}

private selectedFilters(): string[] {
const filters = [];
for (const filter of this.currentlyAvailableFilters) {
if (this.currentFilters.get(filter) && this.currentFilters.get(filter).getRawValue()) {
filters.push(filter);
}
}
return filters;
}

private updateFilteredResults(): void {
this.filteredResults = [];
let allUnchecked = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,21 @@ export class GlobalSearchService {

public async searchChange(
searchTerm: string,
reqCollections: string[] = [],
collections: string[] = [],
meeting?: Id
): Promise<{ resultList: GlobalSearchEntry[]; models: GlobalSearchResponse }> {
if (!searchTerm) {
return { resultList: [], models: {} };
}

const params: { q: string; m?: string } = { q: searchTerm };
const params: { q: string; c?: string; m?: string } = { q: searchTerm };
if (meeting) {
params.m = meeting.toString();
}
if (reqCollections && reqCollections.length) {
params.c = reqCollections.join(`,`);
}

const rawResults: GlobalSearchResponse = await this.http.get(`/system/search`, null, params);

Expand Down Expand Up @@ -101,6 +105,12 @@ export class GlobalSearchService {
const content = results[fqid].content;
const collection = collectionFromFqid(fqid);
const id = content.sequential_number || idFromFqid(fqid);
let meeting = null;
if (content.meeting_id) {
meeting = results[`meeting/${content.meeting_id}`]?.content;
} else if (content.owner_id && content.owner_id.startsWith(`meeting`)) {
meeting = results[content.owner_id]?.content;
}

return {
title: this.getTitle(collection, content),
Expand All @@ -109,7 +119,7 @@ export class GlobalSearchService {
fqid,
collection,
url: this.getUrl(collection, id, content),
meeting: results[`meeting/${content.meeting_id}`]?.content,
meeting,
committee: results[`committee/${content.committee_id}`]?.content,
score: results[fqid].score || 0
};
Expand Down