Skip to content

Commit f7e0ff1

Browse files
committed
Fix search order accuracy
1 parent 7a61d20 commit f7e0ff1

File tree

5 files changed

+39
-7
lines changed

5 files changed

+39
-7
lines changed

src/components/result/OrcidDisplay.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useEffect, useMemo } from "react"
22
import useSWRImmutable from "swr/immutable"
3+
import { Skeleton } from "@/components/ui/skeleton"
34

45
async function orcidFetch(orcid: string) {
56
const req = await fetch(`https://pub.orcid.org/v3.0/${orcid}`, {
@@ -29,9 +30,10 @@ export function OrcidDisplay({ orcid }: { orcid: string }) {
2930
}, [data])
3031

3132
useEffect(() => {
32-
if (error) console.log(error)
33-
}, [error])
33+
if (error) console.warn(`OrcidDisplay failed to resolve ${orcid}`, error)
34+
}, [error, orcid])
3435

3536
if (familyName && givenName) return givenName + " " + familyName
36-
return null
37+
if (error) return orcid
38+
return <Skeleton className="rfs-h-4 rfs-w-14 rfs-bg-muted-foreground/10" />
3739
}

src/components/ui/skeleton.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { cn } from "@/lib/utils"
2+
3+
function Skeleton({
4+
className,
5+
...props
6+
}: React.HTMLAttributes<HTMLDivElement>) {
7+
return (
8+
<div
9+
className={cn("rfs-animate-pulse rfs-rounded-md rfs-bg-muted", className)}
10+
{...props}
11+
/>
12+
)
13+
}
14+
15+
export { Skeleton }

src/config/FairDOConfig.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { RequestState } from "@elastic/search-ui"
1+
import { RequestState, SearchFieldConfiguration } from "@elastic/search-ui"
22

33
export interface FairDOCoreFacetConfig {
44
key: string
@@ -47,7 +47,7 @@ export interface FairDOIndexConfig {
4747
/**
4848
* Fields that support searching
4949
*/
50-
searchFields: string[]
50+
searchFields: (string | ({ field: string } & SearchFieldConfiguration))[]
5151
/**
5252
* Fields that should be included in the results for a search query
5353
*/

src/config/FairDOConfigBuilder.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ export class FairDOConfigBuilder {
6363
index_names.push(index.name)
6464

6565
allSearchFields = (index.searchFields || []).reduce((acc, n) => {
66-
acc[n] = {}
66+
if (typeof n === "string") {
67+
acc[n] = {}
68+
} else {
69+
acc[n.field] = n
70+
}
6771

6872
return acc
6973
}, allSearchFields)

src/stories/FairDOElasticSearch.stories.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,18 @@ const demoConfig: FairDOConfig = {
7171
}
7272
],
7373
resultFields: [], // Leave empty to get all fields
74-
searchFields: ["name", "pid", "hasMetadata", "isMetadataFor", "NMR_Method"]
74+
searchFields: [
75+
{ field: "name", weight: 2 },
76+
{ field: "pid", weight: 2 },
77+
"hasMetadata",
78+
"isMetadataFor",
79+
"NMR_Method",
80+
"digitalObjectType",
81+
"Acquisition_Nucleus",
82+
"Pulse_Sequence_Name",
83+
"hadPrimarySource",
84+
"resourceType"
85+
]
7586
}
7687
],
7788
initialState: {

0 commit comments

Comments
 (0)