Browse Source

search bug fixes.

Tongyanqun 1 year ago
parent
commit
8e2e76fdf1
4 changed files with 19 additions and 26 deletions
  1. 1 1
      README.md
  2. 3 3
      app/src/components/AppHeader.vue
  3. 0 21
      webserver/handlers/book.py
  4. 15 1
      webserver/handlers/meta.py

+ 1 - 1
README.md

@@ -1,3 +1,3 @@
-本代码工程Fork自:[GitHub-TaleBook](https://github.com/talebook/talebook) ,感谢作者贡献这么好的开源项目。
+本代码工程Fork自:[GitHub-TaleBook](https://github.com/talebook/talebook) ,感谢作者贡献这么好的开源项目。本站按照自己的使用习惯做了部分修改和优化。
 
 安装使用介绍:[食用方法](https://codefine.site/3251.html)

+ 3 - 3
app/src/components/AppHeader.vue

@@ -103,7 +103,7 @@
                     ref="search"
                     v-model="search"
                     name="name"
-                    label="Search"
+                    label="搜索书籍"
                     class="d-none d-sm-flex ml-8"
                 >
                 </v-text-field>
@@ -342,7 +342,7 @@ export default {
         },
         do_mobile_search: function () {
             if (this.search.trim() !== "") {
-                this.$router.push("/search?name=" + this.search).catch(() => {
+                this.$router.push("/search/" + this.search).catch(() => {
                 });
             } else {
                 this.$refs.mobile_search.focus();
@@ -350,7 +350,7 @@ export default {
         },
         do_search: function () {
             if (this.search.trim() !== "") {
-                this.$router.push("/search?name=" + this.search).catch(() => {
+                this.$router.push("/search/" + this.search).catch(() => {
                 });
             } else {
                 this.$refs.search.focus();

+ 0 - 21
webserver/handlers/book.py

@@ -508,26 +508,6 @@ class RecentBook(ListHandler):
         return self.render_book_list(ids=ids, title=title, sort_by_id=True)
 
 
-class SearchBook(ListHandler):
-    def get(self):
-        name = self.get_argument("name", "")
-        if not name.strip():
-            return self.write({"err": "params.invalid", "msg": _(u"请输入搜索关键字")})
-
-        title = _(u"搜索:%(name)s") % {"name": name}
-        id_set = set()
-        id_list = []
-        for i in ["title", "author", "tag", "series"]:
-            ids_tmp = self.cache.search("%s:%s" % (i, name))
-            for id in ids_tmp:
-                if id not in id_set:
-                    id_set.add(id)
-                    id_list.append(id)
-            logging.info("keyword: %s:%s" % (i, name))
-            logging.info("books: {}".format(ids_tmp))
-        return self.render_book_list(ids=id_list, title=title)
-
-
 class HotBook(ListHandler):
     @js
     def get(self):
@@ -885,7 +865,6 @@ class BookPush(BaseHandler):
 def routes():
     return [
         (r"/api/index", Index),
-        (r"/api/search", SearchBook),
         (r"/api/recent", RecentBook),
         (r"/api/hot", HotBook),
         (r"/api/book/nav", BookNav),

+ 15 - 1
webserver/handlers/meta.py

@@ -72,6 +72,7 @@ class MetaBooks(ListHandler):
             "series": _('"%(name)s"丛书包含的书籍'),
             "rating": _("评分为%(name)s星的书籍"),
             "publisher": _(u'"%(name)s"出版的书籍'),
+            "search": _(u"搜索:%(name)s")
         }
         start = self.get_argument_start()
         try:
@@ -110,6 +111,19 @@ class MetaBooks(ListHandler):
                 "books": [self.fmt(b) for b in books],
             }
 
+        if meta in ["search"]:
+            id_set = set()
+            id_list = []
+            for i in ["title", "author", "tag", "series"]:
+                ids_tmp = self.cache.search("%s:%s" % (i, name))
+                for id in ids_tmp:
+                    if id not in id_set:
+                        id_set.add(id)
+                        id_list.append(id)
+                logging.info("keyword: %s:%s" % (i, name))
+                logging.info("books: {}".format(ids_tmp))
+            return self.render_book_list(ids=id_list, title=title)
+
         category = meta + "s" if meta in ["tag", "author"] else meta
         if meta in ["rating"]:
             try:
@@ -138,7 +152,7 @@ class MetaBooks(ListHandler):
 def routes():
     return [
         (r"/api/(author|publisher|tag|rating|series)", MetaList),
-        (r"/api/(author|publisher|tag|rating|series)/(.*)", MetaBooks),
+        (r"/api/(author|publisher|tag|rating|series|search)/(.*)", MetaBooks),
         (r"/api/author/(.*)/update", AuthorBooksUpdate),
         (r"/api/publisher/(.*)/update", PubBooksUpdate),
     ]