@@ -4,7 +4,7 @@ import { Tables } from "./supabase.types.generated";
44import { supabase } from "./supabase.server" ;
55import { slog } from "../modules/observability.server" ;
66import { authorIdSchema } from "./author.shape" ;
7- import { shuffle , uniqBy } from "es-toolkit" ;
7+ import { uniqBy } from "es-toolkit" ;
88import TTLCache from "@isaacs/ttlcache" ;
99import { format , hoursToMilliseconds } from "date-fns" ;
1010
@@ -162,32 +162,19 @@ export class PackageService {
162162 query : string ,
163163 options ?: { limit ?: number ; permutations ?: number } ,
164164 ) {
165- const { limit = 20 , permutations = 3 } = options || { } ;
165+ const { limit = 20 } = options || { } ;
166166
167- const randomQueries = Array . from ( { length : permutations } , ( ) => {
168- return shuffle ( query . split ( " " ) ) . join ( " " ) ;
167+ const { error, data } = await supabase . rpc ( "find_closest_packages" , {
168+ search_term : query ,
169+ result_limit : limit ,
169170 } ) ;
170171
171- const allQueries = [ query , ...randomQueries ] ;
172-
173- const nestedHits = await Promise . all (
174- allQueries . map ( async ( query ) => {
175- const { data, error } = await supabase
176- . from ( "cran_packages" )
177- . select ( "id,name" )
178- . textSearch ( "name, title, description" , query , { config : "english" } )
179- . limit ( limit ) ;
180-
181- if ( error ) {
182- slog . error ( "Error in searchPackages" , error ) ;
183- return [ ] ;
184- }
185-
186- return data ;
187- } ) ,
188- ) ;
172+ if ( error ) {
173+ slog . error ( "Error in searchPackages" , error ) ;
174+ return [ ] ;
175+ }
189176
190- return uniqBy ( nestedHits . flat ( ) , ( item ) => item . id ) ;
177+ return uniqBy ( data , ( item ) => item . id ) ;
191178 }
192179
193180 private static sanitizeSitemapName ( name : string ) {
0 commit comments