diff --git a/hinghwa-dict-backend/word/word/urls.py b/hinghwa-dict-backend/word/word/urls.py index 837edf2..7314d59 100644 --- a/hinghwa-dict-backend/word/word/urls.py +++ b/hinghwa-dict-backend/word/word/urls.py @@ -13,4 +13,5 @@ path("/upload_standard", upload_standard), # WD0302POST path("/phonetic_ordering", csrf_exempt(PhoneticOrdering.as_view())), # WD0501 path("/dictionary", csrf_exempt(DictionarySearch.as_view())), # WD0502 + path("/search", csrf_exempt(searchWordsByTags)), ] diff --git a/hinghwa-dict-backend/word/word/views.py b/hinghwa-dict-backend/word/word/views.py index 8528444..09a6cc9 100644 --- a/hinghwa-dict-backend/word/word/views.py +++ b/hinghwa-dict-backend/word/word/views.py @@ -232,7 +232,7 @@ def load_word(request): print("load character {}".format(word.id)) else: raise Exception("add fail in {}".format(dic)) - PhoneticOrdering.sign = True # 词语批量上传,音序表需要重建 + PhoneticOrdering.sign = True # 词语批量上传,音序表需要重建 return JsonResponse({}, status=200) except Exception as e: return JsonResponse({"msg": str(e)}, status=500) @@ -453,3 +453,19 @@ def post(self, request) -> JsonResponse: {"words": result, "msg": "请求的词语太多了,请更精确一些"}, status=400 ) return JsonResponse({"words": result}, status=200) + + +# WD0203标签查询词语 +def searchWordsByTags(request): + try: + if request.method == "GET": + query = request.GET["tags"] + query = re.findall(r"[\u4e00-\u9fa5]+", query) + result = [] + for key in query: + words = Word.objects.filter(tags__icontains=key) + for word in words: + result.append(word_all(word)) + return JsonResponse({"total": len(result), "words": result}, status=200) + except Exception as e: + return JsonResponse({"msg": str(e)}, status=500)