Commit cf777b6871ee6e23ab3e3f97acd6bbf3516478cc

Authored by conradverm
1 parent 858b57d0

KTS-673

"The search algorithm needs some work"
Added. Primitive simple command line search.

Committed By: Conrad Vermeulen
Reviewed By: Kevin Fourie

git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@7296 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing 1 changed file with 81 additions and 0 deletions
search2/search/bin/search.php 0 → 100755
  1 +<?php
  2 +
  3 +require_once(realpath('../../../config/dmsDefaults.php'));
  4 +require_once(KT_DIR . '/ktapi/ktapi.inc.php');
  5 +
  6 +$username = '';
  7 +$password = '';
  8 +$expr = '';
  9 +
  10 +print _kt('Command line search') . "...\n";
  11 +
  12 +$output = 'simple';
  13 +$verbose = false;
  14 +if ($argc > 0)
  15 +{
  16 + foreach($argv as $arg)
  17 + {
  18 + if (strpos($arg, '=') === false)
  19 + {
  20 + $expr = $arg;
  21 + continue;
  22 + }
  23 + list($param, $value) = explode('=', $arg);
  24 +
  25 + switch (strtolower($param))
  26 + {
  27 + case 'verbose':
  28 + $verbose=true;
  29 + break;
  30 + case 'output':
  31 + switch(strtolower($value))
  32 + {
  33 + case 'xml': $output = 'simple'; break;
  34 + case 'csv': $output = 'csv'; break;
  35 + default:
  36 + $output = 'simple';
  37 + }
  38 + case 'user':
  39 + $username = $value;
  40 + print "* User = $value\n";
  41 + break;
  42 + case 'pass':
  43 + $password = $value;
  44 + print "* User = $value\n";
  45 + break;
  46 + case 'help':
  47 + print "Usage: search.php [verbose] user=username pass=password [output=simple|xml|csv] 'expression'\n";
  48 + exit;
  49 + }
  50 + }
  51 +}
  52 +
  53 +$ktapi = new KTAPI();
  54 +$result = $ktapi->start_session($username, $password);
  55 +if (PEAR::isError($result))
  56 +{
  57 + print _kt("Cannot locate user:") . " $username\n";
  58 + exit;
  59 +}
  60 +
  61 +try
  62 +{
  63 + $expr = parseExpression($expr);
  64 +
  65 + $result = $expr->evaluate();
  66 +
  67 +
  68 + foreach($result as $item)
  69 + {
  70 + print $item->DocumentID . ' ' . $item->Title . ' ' . $item->Rank . "\n";
  71 + }
  72 +
  73 + print _kt("Done.") . "\n";
  74 +
  75 +}
  76 +catch(Exception $e)
  77 +{
  78 + print $e->getMessage();
  79 +}
  80 +
  81 +?>
0 82 \ No newline at end of file
... ...