Commit 9f8fcef94b083179ecc31dc8e2e2141d6347536e
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 | $password = ''; |
| 8 | 8 | $expr = ''; |
| 9 | 9 | |
| 10 | -print _kt('Command line search') . "...\n"; | |
| 11 | 10 | |
| 12 | 11 | $output = 'simple'; |
| 13 | 12 | $verbose = false; |
| ... | ... | @@ -30,26 +29,40 @@ if ($argc > 0) |
| 30 | 29 | case 'output': |
| 31 | 30 | switch(strtolower($value)) |
| 32 | 31 | { |
| 33 | - case 'xml': $output = 'simple'; break; | |
| 32 | + case 'xml': $output = 'xml'; break; | |
| 34 | 33 | case 'csv': $output = 'csv'; break; |
| 35 | 34 | default: |
| 36 | 35 | $output = 'simple'; |
| 37 | 36 | } |
| 37 | + break; | |
| 38 | 38 | case 'user': |
| 39 | 39 | $username = $value; |
| 40 | - print "* User = $value\n"; | |
| 40 | + if ($verbose) print "* User = $value\n"; | |
| 41 | 41 | break; |
| 42 | 42 | case 'pass': |
| 43 | 43 | $password = $value; |
| 44 | - print "* User = $value\n"; | |
| 44 | + if ($verbose) print "* User = $value\n"; | |
| 45 | 45 | break; |
| 46 | 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 | 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 | 66 | $ktapi = new KTAPI(); |
| 54 | 67 | $result = $ktapi->start_session($username, $password); |
| 55 | 68 | if (PEAR::isError($result)) |
| ... | ... | @@ -64,13 +77,34 @@ try |
| 64 | 77 | |
| 65 | 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 | 110 | catch(Exception $e) | ... | ... |