-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery_ticket.sh
executable file
·66 lines (59 loc) · 1.42 KB
/
query_ticket.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
print_ticket=false
consider_full_ticket=false
nb_tickets=5
while [[ $# -gt 0 ]]; do
case $1 in
-n|--limit)
nb_tickets="$2"
shift
shift
;;
-p|--print-ticket)
print_ticket=true
shift
;;
-f|--consider-full-ticket)
consider_full_ticket=true
shift
;;
-*|--*)
echo "Unknown option $1" >&2
exit 1
;;
*)
if [ ! -z "$ticket_number" ] ; then
echo "Only one positional argument expected" >&2
exit 1
fi
ticket_number="$1"
shift
;;
esac
done
if [ -z "$ticket_number" ] ; then
echo "One positional argument expected" >&2
exit 1
fi
readonly ticket_number nb_tickets print_ticket consider_full_ticket
readonly db="otrs"
readonly role="postgres"
readonly psql="psql -h localhost -U "$role" -d "$db" --tuples-only --no-align"
${psql[@]} <<EOF
SET search_path=aide,public;
SELECT t2.id, t2.tn $("$print_ticket" && echo ", t2c.conversation")
FROM ticket t1
JOIN ticket_embeddings t1e ON t1e.ticket_id = t1.id
JOIN ticket t2 ON t2.id <> t1.id
JOIN ticket_embeddings t2e ON t2e.ticket_id = t2.id
JOIN ticket_conversations t2c ON t2c.id = t2e.ticket_id
WHERE t1.tn = '$ticket_number'
$(
if "$consider_full_ticket" ; then
echo "ORDER BY t1e.conversation_embedding <-> t2e.conversation_embedding"
else
echo "ORDER BY t1e.first_article_embedding <-> t2e.first_article_embedding"
fi
)
LIMIT $nb_tickets;
EOF