Skip to content

An AI-powered search engine with a generative UI

chore: Improve display of search result URLs

Yoshiki Miurab262f951cc3d
diff --git a/components/search-results.tsx b/components/search-results.tsx
index 89de31cb..5e7e6a41 100644
--- a/components/search-results.tsx
+++ b/components/search-results.tsx
@@ -21,6 +21,11 @@ export function SearchResults({ results }: SearchResultsProps) {
const displayedResults = showAllResults ? results : results.slice(0, 3)
const additionalResultsCount = results.length > 3 ? results.length - 3 : 0
+ const displayUrlName = (url: string) => {
+ const hostname = new URL(url).hostname
+ const parts = hostname.split('.')
+ return parts.length > 2 ? parts.slice(1, -1).join('.') : parts[0]
+ }
return (
<div className="flex flex-wrap">
@@ -32,7 +37,7 @@ export function SearchResults({ results }: SearchResultsProps) {
<p className="text-xs line-clamp-2">
{result.title || result.content}
</p>
- <div className="mt-2 flex items-center space-x-2">
+ <div className="mt-2 flex items-center space-x-1">
<Avatar className="h-4 w-4">
<AvatarImage
src={`https://www.google.com/s2/favicons?domain=${
@@ -45,7 +50,7 @@ export function SearchResults({ results }: SearchResultsProps) {
</AvatarFallback>
</Avatar>
<div className="text-xs opacity-60 truncate">
- {new URL(result.url).hostname}
+ {`${displayUrlName(result.url)} - ${index + 1}`}
</div>
</div>
</CardContent>
diff --git a/lib/agents/researcher.tsx b/lib/agents/researcher.tsx
index fd04a449..6e6f5eed 100644
--- a/lib/agents/researcher.tsx
+++ b/lib/agents/researcher.tsx
@@ -34,7 +34,7 @@ export async function researcher(
For each user query, utilize the search results to their fullest potential to provide additional information and assistance in your response.
If there are any images relevant to your answer, be sure to include them as well.
Aim to directly address the user's question, augmenting your response with insights gleaned from the search results.
- Whenever quoting or referencing information from a specific URL, always explicitly cite the source URL using the [number](url) format. Multiple citations can be included as needed, e.g., [[number]](url), [[number]](url).
+ Whenever quoting or referencing information from a specific URL, always explicitly cite the source URL using the [[number]](url) format. Multiple citations can be included as needed, e.g., [[number]](url), [[number]](url).
The retrieve tool can only be used with URLs provided by the user. URLs from search results cannot be used.
If it is a domain or a site name instead of a URL, specify it in the include_domains of the search tool.
Please match the language of the response to the user's language. Current date and time: ${currentDate}`,