This commit is contained in:
parent
2677f4b8b6
commit
70516db074
5 changed files with 120 additions and 11 deletions
|
@ -39,13 +39,61 @@ class ItemViewSet(viewsets.ModelViewSet):
|
|||
|
||||
def filter_items(items, query):
|
||||
query_tokens = query.split(' ')
|
||||
matches = []
|
||||
for item in items:
|
||||
value = 0
|
||||
if "I#" + str(item.id) in query:
|
||||
value += 12
|
||||
matches.append(
|
||||
{'type': 'item_id', 'text': f'is exactly {item.id} and matched "I#{item.id}"'})
|
||||
elif "#" + str(item.id) in query:
|
||||
value += 11
|
||||
matches.append(
|
||||
{'type': 'item_id', 'text': f'is exactly {item.id} and matched "#{item.id}"'})
|
||||
elif str(item.id) in query:
|
||||
value += 10
|
||||
matches.append({'type': 'item_id', 'text': f'is exactly {item.id}'})
|
||||
for issue in item.related_issues:
|
||||
if "T#" + issue.short_uuid() in query:
|
||||
value += 8
|
||||
matches.append({'type': 'ticket_uuid',
|
||||
'text': f'is exactly {issue.short_uuid()} and matched "T#{issue.short_uuid()}"'})
|
||||
elif "#" + issue.short_uuid() in query:
|
||||
value += 5
|
||||
matches.append({'type': 'ticket_uuid',
|
||||
'text': f'is exactly {issue.short_uuid()} and matched "#{issue.short_uuid()}"'})
|
||||
elif issue.short_uuid() in query:
|
||||
value += 3
|
||||
matches.append({'type': 'ticket_uuid', 'text': f'is exactly {issue.short_uuid()}'})
|
||||
if "T#" + str(issue.id) in query:
|
||||
value += 8
|
||||
matches.append({'type': 'ticket_id', 'text': f'is exactly {issue.id} and matched "T#{issue.id}"'})
|
||||
elif "#" + str(issue.id) in query:
|
||||
value += 5
|
||||
matches.append({'type': 'ticket_id', 'text': f'is exactly {issue.id} and matched "#{issue.id}"'})
|
||||
elif str(issue.id) in query:
|
||||
value += 3
|
||||
matches.append({'type': 'ticket_id', 'text': f'is exactly {issue.id}'})
|
||||
for comment in issue.comments.all():
|
||||
for token in query_tokens:
|
||||
if token in comment.comment:
|
||||
value += 1
|
||||
matches.append({'type': 'ticket_comment', 'text': f'contains {token}'})
|
||||
for token in query_tokens:
|
||||
if token in issue.name:
|
||||
value += 1
|
||||
matches.append({'type': 'ticket_name', 'text': f'contains {token}'})
|
||||
for token in query_tokens:
|
||||
if token in item.description:
|
||||
value += 1
|
||||
matches.append({'type': 'item_description', 'text': f'contains {token}'})
|
||||
for comment in item.comments.all():
|
||||
for token in query_tokens:
|
||||
if token in comment.comment:
|
||||
value += 1
|
||||
matches.append({'type': 'comment', 'text': f'contains {token}'})
|
||||
if value > 0:
|
||||
yield {'search_score': value, 'item': item}
|
||||
yield {'search_score': value, 'item': item, 'search_matches': matches}
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue