<?php require "strus.php"; $config = "path=storage; metadata=doclen UINT16"; $ctx = new StrusContext(); try { $ctx->destroyStorage($config); # ... delete the storage files if they already exists } catch (Exception $e) { } # Create a new storage: $ctx->createStorage($config); # Get a client for the new created storage: $storage = $ctx->createStorageClient($config); # Define the document analyzer to use: $analyzer = $ctx->createDocumentAnalyzer(); # Define the features and attributes to store: $analyzer->defineAttribute("title", "/doc/title()", "content", "orig"); $analyzer->addSearchIndexFeature("word", "/doc/text()", "word", array(array("stem", "en"), "lc", array("convdia", "en")), ""); $analyzer->addForwardIndexFeature("orig", "/doc/text()", "split", "orig", ""); # Read input files, analyze and insert them: $datadir = "./data/"; $datafiles = scandir($datadir); $transaction = $storage->createTransaction(); foreach ($datafiles as &$datafile) { if ($datafile[0] != '.') { print "process document " . $datafile . "\n"; $docid = substr($datafile, 0, strlen($datafile) - 4); $fullname = $datadir . $datafile; $doc = $analyzer->analyze(file_get_contents($fullname)); $transaction->insertDocument($docid, $doc);
<!DOCTYPE html> <html> <body> <?php require "strus.php"; try { $context = new StrusContext("localhost:7181"); $storage = $context->createStorageClient(""); echo '<p>'; echo "Number of documents inserted: " . $storage->nofDocumentsInserted() . "!"; echo '</p>'; } catch (Exception $e) { echo '<p><font color="red">Caught exception: ' . "{$e->getMessage}()</font></p>"; } ?> </body> </html>
$restrictdoc = NULL; parse_str(getenv('QUERY_STRING'), $_GET); $queryString = $_GET['q']; if (array_key_exists('n', $_GET)) { $nofRanks = intval($_GET['n']); } if (array_key_exists('i', $_GET)) { $minRank = intval($_GET['i']); } if (array_key_exists('s', $_GET)) { $scheme = $_GET['s']; } if (array_key_exists('d', $_GET)) { $restrictdoc = intval($_GET['d']); } $context = new StrusContext("localhost:7181"); $storage = $context->createStorageClient(""); $BM25_checked = ""; $BM25pff_checked = ""; $NBLNK_checked = ""; if (!$scheme || $scheme == 'BM25') { $BM25_checked = "checked"; } else { if ($scheme == 'BM25pff') { $BM25pff_checked = "checked"; } else { if ($scheme == 'NBLNK') { $NBLNK_checked = "checked"; } } }
<?php require "strus.php"; $queryphrase = "city"; $config = "path=storage"; $ctx = new StrusContext(); try { # Get a client for the storage: $storage = $ctx->createStorageClient($config); # Define the query analyzer to use: $analyzer = $ctx->createQueryAnalyzer(); $analyzer->addSearchIndexElement("word", "word", "word", array(array("stem", "en"), "lc", array("convdia", "en"))); # Define the query evaluation scheme: $queryeval = $ctx->createQueryEval(); # Here we define what query features decide, what is ranked for the result: $queryeval->addSelectionFeature("select"); # Here we define how we rank a document selected. We use the 'BM25' weighting scheme: $queryeval->addWeightingFunction("BM25", array("k1" => 0.75, "b" => 2.1, "avgdoclen" => 1000, ".match" => "seek")); # Now we define what attributes of the documents are returned and how they are build. # The functions that extract stuff from documents for presentation are called summarizers. # First we add a summarizer that extracts us the title of the document: $queryeval->addSummarizer("attribute", array("name" => "title")); # Then we add a summarizer that collects the sections that enclose the best matches # in a ranked document: $queryeval->addSummarizer("matchphrase", array("type" => "orig", "sentencesize" => 40, "windowsize" => 60, ".match" => "seek")); # Now we build the query to issue: $query = $queryeval->createQuery($storage); # First we analyze the query phrase to get the terms to find in the form as they are stored in the storage: $terms = $analyzer->analyzeField("word", $queryphrase); if (count($terms) == 0) { throw new Exception("query is empty");
<?php require "strus.php"; $ctx = new StrusContext(); $config = "path=storage; metadata=doclen UINT16"; $storage = $ctx->createStorageClient($config); # Query the number of documents inserted: $nofDocuments = $storage->nofDocumentsInserted(); # Output: print "Number of documents inserted: {$nofDocuments}\n"; ?>