<?php
/*
example usage of class: PHP_SuperEzSearch
This class is a simple search engine that uses sequence matching of two character sequences to match documents and documents to phrases.
It allows for negative queries to be used to exclude documents from the search results.
Negative prompt works meh, but it works a bit for the most part.
*/
require_once('class.phpsuperezsearch.php');
ob_start();
session_start();
// Usage example
$ez = new PHP_SuperEzSearch();
$ez->addDocument('a', "This is a sample document.");
$ez->addDocument('b', "Another document in the database.");
$ez->addDocument('c', "Yet another sample document with different content.");
$ez->addDocument(1, 'The quick yellow fox jumps over the lazy dog');
$ez->addDocument(2, 'The quick brown dog jumps over the lazy fox');
$ez->addDocument(3, 'The sleeping dog is a walrus and is friends with the blue fox.');
$ez->addDocument(4, 'A quick brown fox and a quick brown dog are friends');
$ez->addDocument('/folder/folder/filename.txt', "I like chicken on my potato salad, said the dog.");
$ez->addDocument('/folder/x.nfo', "a title of a story somewhere about the fox and the hen.");
// Index multiple documents at once
$documentArray = [
'5' => 'The quick brown goat is faster than the lazy dog',
'6' => 'The sleepy brown dog is slower than the quick blue zebra',
];
$ez->indexDocuments($documentArray);
echo "testing search...\r\n<br />";
// test no match
print("You search for 'aardvark' and we found the following results:\n<br />");
$results = $ez->search("arrdvark");
print_r($results);
// test some matches
$q = "The green dog is slower than the quick brown goat";
print("You search for [$q] and we found the following results:\n<br />");
$results = $ez->search($q);
print_r($results);
$q = "is a";
print("You search for [$q] and we found the following results:\n<br />");
$results = $ez->search($q);
print_r($results);
// test negative queries
echo "testing negative queries...\r\n<br />";
$q = "document";
print("You search for [$q] and we found the following results:\n<br />");
$results = $ez->search($q);
print_r($results);
$neg_q = "con";
print("You search for [$q] and negative query [".print_r($neg_q,1)."] and we found the following results:\n<br />");
$results = $ez->search($q, 5, $neg_q);
print_r($results);
$q = "dog";
print("You search for [$q] and we found the following results:\n<br />");
$results = $ez->search($q);
print_r($results);
$neg_q = "fox";
print("You search for [$q] and negative query [".print_r($neg_q,1)."] and we found the following results:\n<br />");
$results = $ez->search($q, 5, $neg_q);
echo "-=-=-=\r\n<br />";
print_r($results);
// test return related documents
$results = $ez->returnRelatedDocuments('a', 15);
echo "\r\n<br />-= returning related items for document id 'a' -=-=\r\n<br />";
print_r($results);
echo "\r\n<br />-=-=-=\r\n<br />";
// example remove some documents
$ez->removeDocument('a');
$ez->removeDocument(4);
echo "Now testing save/load...\r\n<br />";
// save to session //
// $ez->save_to_session('db');
// $ez2 = new PHP_SuperEzSearch();
// $ez2->load_from_session('db');
// print_r($ez2->documentVectors);
// save binary
// $ez->save('db.bin');
// $ez3 = new PHP_SuperEzSearch();
// $ez3->load('db.bin');
// print_r($ez3->documentVectors);
// save compressed
$ez->save_compressed('db.gz');
$ez4 = new PHP_SuperEzSearch();
$ez4->load_compressed('db.gz');
print_r($ez4->documentVectors);
// print_r($ez->documentVectors);
?>
|