From 753ffc007ea6c36db449dce17cc43e2c13a38f2d Mon Sep 17 00:00:00 2001 From: Irmantas Kaukas Date: Fri, 22 Nov 2024 10:45:45 +0100 Subject: [PATCH] fix: advanced search results for specific project (DEV-4326) --- .../advanced-search-store.service.ts | 10 +++++++++- .../gravsearch-service/gravsearch.service.ts | 13 ++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/libs/vre/advanced-search/src/lib/data-access/advanced-search-store/advanced-search-store.service.ts b/libs/vre/advanced-search/src/lib/data-access/advanced-search-store/advanced-search-store.service.ts index 7c679c3382..06369b1e78 100644 --- a/libs/vre/advanced-search/src/lib/data-access/advanced-search-store/advanced-search-store.service.ts +++ b/libs/vre/advanced-search/src/lib/data-access/advanced-search-store/advanced-search-store.service.ts @@ -657,13 +657,21 @@ export class AdvancedSearchStoreService extends ComponentStore state.ontologies)[0].iri; const selectedResourceClass = this.get(state => state.selectedResourceClass); const propertyFormList = this.get(state => state.propertyFormList); const orderByList = this.get(state => state.propertiesOrderByList); + const resourceClasses = this.get(state => state.resourceClasses).map(resClass => resClass.iri); this._storeSnapshotInLocalStorage(); - return this._gravsearchService.generateGravSearchQuery(selectedResourceClass?.iri, propertyFormList, orderByList); + return this._gravsearchService.generateGravSearchQuery( + ontoIri, + resourceClasses, + selectedResourceClass?.iri, + propertyFormList, + orderByList + ); } onReset() { diff --git a/libs/vre/advanced-search/src/lib/data-access/gravsearch-service/gravsearch.service.ts b/libs/vre/advanced-search/src/lib/data-access/gravsearch-service/gravsearch.service.ts index cfe7adb288..5b63c87bd0 100644 --- a/libs/vre/advanced-search/src/lib/data-access/gravsearch-service/gravsearch.service.ts +++ b/libs/vre/advanced-search/src/lib/data-access/gravsearch-service/gravsearch.service.ts @@ -8,17 +8,23 @@ import { Operators, OrderByItem, PropertyFormItem } from '../advanced-search-sto }) export class GravsearchService { generateGravSearchQuery( + ontoIri: string, + resourceClasses: string[], resourceClassIri: string | undefined, properties: PropertyFormItem[], orderByList: OrderByItem[] ): string { // class restriction for the resource searched for let restrictToResourceClass = ''; + const ontoShortCode = ontoIri.match(/\/([^/]+)\/v2$/)![1]; // if given, create the class restriction for the main resource - if (resourceClassIri !== undefined) { - restrictToResourceClass = `?mainRes a <${resourceClassIri}> .`; - } + restrictToResourceClass = + resourceClassIri !== undefined + ? `?mainRes a <${resourceClassIri}> .` + : resourceClasses + .map(resourceClass => `{ ?mainRes a ${ontoShortCode}:${resourceClass.split('#').pop()} . }`) + .join(' UNION '); const propertyStrings: GravsearchPropertyString[] = properties.map((prop, index) => this._propertyStringHelper(prop, index) @@ -48,6 +54,7 @@ export class GravsearchService { const gravSearch = 'PREFIX knora-api: \n' + + `PREFIX ${ontoShortCode}: <${ontoIri}#>\n` + 'CONSTRUCT {\n' + '?mainRes knora-api:isMainResource true .\n' + `${propertyStrings.map(prop => prop.constructString).join('\n')}\n` +