Skip to content
Closed
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
2 changes: 1 addition & 1 deletion src/app/search-page/search-page.component.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<ds-search [showCsvExport]="true" [trackStatistics]="true"></ds-search>
<ds-search [showCsvExport]="true" [trackStatistics]="true" [forcedDsoTypes]="forcedDsoTypes"></ds-search>
3 changes: 3 additions & 0 deletions src/app/search-page/search-page.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component } from '@angular/core';

import { DSpaceObjectType } from '../core/shared/dspace-object-type.model';
import { SearchConfigurationService } from '../core/shared/search/search-configuration.service';
import { SEARCH_CONFIG_SERVICE } from '../my-dspace-page/my-dspace-configuration.service';
import { ThemedSearchComponent } from '../shared/search/themed-search.component';
Expand All @@ -22,4 +23,6 @@ import { ThemedSearchComponent } from '../shared/search/themed-search.component'
* It renders search results depending on the current search options
*/
export class SearchPageComponent {
/** Restrict the search page to items only (hides community/collection results); empty = all types. */
forcedDsoTypes: DSpaceObjectType[] = [DSpaceObjectType.ITEM];
}
11 changes: 11 additions & 0 deletions src/app/shared/search/search.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { CommunityDataService } from '../../core/data/community-data.service';
import { RemoteData } from '../../core/data/remote-data';
import { RouteService } from '../../core/services/route.service';
import { DSpaceObject } from '../../core/shared/dspace-object.model';
import { DSpaceObjectType } from '../../core/shared/dspace-object-type.model';
import { Item } from '../../core/shared/item.model';
import { SearchService } from '../../core/shared/search/search.service';
import { SearchConfigurationService } from '../../core/shared/search/search-configuration.service';
Expand Down Expand Up @@ -316,6 +317,16 @@ describe('SearchComponent', () => {
expect((comp as any).retrieveSearchResults).toHaveBeenCalledWith(expectedSearchOptions);
}));

it('should force the configured dsoTypes onto the search options when forcedDsoTypes is set', fakeAsync(() => {
const retrieveSpy = spyOn((comp as any), 'retrieveSearchResults').and.callThrough();
comp.forcedDsoTypes = [DSpaceObjectType.ITEM];
fixture.detectChanges();
tick(100);

const usedOptions = retrieveSpy.calls.mostRecent().args[0] as PaginatedSearchOptions;
expect(usedOptions.dsoTypes).toEqual([DSpaceObjectType.ITEM]);
}));
Comment thread
Kasinhou marked this conversation as resolved.

it('should retrieve SearchResults', fakeAsync(() => {
fixture.detectChanges();
tick(100);
Expand Down
8 changes: 8 additions & 0 deletions src/app/shared/search/search.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import { RemoteData } from '../../core/data/remote-data';
import { RouteService } from '../../core/services/route.service';
import { Context } from '../../core/shared/context.model';
import { DSpaceObject } from '../../core/shared/dspace-object.model';
import { DSpaceObjectType } from '../../core/shared/dspace-object-type.model';
import { Item } from '../../core/shared/item.model';
import { getFirstCompletedRemoteData } from '../../core/shared/operators';
import { SearchService } from '../../core/shared/search/search.service';
Expand Down Expand Up @@ -242,6 +243,9 @@ export class SearchComponent implements OnDestroy, OnInit {
*/
@Input() renderOnServerSide: boolean;

/** Restrict results to these DSpaceObject types (e.g. items only); empty = all types. */
@Input() forcedDsoTypes: DSpaceObjectType[] = [];

/**
* The current configuration used during the search
*/
Expand Down Expand Up @@ -431,6 +435,10 @@ export class SearchComponent implements OnDestroy, OnInit {
if (isEmpty(combinedOptions.scope)) {
combinedOptions.scope = scope;
}
// Force the configured result types (e.g. items only) when no explicit dsoTypes are set.
if (isNotEmpty(this.forcedDsoTypes) && isEmpty(combinedOptions.dsoTypes)) {
combinedOptions.dsoTypes = [...this.forcedDsoTypes];
}
const newSearchOptions = new PaginatedSearchOptions(combinedOptions);
// check if search options are changed
// if so retrieve new related results otherwise skip it
Expand Down
4 changes: 4 additions & 0 deletions src/app/shared/search/themed-search.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {

import { Context } from '../../core/shared/context.model';
import { DSpaceObject } from '../../core/shared/dspace-object.model';
import { DSpaceObjectType } from '../../core/shared/dspace-object-type.model';
import { ViewMode } from '../../core/shared/view-mode.model';
import { CollectionElementLinkType } from '../object-collection/collection-element-link.type';
import { ListableObject } from '../object-collection/shared/listable-object.model';
Expand Down Expand Up @@ -51,6 +52,7 @@ export class ThemedSearchComponent extends ThemedComponent<SearchComponent> {
'query',
'scope',
'hideScopeInUrl',
'forcedDsoTypes',
'resultFound',
'deselectObject',
'selectObject',
Expand Down Expand Up @@ -106,6 +108,8 @@ export class ThemedSearchComponent extends ThemedComponent<SearchComponent> {

@Input() hideScopeInUrl: boolean;

@Input() forcedDsoTypes: DSpaceObjectType[];

@Output() resultFound: EventEmitter<SearchObjects<DSpaceObject>> = new EventEmitter();

@Output() deselectObject: EventEmitter<ListableObject> = new EventEmitter();
Expand Down
Loading