✨ (search): 书目搜索带上作者参数

/store/search 的 author 不再写死为空。不传时仍是空串。
This commit is contained in:
Garfield committed 2026-11-26 15:52:52 +08:00
1 parent f4f8386a61
commit a890c230ac
4 files changed
+16 -9

No files matched your search

@@ -72,11 +72,12 @@ end
--- 书城搜索(App ``GET /store/search``)。回包书在 ``data[]``,每条 ``bookInfo``;补成 ``books[]`` 交给 mapper。 --- 书城搜索(App ``GET /store/search``)。回包书在 ``data[]``,每条 ``bookInfo``;补成 ``books[]`` 交给 mapper。
---@param keyword string ---@param keyword string
---@param cb fun(data: table|nil, err: string|nil) ---@param cb fun(data: table|nil, err: string|nil)
---@param author string|nil 作者过滤;旧调用不传,查询里仍是空串
---@return { cancel: fun() }|nil ---@return { cancel: fun() }|nil
function Client:searchAsync(keyword, cb) function Client:searchAsync(keyword, cb, author)
return Eink.callAsync("GET", "/store/search", { return Eink.callAsync("GET", "/store/search", {
query = { query = {
keyword = keyword, author = "", authorVids = "", categoryId = "", keyword = keyword, author = type(author) == "string" and author or "", authorVids = "", categoryId = "",
count = 20, maxIdx = 0, type = 0, v = 2, outer = 0, fromBookId = "", count = 20, maxIdx = 0, type = 0, v = 2, outer = 0, fromBookId = "",
scope = 0, scene = 0, filterType = 0, filterField = "", queryUid = "", isQueryWord = 0, scope = 0, scene = 0, filterType = 0, filterField = "", queryUid = "", isQueryWord = 0,
}, },
@@ -1520,18 +1520,19 @@ function Source:paragraphReviewsEnabled()
return require("source.review_setting").enabled(self.id) return require("source.review_setting").enabled(self.id)
end end
--- 按书名搜索微信读书书目(关联本地书看段评用)。 --- 按书名搜索微信读书书目(关联本地书看段评用)。author 写入 /store/search 的作者参数。
---@param keyword string ---@param keyword string
---@param cb fun(books: WechatSearchBook[]|nil, err: string|nil) ---@param cb fun(books: WechatSearchBook[]|nil, err: string|nil)
---@param author string|nil
---@return { cancel: fun() }|nil ---@return { cancel: fun() }|nil
function Source:searchBooksAsync(keyword, cb) function Source:searchBooksAsync(keyword, cb, author)
return self._client:searchAsync(keyword, function(wire, err) return self._client:searchAsync(keyword, function(wire, err)
if not wire then if not wire then
cb(nil, err) cb(nil, err)
return return
end end
cb(Mapper.searchBooks(wire)) cb(Mapper.searchBooks(wire))
end) end, author)
end end
--- 书城搜索:回包形状同 listStoreAsync。 --- 书城搜索:回包形状同 listStoreAsync。
+4
View File
@@ -214,7 +214,11 @@ do
req = call(client.searchAsync, client, "三体", function(d) wire = d end) req = call(client.searchAsync, client, "三体", function(d) wire = d end)
Assert.eq(req.path, "/store/search") Assert.eq(req.path, "/store/search")
Assert.eq(req.query.keyword, "三体") Assert.eq(req.query.keyword, "三体")
Assert.eq(req.query.author, "")
Assert.eq(req.query.v, 2) Assert.eq(req.query.v, 2)
req = call(client.searchAsync, client, "三体", function() end, "刘慈欣")
Assert.eq(req.query.keyword, "三体")
Assert.eq(req.query.author, "刘慈欣")
Assert.eq(req.query.type, 0) Assert.eq(req.query.type, 0)
Assert.eq(wire.books[1].bookInfo.bookId, "9") Assert.eq(wire.books[1].bookInfo.bookId, "9")
end end
+5 -4
View File
@@ -1369,9 +1369,9 @@ do
require("moonsource_weread.toc").clear() require("moonsource_weread.toc").clear()
-- 书名搜索:只留带 bookId 的书目。 -- 书名搜索:只留带 bookId 的书目。
local keyword local keyword, got_author
fake_client.searchAsync = function(_self, word, cb) fake_client.searchAsync = function(_self, word, cb, author)
keyword = word keyword, got_author = word, author
cb({ books = { cb({ books = {
{ type = 0, bookInfo = { bookId = 834464, title = "活着", author = "余华", publisher = "作家" } }, { type = 0, bookInfo = { bookId = 834464, title = "活着", author = "余华", publisher = "作家" } },
{ type = 3, mpInfo = { title = "公众号" } }, { type = 3, mpInfo = { title = "公众号" } },
@@ -1379,8 +1379,9 @@ do
return { cancel = function() end } return { cancel = function() end }
end end
local found local found
src:searchBooksAsync("活着", function(books) found = books end) src:searchBooksAsync("活着", function(books) found = books end, "余华")
Assert.eq(keyword, "活着") Assert.eq(keyword, "活着")
Assert.eq(got_author, "余华")
Assert.len(found, 1) Assert.len(found, 1)
Assert.eq(found[1].book_id, "834464") Assert.eq(found[1].book_id, "834464")
Assert.eq(found[1].author, "余华") Assert.eq(found[1].author, "余华")