a
This commit is contained in:
@@ -17,7 +17,9 @@ const searchSchema = z.object({
|
||||
icon: z.string().optional(),
|
||||
enabled: z.boolean(),
|
||||
searchTemplate: z.string().optional(),
|
||||
rateLimit: z.number()
|
||||
rateLimit: z.number(),
|
||||
site: z.string().optional(),
|
||||
custom: z.boolean().optional()
|
||||
})),
|
||||
strategies: z.array(z.string()),
|
||||
maxResults: z.number().default(50)
|
||||
@@ -115,9 +117,21 @@ export async function POST(request: NextRequest) {
|
||||
);
|
||||
}
|
||||
|
||||
const resultUrls = Array.from(
|
||||
new Set(searchResults.map((result) => result.url).filter(Boolean))
|
||||
)
|
||||
const existingUrls = await fetchQuery(
|
||||
api.seenUrls.listExisting,
|
||||
{ projectId: projectId as any, urls: resultUrls },
|
||||
{ token }
|
||||
)
|
||||
const existingSet = new Set(existingUrls)
|
||||
const newUrls = resultUrls.filter((url) => !existingSet.has(url))
|
||||
const filteredResults = searchResults.filter((result) => !existingSet.has(result.url))
|
||||
|
||||
// Score and rank
|
||||
console.log(' Scoring opportunities...')
|
||||
const opportunities = scoreOpportunities(searchResults, analysis as EnhancedProductAnalysis)
|
||||
const opportunities = scoreOpportunities(filteredResults, analysis as EnhancedProductAnalysis)
|
||||
console.log(` ✓ Scored ${opportunities.length} opportunities`)
|
||||
if (jobId) {
|
||||
await fetchMutation(
|
||||
@@ -135,18 +149,22 @@ export async function POST(request: NextRequest) {
|
||||
);
|
||||
}
|
||||
|
||||
if (newUrls.length > 0) {
|
||||
await fetchMutation(
|
||||
api.seenUrls.markSeenBatch,
|
||||
{ projectId: projectId as any, urls: newUrls, source: "search" },
|
||||
{ token }
|
||||
);
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
data: {
|
||||
opportunities: opportunities.slice(0, 50),
|
||||
stats: {
|
||||
queriesGenerated: queries.length,
|
||||
rawResults: searchResults.length,
|
||||
opportunitiesFound: opportunities.length,
|
||||
highRelevance: opportunities.filter(o => o.relevanceScore >= 0.7).length,
|
||||
averageScore: opportunities.length > 0
|
||||
? opportunities.reduce((a, o) => a + o.relevanceScore, 0) / opportunities.length
|
||||
: 0
|
||||
rawResults: filteredResults.length,
|
||||
opportunitiesFound: opportunities.length
|
||||
},
|
||||
queries: queries.map(q => ({
|
||||
query: q.query,
|
||||
|
||||
Reference in New Issue
Block a user