예제 #1
0
 def global_search_content(self, user_id: str, search_info: str, page: int):
     try:  # 判断是否存在用户 id
         # 判断是否存在用户 id
         if not self.user_id_exist(user_id):
             return error.error_non_exist_user_id_when_search(user_id)
         # 查询
         # # 先找出这家店的book_id
         cursor = self.conn.cursor()
         query = "SELECT DISTINCT book_id FROM \"store\" "  # global 的时候去掉where
         cursor.execute(query)
         book_id = []
         rows = cursor.fetchall()
         for row in rows:
             book_id.append(row[0])
         _content_search = search.Search(search_info, page,
                                         book_id)  # 实例化一个search类
         book_list = _content_search.search_bookid_content(
         )  # !!!!!调用函数,得到返回结果 返回得到相关列表
         if len(book_list) == 0:
             return error.error_page_out_of_range(user_id)
     except (Exception, psycopg2.DatabaseError) as e:
         logging.info("528, {}".format(str(e)))
         return 528, "{}".format(str(e)), " "
     except BaseException as e:
         logging.info("530, {}".format(str(e)))
         return 530, "{}".format(str(e)), " "
     return 200, "ok", book_list
예제 #2
0
 def global_search_tag(self, user_id: str, search_info: str, page: int):
     try:
         # 判断是否存在用户 id
         if not self.user_id_exist(user_id):
             return error.error_non_exist_user_id_when_search(user_id)
         # 进行查询
         cursor = self.conn.cursor()
         # query =
         cursor.execute("SELECT DISTINCT book_id FROM \"store\" ")
         book_id = []
         rows = cursor.fetchall()
         for row in rows:
             book_id.append(row[0])
         title_search = search.Search(search_info, page, book_id)
         # 考虑到用户会输入多个 tag 的情况,选出覆盖全部 tag 的 bookid
         tag_search = search_info.split(" ")  # 获得用户输入的多个 tag
         book_list = title_search.search_bookid_tag(tag_search)
         if len(book_list) == 0:
             return error.error_page_out_of_range(user_id)
     except (Exception, psycopg2.DatabaseError) as e:
         logging.info("528, {}".format(str(e)))
         return 528, "{}".format(str(e)), " "
     except BaseException as e:
         logging.info("530, {}".format(str(e)))
         return 530, "{}".format(str(e)), " "
     return 200, "ok", book_list
예제 #3
0
 def store_search_book_intro(self, user_id: str, store_id: str,
                             search_info: str, page: int):
     try:
         # 判断是否存在用户 id
         if not self.user_id_exist(user_id):
             return error.error_non_exist_user_id_when_search(user_id)
         # 查询
         ## 先找出这家店的book_id
         cursor = self.conn.cursor()
         # query =     #global 的时候去掉where
         cursor.execute(
             "SELECT DISTINCT book_id FROM \"store\" WHERE store_id = %s",
             (store_id, ))
         book_id = []
         rows = cursor.fetchall()
         for row in rows:
             book_id.append(row[0])
         book_intro_search = search.Search(search_info, page,
                                           book_id)  #实例化一个search类
         book_list = book_intro_search.search_bookid_book_intro(
         )  # !!!!!调用函数,得到返回结果
         if len(book_list) == 0:
             return error.error_page_out_of_range(user_id)
     except (Exception, psycopg2.DatabaseError) as e:
         logging.log(logging.CRITICAL, "*****" + store_id + "*******")
         traceback.print_exc()
         logging.info("528, {}".format(str(e)))
         return 528, "{}".format(str(e)), " "
     except BaseException as e:
         logging.info("530, {}".format(str(e)))
         return 530, "{}".format(str(e)), " "
     return 200, "ok", book_list
예제 #4
0
 def get_store_id(self, user_id: str, book_id):
     try:
         # 判断是否存在用户 id
         if not self.user_id_exist(user_id):
             return error.error_non_exist_user_id_when_search(user_id)
         cursor = self.conn.cursor()
         cursor.execute(
             "SELECT DISTINCT store_id FROM \"store\" WHERE book_id = (%s)",
             (book_id, ))
         rows = cursor.fetchall()
         store_id_list = ""
         #store_id_list = []
         for row in rows:
             store_id_list = store_id_list + " " + row[0]
             #store_id_list.append(row[0])
         return 200, "ok", store_id_list
     except (Exception, psycopg2.DatabaseError) as e:
         logging.info("528, {}".format(str(e)))
         return 528, "{}".format(str(e)), ""
     except BaseException as e:
         logging.info("530, {}".format(str(e)))
         return 530, "{}".format(str(e)), ""