|
1 | 1 | import io |
2 | | -import logging |
3 | 2 | import os |
4 | 3 | import re |
5 | 4 | import traceback |
@@ -347,34 +346,36 @@ class Query(serializers.Serializer): |
347 | 346 | # 知识库id |
348 | 347 | workspace_id = serializers.CharField(required=True, label=_('workspace id')) |
349 | 348 | knowledge_id = serializers.UUIDField(required=True, label=_('knowledge id')) |
350 | | - name = serializers.CharField(required=False, max_length=128, min_length=1, allow_null=True, allow_blank=True, |
351 | | - label=_('document name')) |
352 | | - hit_handling_method = serializers.CharField(required=False, label=_('hit handling method')) |
353 | | - is_active = serializers.BooleanField(required=False, label=_('document is active')) |
| 349 | + name = serializers.CharField( |
| 350 | + required=False, max_length=128, min_length=1, allow_null=True, allow_blank=True, label=_('document name') |
| 351 | + ) |
| 352 | + hit_handling_method = serializers.CharField( |
| 353 | + required=False, label=_('hit handling method'), allow_null=True, allow_blank=True |
| 354 | + ) |
| 355 | + is_active = serializers.BooleanField(required=False, label=_('document is active'), allow_null=True) |
354 | 356 | task_type = serializers.IntegerField(required=False, label=_('task type')) |
355 | | - status = serializers.CharField(required=False, label=_('status')) |
356 | | - order_by = serializers.CharField(required=False, label=_('order by')) |
| 357 | + status = serializers.CharField(required=False, label=_('status'), allow_null=True, allow_blank=True) |
| 358 | + order_by = serializers.CharField(required=False, label=_('order by'), allow_null=True, allow_blank=True) |
357 | 359 |
|
358 | 360 | def get_query_set(self): |
359 | 361 | query_set = QuerySet(model=Document) |
360 | 362 | query_set = query_set.filter(**{'knowledge_id': self.data.get("knowledge_id")}) |
361 | 363 | if 'name' in self.data and self.data.get('name') is not None: |
362 | 364 | query_set = query_set.filter(**{'name__icontains': self.data.get('name')}) |
363 | | - if 'hit_handling_method' in self.data and self.data.get('hit_handling_method') is not None: |
| 365 | + if 'hit_handling_method' in self.data and self.data.get('hit_handling_method') not in [None, '']: |
364 | 366 | query_set = query_set.filter(**{'hit_handling_method': self.data.get('hit_handling_method')}) |
365 | 367 | if 'is_active' in self.data and self.data.get('is_active') is not None: |
366 | 368 | query_set = query_set.filter(**{'is_active': self.data.get('is_active')}) |
367 | | - if 'status' in self.data and self.data.get( |
368 | | - 'status') is not None: |
| 369 | + if 'status' in self.data and self.data.get('status') is not None: |
369 | 370 | task_type = self.data.get('task_type') |
370 | | - status = self.data.get( |
371 | | - 'status') |
| 371 | + status = self.data.get('status') |
372 | 372 | if task_type is not None: |
373 | 373 | query_set = query_set.annotate( |
374 | 374 | reversed_status=Reverse('status'), |
375 | | - task_type_status=Substr('reversed_status', TaskType(task_type).value, |
376 | | - 1), |
377 | | - ).filter(task_type_status=State(status).value).values('id') |
| 375 | + task_type_status=Substr('reversed_status', TaskType(task_type).value, 1), |
| 376 | + ).filter( |
| 377 | + task_type_status=State(status).value |
| 378 | + ).values('id') |
378 | 379 | else: |
379 | 380 | if status != State.SUCCESS.value: |
380 | 381 | query_set = query_set.filter(status__icontains=status) |
|
0 commit comments