Commit 9f8fcef94b083179ecc31dc8e2e2141d6347536e

Authored by conradverm
1 parent b9237d6c

KTS-673

"The search algorithm needs some work"
Updated. Completed basics of script.

Committed By: Conrad Vermeulen
Reviewed By: Kevin Fourie

git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@7429 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing 1 changed file with 45 additions and 11 deletions
search2/search/bin/search.php
@@ -7,7 +7,6 @@ $username = ''; @@ -7,7 +7,6 @@ $username = '';
7 $password = ''; 7 $password = '';
8 $expr = ''; 8 $expr = '';
9 9
10 -print _kt('Command line search') . "...\n";  
11 10
12 $output = 'simple'; 11 $output = 'simple';
13 $verbose = false; 12 $verbose = false;
@@ -30,26 +29,40 @@ if ($argc > 0) @@ -30,26 +29,40 @@ if ($argc > 0)
30 case 'output': 29 case 'output':
31 switch(strtolower($value)) 30 switch(strtolower($value))
32 { 31 {
33 - case 'xml': $output = 'simple'; break; 32 + case 'xml': $output = 'xml'; break;
34 case 'csv': $output = 'csv'; break; 33 case 'csv': $output = 'csv'; break;
35 default: 34 default:
36 $output = 'simple'; 35 $output = 'simple';
37 } 36 }
  37 + break;
38 case 'user': 38 case 'user':
39 $username = $value; 39 $username = $value;
40 - print "* User = $value\n"; 40 + if ($verbose) print "* User = $value\n";
41 break; 41 break;
42 case 'pass': 42 case 'pass':
43 $password = $value; 43 $password = $value;
44 - print "* User = $value\n"; 44 + if ($verbose) print "* User = $value\n";
45 break; 45 break;
46 case 'help': 46 case 'help':
47 - print "Usage: search.php [verbose] user=username pass=password [output=simple|xml|csv] 'expression'\n"; 47 + print "Usage: search.php [verbose] user=username pass=password [output=simple|xml|csv] 'search criteria'\n";
48 exit; 48 exit;
49 } 49 }
50 } 50 }
51 } 51 }
52 52
  53 +
  54 +if ($verbose) print _kt('Command line search') . "...\n";
  55 +
  56 +if (empty($username))
  57 +{
  58 + die(_kt("Please specify a username!"));
  59 +}
  60 +
  61 +if (empty($expr))
  62 +{
  63 + die(_kt("Please specify search criteria!"));
  64 +}
  65 +
53 $ktapi = new KTAPI(); 66 $ktapi = new KTAPI();
54 $result = $ktapi->start_session($username, $password); 67 $result = $ktapi->start_session($username, $password);
55 if (PEAR::isError($result)) 68 if (PEAR::isError($result))
@@ -64,13 +77,34 @@ try @@ -64,13 +77,34 @@ try
64 77
65 $result = $expr->evaluate(); 78 $result = $expr->evaluate();
66 79
  80 + switch ($output)
  81 + {
  82 + case 'simple':
  83 + foreach($result as $item)
  84 + {
  85 + print 'Document ID: ' . $item->DocumentID . ' Title:' . $item->Title . ' Relevance:' . $item->Rank . "\n";
  86 + }
  87 + break;
  88 + case 'csv':
  89 + print "DocumentId,Title,Relevance\n";
  90 + foreach($result as $item)
  91 + {
  92 + print $item->DocumentID . ',' . $item->Title . ',' . $item->Rank . "\n";
  93 + }
  94 + break;
  95 + case 'xml':
  96 + print "<result>\n";
  97 + foreach($result as $item)
  98 + {
  99 + print "\t<item id=\"$item->DocumentID\" title=\"$item->Title\" relevance=\"$item->Rank\"/>\n";
  100 + }
  101 + print "</result>\n";
  102 + }
67 103
68 - foreach($result as $item)  
69 - {  
70 - print $item->DocumentID . ' ' . $item->Title . ' ' . $item->Rank . "\n";  
71 - }  
72 -  
73 - print _kt("Done.") . "\n"; 104 + if ($verbose)
  105 + {
  106 + print _kt("Done.") . "\n";
  107 + }
74 108
75 } 109 }
76 catch(Exception $e) 110 catch(Exception $e)