feat: support searchapi (#1284)

This commit is contained in:
yetone
2025-02-17 00:36:00 +08:00
committed by GitHub
parent c60dc6c316
commit 7fa7b0fa3b
4 changed files with 52 additions and 5 deletions

View File

@@ -56,10 +56,39 @@ M._defaults = {
title = result.title,
link = result.link,
snippet = result.snippet,
date = result.date,
}
end
)
:take(5)
:take(10)
:totable()
return vim.json.encode(jsn), nil
end
return "", nil
end,
},
searchapi = {
api_key_name = "SEARCHAPI_API_KEY",
extra_request_body = {
engine = "google",
},
---@type WebSearchEngineProviderResponseBodyFormatter
format_response_body = function(body)
if body.answer_box ~= nil then return body.answer_box.result, nil end
if body.organic_results ~= nil then
local jsn = vim
.iter(body.organic_results)
:map(
function(result)
return {
title = result.title,
link = result.link,
snippet = result.snippet,
date = result.date,
}
end
)
:take(10)
:totable()
return vim.json.encode(jsn), nil
end
@@ -84,7 +113,7 @@ M._defaults = {
}
end
)
:take(5)
:take(10)
:totable()
return vim.json.encode(jsn), nil
end