649c79c36519a3cb3aac9c456150d7da1ee988ec
[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 exit 1
101
102 T1=`grep ": 1 " scores.data | head -1 | cut -d'#' -f2 | cut -d' ' -f2`
103 T2=`grep ": 2 " scores.data | head -1 | cut -d'#' -f2 | cut -d' ' -f2`
104 T3=`grep ": 3 " scores.data | head -1 | cut -d'#' -f2 | cut -d' ' -f2`
105 T4=`grep ": 4 " scores.data | head -1 | cut -d'#' -f2 | cut -d' ' -f2`
106 T5=`grep ": 5 " scores.data | head -1 | cut -d'#' -f2 | cut -d' ' -f2`
107 T6=`grep ": 6 " scores.data | head -1 | cut -d'#' -f2 | cut -d' ' -f2`
108
109 echo "
110   set term png
111   set out \"plot.png\"
112   set title \"$HEADLINE\"
113   plot \"scores.data\" using 0:(\$2==1?\$6:1/0) with points title \"1: $T1\", \
114        \"scores.data\" using 0:(\$2==2?\$6:1/0) with points title \"2: $T2\", \
115        \"scores.data\" using 0:(\$2==3?\$6:1/0) with points title \"3: $T3\", \
116        \"scores.data\" using 0:(\$2==4?\$6:1/0) with points title \"4: $T4\", \
117        \"scores.data\" using 0:(\$2==5?\$6:1/0) with points title \"5: $T5\", \
118        \"scores.data\" using 0:(\$2==6?\$6:1/0) with points title \"6: $T6\"
119 " > plot.cmd
120 cat plot.cmd | gnuplot
121
122
123
124 echo "All done"
125 kill `cat $PIDFILE`
126 rm -f $PIDFILE 
127