Skip to content

Commit dfa1e5a

Browse files
Matus Kasakclaude
andcommitted
Clarin9/Restrict main search page to items only
The main /search page previously returned all DSpace object types (items, collections and communities), matching the backend `default` discovery configuration. In v7 only items were shown there. Add a reusable `forcedDsoTypes` input to the (themed) SearchComponent that forces the given DSpaceObject types onto every search request the component makes, and set it to items only on the main search page. Community and collection results are therefore hidden from /search, while other search pages (MyDSpace, admin, browse, scoped configuration searches) are untouched. Clearing SearchPageComponent.forcedDsoTypes restores the previous behaviour, and the input can be reused to expose this as a facet/config later. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent f78da0e commit dfa1e5a

5 files changed

Lines changed: 27 additions & 1 deletion

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<ds-search [showCsvExport]="true" [trackStatistics]="true"></ds-search>
1+
<ds-search [showCsvExport]="true" [trackStatistics]="true" [forcedDsoTypes]="forcedDsoTypes"></ds-search>

src/app/search-page/search-page.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Component } from '@angular/core';
22

3+
import { DSpaceObjectType } from '../core/shared/dspace-object-type.model';
34
import { SearchConfigurationService } from '../core/shared/search/search-configuration.service';
45
import { SEARCH_CONFIG_SERVICE } from '../my-dspace-page/my-dspace-configuration.service';
56
import { ThemedSearchComponent } from '../shared/search/themed-search.component';
@@ -22,4 +23,6 @@ import { ThemedSearchComponent } from '../shared/search/themed-search.component'
2223
* It renders search results depending on the current search options
2324
*/
2425
export class SearchPageComponent {
26+
/** Restrict the search page to items only (hides community/collection results); empty = all types. */
27+
forcedDsoTypes: DSpaceObjectType[] = [DSpaceObjectType.ITEM];
2528
}

src/app/shared/search/search.component.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import { CommunityDataService } from '../../core/data/community-data.service';
3939
import { RemoteData } from '../../core/data/remote-data';
4040
import { RouteService } from '../../core/services/route.service';
4141
import { DSpaceObject } from '../../core/shared/dspace-object.model';
42+
import { DSpaceObjectType } from '../../core/shared/dspace-object-type.model';
4243
import { Item } from '../../core/shared/item.model';
4344
import { SearchService } from '../../core/shared/search/search.service';
4445
import { SearchConfigurationService } from '../../core/shared/search/search-configuration.service';
@@ -316,6 +317,16 @@ describe('SearchComponent', () => {
316317
expect((comp as any).retrieveSearchResults).toHaveBeenCalledWith(expectedSearchOptions);
317318
}));
318319

320+
it('should force the configured dsoTypes onto the search options when forcedDsoTypes is set', fakeAsync(() => {
321+
const retrieveSpy = spyOn((comp as any), 'retrieveSearchResults').and.callThrough();
322+
comp.forcedDsoTypes = [DSpaceObjectType.ITEM];
323+
fixture.detectChanges();
324+
tick(100);
325+
326+
const usedOptions = retrieveSpy.calls.mostRecent().args[0] as PaginatedSearchOptions;
327+
expect(usedOptions.dsoTypes).toEqual([DSpaceObjectType.ITEM]);
328+
}));
329+
319330
it('should retrieve SearchResults', fakeAsync(() => {
320331
fixture.detectChanges();
321332
tick(100);

src/app/shared/search/search.component.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import { RemoteData } from '../../core/data/remote-data';
4747
import { RouteService } from '../../core/services/route.service';
4848
import { Context } from '../../core/shared/context.model';
4949
import { DSpaceObject } from '../../core/shared/dspace-object.model';
50+
import { DSpaceObjectType } from '../../core/shared/dspace-object-type.model';
5051
import { Item } from '../../core/shared/item.model';
5152
import { getFirstCompletedRemoteData } from '../../core/shared/operators';
5253
import { SearchService } from '../../core/shared/search/search.service';
@@ -242,6 +243,9 @@ export class SearchComponent implements OnDestroy, OnInit {
242243
*/
243244
@Input() renderOnServerSide: boolean;
244245

246+
/** Restrict results to these DSpaceObject types (e.g. items only); empty = all types. */
247+
@Input() forcedDsoTypes: DSpaceObjectType[] = [];
248+
245249
/**
246250
* The current configuration used during the search
247251
*/
@@ -431,6 +435,10 @@ export class SearchComponent implements OnDestroy, OnInit {
431435
if (isEmpty(combinedOptions.scope)) {
432436
combinedOptions.scope = scope;
433437
}
438+
// Force the configured result types (e.g. items only) when no explicit dsoTypes are set.
439+
if (isNotEmpty(this.forcedDsoTypes) && isEmpty(combinedOptions.dsoTypes)) {
440+
combinedOptions.dsoTypes = [...this.forcedDsoTypes];
441+
}
434442
const newSearchOptions = new PaginatedSearchOptions(combinedOptions);
435443
// check if search options are changed
436444
// if so retrieve new related results otherwise skip it

src/app/shared/search/themed-search.component.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77

88
import { Context } from '../../core/shared/context.model';
99
import { DSpaceObject } from '../../core/shared/dspace-object.model';
10+
import { DSpaceObjectType } from '../../core/shared/dspace-object-type.model';
1011
import { ViewMode } from '../../core/shared/view-mode.model';
1112
import { CollectionElementLinkType } from '../object-collection/collection-element-link.type';
1213
import { ListableObject } from '../object-collection/shared/listable-object.model';
@@ -51,6 +52,7 @@ export class ThemedSearchComponent extends ThemedComponent<SearchComponent> {
5152
'query',
5253
'scope',
5354
'hideScopeInUrl',
55+
'forcedDsoTypes',
5456
'resultFound',
5557
'deselectObject',
5658
'selectObject',
@@ -106,6 +108,8 @@ export class ThemedSearchComponent extends ThemedComponent<SearchComponent> {
106108

107109
@Input() hideScopeInUrl: boolean;
108110

111+
@Input() forcedDsoTypes: DSpaceObjectType[];
112+
109113
@Output() resultFound: EventEmitter<SearchObjects<DSpaceObject>> = new EventEmitter();
110114

111115
@Output() deselectObject: EventEmitter<ListableObject> = new EventEmitter();

0 commit comments

Comments
 (0)