Skip to content

Commit 6d6a174

Browse files
committed
fix: author search link
1 parent e69c3b2 commit 6d6a174

File tree

4 files changed

+39
-18
lines changed

4 files changed

+39
-18
lines changed

web/app/data/package.service.ts

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Tables } from "./supabase.types.generated";
44
import { supabase } from "./supabase.server";
55
import { slog } from "../modules/observability.server";
66
import { authorIdSchema } from "./author.shape";
7-
import { groupBy, uniqBy } from "es-toolkit";
7+
import { groupBy, omit, uniqBy } from "es-toolkit";
88
import TTLCache from "@isaacs/ttlcache";
99
import { format, hoursToMilliseconds } from "date-fns";
1010
import { embed } from "ai";
@@ -199,12 +199,12 @@ export class PackageService {
199199
]);
200200

201201
if (packageFTS.error) {
202-
slog.error("Error in searchPackages", packageFTS.error);
202+
slog.error("Error in searchPackages FTS", packageFTS.error);
203203
throw packageFTS.error;
204204
}
205205

206206
if (packageExact.error) {
207-
slog.error("Error in searchPackages", packageExact.error);
207+
slog.error("Error in searchPackages Exact", packageExact.error);
208208
throw packageExact.error;
209209
}
210210

@@ -217,20 +217,38 @@ export class PackageService {
217217

218218
if (embeddingSimilarity) {
219219
if (embeddingSimilarity.error) {
220-
slog.error("Error in searchPackages", embeddingSimilarity.error);
220+
slog.error(
221+
"Error in searchPackages Embeddings",
222+
embeddingSimilarity.error,
223+
);
221224
}
222225
}
223226

227+
// console.log(
228+
// "embeddingSimilarity",
229+
// embeddingSimilarity?.data?.map((x) => {
230+
// const { source_searchable_content, ...rest } = x;
231+
// return rest;
232+
// }),
233+
// );
234+
224235
// Prefer the exact match over the similarity match.
225236
// Therefore we filter out the similarity match if it's the same as the exact match.
226237
const sources = [
227-
...(embeddingFTS?.data || []),
228238
...(embeddingSimilarity?.data || []),
229-
].filter((item) => {
230-
const hasExactMatch =
231-
packageExact.data && packageExact.data.id === item.cran_package_id;
232-
return !hasExactMatch;
233-
});
239+
...(embeddingFTS?.data || []),
240+
]
241+
.filter((item) => {
242+
const hasExactMatch =
243+
packageExact.data && packageExact.data.id === item.cran_package_id;
244+
return !hasExactMatch;
245+
})
246+
.map((item) => {
247+
// Remove the source_searchable_content from the response
248+
// for now, as it's quite a lot of text data that's not
249+
// applied in the UI.
250+
return omit(item, ["source_searchable_content"]);
251+
});
234252

235253
const lexical = uniqBy(packageFTS.data, (item) => item.id)
236254
.filter((item) => {
@@ -263,7 +281,7 @@ export class PackageService {
263281
.maybeSingle();
264282

265283
if (error || !data) {
266-
slog.error("Error in searchPackages", error);
284+
slog.error("Error in searchPackages fetching package data", error);
267285
return null;
268286
}
269287

web/app/modules/search.hit.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Link } from "react-router";
22
import { Database } from "../data/supabase.types.generated";
33
import { Tag } from "./tag";
44
import { PropsWithChildren, ReactNode } from "react";
5+
import { RiArrowRightUpLine } from "@remixicon/react";
56

67
export type BaseSearchHit = { id: number; name: string; synopsis?: string };
78

@@ -62,11 +63,14 @@ export function PackageHit(props: {
6263
}
6364

6465
const isInternal = refData.source_type === "internal";
66+
const hasSource = Boolean(refData.source_url);
6567

6668
const content = (
6769
<Tag size="sm" className="flex items-center gap-2 leading-none">
6870
{sourceName}
69-
{/* !isInternal ? <RiArrowRightUpLine size={12} /> : null */}
71+
{!isInternal && hasSource ? (
72+
<RiArrowRightUpLine size={12} />
73+
) : null}
7074
</Tag>
7175
);
7276

@@ -105,7 +109,7 @@ export function AuthorHit(props: { item: BaseSearchHit; onClick: () => void }) {
105109
return (
106110
<>
107111
<HitLink
108-
to={`/package/${name}`}
112+
to={`/author/${name}`}
109113
name={name}
110114
tag={<Tag borderGradients="jade">CRAN Author</Tag>}
111115
onClick={onClick}

web/app/modules/search.nav.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
RefObject,
88
useCallback,
99
useEffect,
10-
useLayoutEffect,
1110
useRef,
1211
useState,
1312
} from "react";
@@ -65,7 +64,7 @@ export function NavSearch(props: Props) {
6564
action: "/api/search?index",
6665
});
6766
},
68-
100,
67+
150,
6968
{
7069
edges: ["trailing"],
7170
},
@@ -268,7 +267,7 @@ export function SearchResults(
268267
function useSyncedQueryHash() {
269268
const [q, setQ] = useState("");
270269

271-
useLayoutEffect(() => {
270+
useEffect(() => {
272271
const getValue = () => {
273272
const hashes = new URLSearchParams(window.location.hash.replace("#", ""));
274273
return hashes.get("q") || "";

web/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"private": true,
44
"sideEffects": false,
55
"type": "module",
6-
"version": "2.7.0",
6+
"version": "2.7.1",
77
"scripts": {
88
"postinstall": "npm run licenses.build",
99
"postuninstall": "npm run licenses.build",
@@ -100,4 +100,4 @@
100100
"engines": {
101101
"node": ">=20.0.0"
102102
}
103-
}
103+
}

0 commit comments

Comments
 (0)