Skip to content

Commit 07e0d0b

Browse files
committed
[fix] update stop words to support special Chinese chars in search query
1 parent 735560f commit 07e0d0b

File tree

4 files changed

+7
-3
lines changed

4 files changed

+7
-3
lines changed

app/models/searchcache.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# "数据分析与实践" -> "数据分析及实践"
1717
# "概率论和数理统计" -> "概率论与数理统计"
1818
def is_chinese_stop_char(c: str) -> bool:
19-
STOP = ["与", "和", "及"]
19+
STOP = ["与", "和", "及", ",", "、", "。", ":", "(", ")", "【", "】"]
2020
return c in STOP
2121

2222

app/views/search/sqlcache.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# from app.utils import print_sqlalchemy_statement
1010

1111

12-
filter = lambda x: re.sub(r"""[~`!@#$%^&*{}\[\]\\:\";'<>,/\+\-\~\(\)><\x00-\x1F\x7F]""", " ", x)
12+
filter = lambda x: re.sub(r"""[~`!@#$%^&*{}\[\]\\:\";'<>,/\+\-\~\(\)><,、。:【】()?“”「」·\x00-\x1F\x7F]""", " ", x)
1313

1414

1515
def init() -> None:

app/views/search/sqllike.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import re
1616

1717

18-
filter = lambda x: re.sub(r'''[~`!@#$%^&*{}[]|\\:";'<>?,./]''', ' ', x)
18+
filter = lambda x: re.sub(r'''[~`!@#$%^&*{}[]|\\:";'<>?,./,、。:【】()?“”「」·]''', ' ', x)
1919

2020

2121
def init() -> None:

tests/import_courses_new.py

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from app.models import *
77
from datetime import datetime
88

9+
910
def parse_file(filename):
1011
data = []
1112
with open(filename) as f:
@@ -250,6 +251,9 @@ def load_courses(insert=True):
250251
course_class.term = term
251252
course_class.cno = class_code
252253

254+
# update course search cache
255+
CourseSearchCache.update(course, commit=False)
256+
253257
print('load complete, committing changes to database')
254258
db.session.commit()
255259
print('%d new teachers loaded' % new_teacher_count)

0 commit comments

Comments
 (0)