From 1c4e92ed351883d2c81864c40d480d9e1cb5ac83 Mon Sep 17 00:00:00 2001 From: KevinHuSh Date: Thu, 16 May 2024 09:00:12 +0800 Subject: [PATCH] Knowledge base search is case sensitive (#797) ### What problem does this PR solve? #793 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- api/db/services/document_service.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/api/db/services/document_service.py b/api/db/services/document_service.py index eca6877a9f..70e7af77c5 100644 --- a/api/db/services/document_service.py +++ b/api/db/services/document_service.py @@ -16,6 +16,7 @@ import random from datetime import datetime from elasticsearch_dsl import Q +from peewee import fn from api.settings import stat_logger from api.utils import current_timestamp, get_format_time @@ -40,8 +41,9 @@ def get_by_kb_id(cls, kb_id, page_number, items_per_page, orderby, desc, keywords): if keywords: docs = cls.model.select().where( - cls.model.kb_id == kb_id, - cls.model.name.like(f"%%{keywords}%%")) + (cls.model.kb_id == kb_id), + (fn.LOWER(cls.model.name).contains(keywords.lower())) + ) else: docs = cls.model.select().where(cls.model.kb_id == kb_id) count = docs.count()