Skip to content

Commit f8c6b55

Browse files
committed
DIGG-463: Updating handling of factes that isn't publisher or choice
1 parent 0af486e commit f8c6b55

File tree

6 files changed

+1692
-1596
lines changed

6 files changed

+1692
-1596
lines changed

components/content/Search/SearchFilters/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ export const SearchFilters: React.FC<SearchFilterProps> = ({
292292
aria-selected={selected(key, facetValue)}
293293
>
294294
<button
295-
className={`focus--in group relative flex w-full items-center break-all py-md pl-md pr-[3rem] text-left hover:bg-brown-100 ${
295+
className={`focus--in group relative flex w-full items-center break-words py-md pl-md pr-[3rem] text-left hover:bg-brown-100 ${
296296
selected(key, facetValue) && "font-strong"
297297
}`}
298298
onClick={() => {

types/entrystore-js.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ declare module "@entryscape/entrystore-js" {
1515
all: boolean,
1616
asyncCallType?: any,
1717
): Promise<Entry[]>;
18+
loadOnlyPublicEntries(all: boolean): void;
1819
}
1920

2021
export class SolrQuery {

utilities/entryScape.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ import {
99
getPublisherNames,
1010
getTemplateChoices,
1111
getLocalizedChoiceLabel,
12+
getFacetNames,
1213
} from "@/utilities";
1314
import { Translate } from "next-translate";
1415
import { SearchSortOrder } from "@/providers/SearchProvider";
1516
// @ts-ignore
1617
import { EntryStore, EntryStoreUtil } from "@entryscape/entrystore-js";
1718
// @ts-ignore
1819
import { namespaces } from "@entryscape/rdfjson";
19-
import { publisherCache } from "./publisherCache";
20+
import { publisherCache, entryCache } from "./localCache";
2021
//const tokenize = require('edge-ngrams')()
2122

2223
//#region ES members
@@ -103,8 +104,7 @@ export class EntryScape {
103104
// Initialize the EntryStore instance
104105
this.entryStore = new EntryStore(this.entryscapeUrl);
105106
this.entryStoreUtil = new EntryStoreUtil(this.entryStore);
106-
// this.entryStore.getREST().disableJSONP();
107-
// this.entryStore.getREST().disableCredentials();
107+
this.entryStoreUtil.loadOnlyPublicEntries(true);
108108
}
109109

110110
/**
@@ -140,6 +140,17 @@ export class EntryScape {
140140
);
141141

142142
if (facetSpec) {
143+
if (
144+
facetSpec.dcatType !== "choice" &&
145+
facetSpec.dcatProperty !== "dcterms:publisher"
146+
) {
147+
await getFacetNames(
148+
f.values.map((v) => v.name),
149+
this.entryStoreUtil,
150+
facetSpec,
151+
);
152+
}
153+
143154
facets[f.predicate] = {
144155
title: this.t(f.predicate),
145156
name: f.name,
@@ -174,6 +185,8 @@ export class EntryScape {
174185
} else if (facetSpec?.dcatProperty === "dcterms:publisher") {
175186
// Use cached publisher name without making new requests
176187
displayName = publisherCache.getValue(value.name) || value.name;
188+
} else {
189+
displayName = entryCache.getValue(value.name) || value.name;
177190
}
178191

179192
return {
@@ -461,7 +474,7 @@ export class EntryScape {
461474

462475
// Set query text
463476
if (query) {
464-
esQuery.all(`*${query}*`);
477+
esQuery.all(`${query}`);
465478
}
466479

467480
try {
@@ -478,7 +491,7 @@ export class EntryScape {
478491
?.values?.map((v: any) => v.name);
479492

480493
if (publisherUris) {
481-
await getPublisherNames(publisherUris, es, esu);
494+
await getPublisherNames(publisherUris, esu);
482495
}
483496

484497
// Process children sequentially to maintain order

utilities/entrystoreUtil.ts

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313

1414
import { EntryStore, EntryStoreUtil } from "@entryscape/entrystore-js";
15-
import { publisherCache } from "./publisherCache";
15+
import { entryCache, publisherCache } from "./localCache";
1616

1717
export const getLocalizedMetadataValue = (
1818
metadataGraph: any,
@@ -118,10 +118,62 @@ export const getSimplifiedLocalizedValue = (
118118
return (svValue || enValue || values[0])?.getValue() || "";
119119
};
120120

121+
export const getFacetNames = async (
122+
facetValues: string[],
123+
esu: EntryStoreUtil,
124+
facetSpec: any,
125+
) => {
126+
const cache = entryCache.get();
127+
// Filter out null values and already cached URIs
128+
const uniqueUris = Array.from(new Set(facetValues)).filter(
129+
(uri): uri is string => uri !== null && !cache.has(uri),
130+
);
131+
132+
if (uniqueUris.length === 0) {
133+
return cache;
134+
}
135+
136+
try {
137+
// Load all entries in one batch with a single request
138+
const entries = await esu.loadEntriesByResourceURIs(
139+
uniqueUris,
140+
null,
141+
true,
142+
facetSpec.predicate,
143+
);
144+
145+
// Process all entries at once
146+
entries.forEach(async (entry: any) => {
147+
if (entry) {
148+
const metadata = entry.getMetadata();
149+
const uri = entry.getResourceURI();
150+
const name =
151+
getSimplifiedLocalizedValue(metadata, "dcterms:title") ||
152+
getSimplifiedLocalizedValue(metadata, "foaf:name") ||
153+
undefined;
154+
155+
cache.set(uri, name);
156+
}
157+
});
158+
159+
// Cache any URIs that weren't found
160+
uniqueUris.forEach((uri) => {
161+
if (!cache.has(uri)) {
162+
cache.set(uri, uri);
163+
}
164+
});
165+
166+
return cache;
167+
} catch (error) {
168+
console.error("Error fetching publisher names:", error);
169+
uniqueUris.forEach((uri) => cache.set(uri, uri));
170+
return cache;
171+
}
172+
};
173+
121174
// Helper function to get publisher name from URI
122175
export const getPublisherNames = async (
123176
publisherUris: string[],
124-
es: EntryStore,
125177
esu: EntryStoreUtil,
126178
) => {
127179
const cache = publisherCache.get();

utilities/publisherCache.ts renamed to utilities/localCache.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,33 @@ class PublisherCacheManager {
2727
}
2828

2929
export const publisherCache = PublisherCacheManager.getInstance();
30+
31+
class EntryCacheManager {
32+
private static instance: EntryCacheManager;
33+
private cache: Map<string, any>;
34+
35+
private constructor() {
36+
this.cache = new Map<string, string>();
37+
}
38+
39+
public static getInstance(): EntryCacheManager {
40+
if (!EntryCacheManager.instance) {
41+
EntryCacheManager.instance = new EntryCacheManager();
42+
}
43+
return EntryCacheManager.instance;
44+
}
45+
46+
public get(): Map<string, string> {
47+
return this.cache;
48+
}
49+
50+
public getValue(key: string): string | undefined {
51+
return this.cache.get(key);
52+
}
53+
54+
public set(key: string, value: string): void {
55+
this.cache.set(key, value);
56+
}
57+
}
58+
59+
export const entryCache = EntryCacheManager.getInstance();

0 commit comments

Comments
 (0)