Skip to content

Commit

Permalink
fix: fix gravsearch results infinite loading (#480)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpro7 committed Jan 6, 2023
1 parent 19fb856 commit 68aa686
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
1 change: 0 additions & 1 deletion src/api/v2/search/search-endpoint-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ export class SearchEndpointV2 extends Endpoint {
*/
doExtendedSearch(gravsearchQuery: string): Observable<ReadResourceSequence | ApiResponseError> {
// TODO: Do not hard-code the URL and http call params, generate this from Knora

// TODO: check if content-type have to be set to text/plain

return this.httpPost("/searchextended", gravsearchQuery, "sparql").pipe(
Expand Down
41 changes: 25 additions & 16 deletions src/models/v2/resources/ResourcesConversionUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,40 @@ import { ResourceClassAndPropertyDefinitions } from "../../../cache/ontology-cac
export namespace ResourcesConversionUtil {

/**
* Given a JSON-LD representing zero, one more resources, converts it to an array of ReadResource.
* Given a JSON-LD representing zero, one or more resources, converts it to an array of ReadResource.
*
* JSON-LD is expected to have expanded prefixes (processed by jsonld processor).
*
* @param resourcesJsonld a JSON-LD object with expanded prefixes representing zero, one or more resources.
* @param resourcesJsonld a JSON-LD object with expanded prefixes representing zero, one or more resources.
* @param ontologyCache instance of OntologyCache to be used.
* @param listNodeCache instance of ListNodeCache to be used.
* @param jsonConvert instance of JsonConvert to be used.
*/
export const createReadResourceSequence = (resourcesJsonld: object, ontologyCache: OntologyCache, listNodeCache: ListNodeV2Cache, jsonConvert: JsonConvert): Observable<ReadResourceSequence> => {

if (resourcesJsonld.hasOwnProperty("@graph")) {
// sequence of resources
return forkJoin((resourcesJsonld as { [index: string]: object[] })["@graph"]
.map((res: { [index: string]: object[] | string }) => createReadResource(res, ontologyCache, listNodeCache, jsonConvert))).pipe(
map((resources: ReadResource[]) => {
// check for mayHaveMoreResults
if (resourcesJsonld.hasOwnProperty(Constants.MayHaveMoreResults)) {
// presence of knora-api:mayHaveMoreResults implicitly means true
return new ReadResourceSequence(resources, true);
} else {
return new ReadResourceSequence(resources);
}
})
);
let graphLength: number = (resourcesJsonld as { [index: string]: object[] })["@graph"].length

if (graphLength > 0) {
// sequence of resources
return forkJoin((resourcesJsonld as { [index: string]: object[] })["@graph"]
.map((res: { [index: string]: object[] | string }) => createReadResource(res, ontologyCache, listNodeCache, jsonConvert))).pipe(
map((resources: ReadResource[]) => {
// check for mayHaveMoreResults
if (resourcesJsonld.hasOwnProperty(Constants.MayHaveMoreResults)) {
// presence of knora-api:mayHaveMoreResults implicitly means true
return new ReadResourceSequence(resources, true);
} else {
return new ReadResourceSequence(resources);
}
})
);
} else {
if (resourcesJsonld.hasOwnProperty(Constants.MayHaveMoreResults)) {
return of(new ReadResourceSequence([], true));
} else {
return of(new ReadResourceSequence([]));
}
}
} else {
// one or no resource
if (Object.keys(resourcesJsonld).length === 0) {
Expand Down
4 changes: 1 addition & 3 deletions src/models/v2/resources/read/read-resource-sequence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,5 @@ export class ReadResourceSequence {
* @param resources sequence of resources.
* @param mayHaveMoreResults flag whether there are more results to be fetched, i.e. for search results.
*/
constructor(readonly resources: ReadResource[], readonly mayHaveMoreResults = false) {
}

constructor(readonly resources: ReadResource[], readonly mayHaveMoreResults = false) { }
}

0 comments on commit 68aa686

Please sign in to comment.