f1176350297ecb065da42a79956a1a8b754d3b2f
[pazpar2-moved-to-github.git] / heikki / solr / test3.sh
1 #!/bin/bash
2 #
3 # Simple script (and config) to get pz2 to run against DBC's OpenSearch, and
4 # calculate rankings. See how they differ for different queries
5 #
6
7 if [ "$1" == "clean" ]
8 then
9   echo "Cleaning up"
10   rm -f $PIDFILE $YAZPIDFILE *.out *.log *.data *~ plot.cmd
11   exit
12 fi
13 killall pazpar2 
14
15 rm -f *.out *.log
16
17 URL="http://localhost:9017/"
18 CFG="test3.cfg"
19
20 PZ="../../src/pazpar2"
21 if [ ! -x $PZ ]
22 then
23   echo "$PZ2 not executable. Panic"
24   exit 1
25 fi
26
27 PIDFILE=pz2.pid
28
29 $PZ -f $CFG  -l pz2.log -p $PIDFILE &
30 sleep 0.2 # make sure it has time to start
31 echo "Init"
32 curl -s "$URL?command=init" > init.out
33 SESSION=`xml_grep --text_only "//session" init.out `
34 # cat init.out; echo
35 echo "Got session $SESSION"
36 SES="&session=$SESSION"
37
38
39 if [ -z "$1" ]
40 then
41   Q="computer"
42 else
43   Q=$1
44 fi
45
46 if [ -z "$2" ]
47 then
48   HEADLINE="$Q"
49 else
50   HEADLINE="$2: $Q"
51 fi
52
53 QRY=`echo $Q | sed 's/ /+/g' `
54
55 #SORT="sort=score"
56 SORT="sort=relevance_h"
57 #SEARCH="command=search$SES&$QRY&rank=1&sort=relevance"
58 #SEARCH="command=search$SES&$QRY"
59 #SEARCH="command=search$SES&query=$QRY&sort=relevance"
60 SEARCH="command=search$SES&query=$QRY&$SORT"
61 echo $SEARCH
62 curl -s "$URL?$SEARCH" > search.out
63 cat search.out | grep search
64 echo
65 sleep 0.5 # let the search start working
66
67 STAT="command=stat&$SES"
68 echo "" > stat.out
69 LOOPING=1
70 while [ $LOOPING = 1 ]
71 do
72   sleep 0.5
73   curl -s "$URL?$STAT" > stat.out
74   ACT=`xml_grep --text_only "//activeclients" stat.out`
75   HIT=`xml_grep --text_only "//hits" stat.out`
76   REC=`xml_grep --text_only "//records" stat.out`
77   echo "$ACT $HIT $REC"
78   echo "Hits/Fetched: $HIT / $REC" > stat.line
79   if grep -q "<activeclients>0</activeclients>" stat.out
80   then
81     LOOPING=0
82   fi
83   echo >> stats.out
84   cat stat.out >> stats.out
85 done
86
87
88 SHOW="command=show$SES&start=0&num=100&$SORT"
89 echo $SHOW
90 curl -s "http://localhost:9017/?$SHOW" > show.out
91 #grep "relevance" show.out | grep += | grep -v "(0)"
92 #grep "round-robin" show.out
93
94 # Plot the lines created by the code
95 grep plotline show.out > scores.data
96 echo "Client numbers"
97 cat scores.data | cut -d' ' -f2 | sort -u
98 head -10 scores.data
99
100 grep mergeplot show.out > merge.tmp
101 LINENUMBER="1"
102 LAST=""
103 echo "0 0 0" > merge.data
104 for lno in `cat merge.tmp | cut -d ' ' -f2`
105 do
106   if [ "$lno" != "$LAST" ]
107   then
108     echo "Found line $lno at $LINENUMBER"
109     grep "mergeplot $lno " merge.tmp | sed "s/mergeplot/$LINENUMBER/" >> merge.data
110     LAST=$lno
111     LINENUMBER=$(($LINENUMBER + 1))
112   fi
113 done
114 echo "$LINENUMBER 0 0 0" >> merge.data
115
116 #exit 1
117
118 T1=`grep ": 1 " scores.data | head -1 | cut -d'#' -f2 | cut -d' ' -f2`
119 T2=`grep ": 2 " scores.data | head -1 | cut -d'#' -f2 | cut -d' ' -f2`
120 T3=`grep ": 3 " scores.data | head -1 | cut -d'#' -f2 | cut -d' ' -f2`
121 T4=`grep ": 4 " scores.data | head -1 | cut -d'#' -f2 | cut -d' ' -f2`
122 T5=`grep ": 5 " scores.data | head -1 | cut -d'#' -f2 | cut -d' ' -f2`
123 T6=`grep ": 6 " scores.data | head -1 | cut -d'#' -f2 | cut -d' ' -f2`
124
125 echo "
126   set term png
127   set out \"plot.png\"
128   set title \"$HEADLINE\"
129   plot \"scores.data\" using 0:(\$2==1?\$6:1/0) with points title \"1: $T1\", \
130        \"scores.data\" using 0:(\$2==2?\$6:1/0) with points title \"2: $T2\", \
131        \"scores.data\" using 0:(\$2==3?\$6:1/0) with points title \"3: $T3\", \
132        \"scores.data\" using 0:(\$2==4?\$6:1/0) with points title \"4: $T4\", \
133        \"scores.data\" using 0:(\$2==5?\$6:1/0) with points title \"5: $T5\", \
134        \"scores.data\" using 0:(\$2==6?\$6:1/0) with points title \"6: $T6\"
135 " > plot.cmd
136 cat plot.cmd | gnuplot
137
138 echo "
139   set term png
140   set out \"cluster.png\"
141   set title \"$HEADLINE\"
142   plot \"merge.data\" using 1:3 with points title \"records\", \
143        \"merge.data\" using 1:4 with points title \"merged score\", \
144        \"merge.data\" using 1:5 with points title \"sum score\", \
145        \"merge.data\" using 1:6 with points title \"avg score\"
146 " > plot.cmd
147 cat plot.cmd | gnuplot
148
149
150 echo "All done"
151 kill `cat $PIDFILE`
152 rm -f $PIDFILE 
153