public function setUp() { $this->engine = new Engine(); $this->engine->clear(); $this->data = json_decode(file_get_contents(Env::get('TEST_DATASET_PATH')))->data; foreach ($this->data as $article) { $this->engine->addDocument(new Document($article->title, $article->content, '')); } }
function setup() { global $index; global $engine; global $store; $tokenizer = new PorterTokenizer(); $store = new SQLDocumentStore(Env::getPDO(), $tokenizer); //$store = new MongoDBDocumentStore(ENV::get('MONGO_HOST'), ENV::get('MONGO_PORT')); $index = new MemcachedDocumentIndex(ENV::get('MEMCACHED_HOST'), ENV::get('MEMCACHED_PORT')); $ranker = new TFIDFDocumentRanker(); $config = Config::createBuilder()->index($index)->store($store)->tokenizer($tokenizer)->ranker($ranker)->build(); $engine = new Engine($config); }
public function testFindKeywords() { $engine = new Engine(Config::createBuilder()->testConfig()->build()); $dataset = json_decode(file_get_contents(Env::get('TEST_DATASET_PATH'))); foreach ($dataset->data as $article) { $engine->addDocument(new Document($article->title, $article->content)); } $results = $engine->findKeywords('In computer engineering, computer architecture is the conceptual design and fundamental operational structure of a computer system.'); $this->assertEquals('computer', $results[0]['keyword']); $this->assertEquals(count($dataset->data), $engine->size()); $engine->clear('index'); $this->assertNotEquals(0, $engine->size()); $engine->clear('store'); $this->assertEquals(0, $engine->size()); }
function testAddDocument() { $this->store->clear(); $tokenizer = new Tokenizer\PorterTokenizer(); $document = new Document('test', 'this is a test document'); $document->id = 1; $document->tokens = $tokenizer->tokenize($document->content); $this->store->addDocument($document); $this->assertEquals(1, $this->store->size()); $d = $this->store->getDocument(1); $this->assertEquals($document, $d); if (Env::isSQLite()) { $this->setExpectedException('Exception', "UNIQUE constraint failed"); } else { $this->setExpectedException('Exception', "Duplicate entry '1' for key 'id'"); } $this->store->addDocument($document); $this->store->clear(); $this->assertEquals(0, $this->store->size()); }
function __construct() { $this->index = new Index\MemcachedDocumentIndex(Env::get('MEMCACHED_HOST'), Env::get('MEMCACHED_PORT')); $this->store = new Store\MongoDBDocumentStore(Env::get('MONGO_HOST'), Env::get('MONGO_PORT')); }
function init() { $this->index = new Index\MongoDBDocumentIndex(Env::get('MONGO_HOST'), Env::get('MONGO_PORT')); $this->store = new Store\MongoDBDocumentStore(Env::get('MONGO_HOST'), Env::get('MONGO_PORT')); }
<?php use Search\Config\Env; require "setup.php"; // Create the table if it does not exist try { $pdo = Env::getPDO(); $query = "CREATE TABLE documents (id int NOT NULL UNIQUE, title VARBINARY (255) NOT NULL, content VARBINARY (2048) NOT NULL);"; $statement = $pdo->prepare($query); $statement->execute(); } catch (\Exception $e) { // Do nothing! } global $index; global $engine; global $store; setup(); // If index is empty, add test data set. if ($index->size() === 0) { $index = $store->buildIndex($index); } if ($engine->size() === 0) { $file = '../../tests/Wikipedia_sample_dataset.json'; $data = json_decode(file_get_contents($file))->data; foreach ($data as $article) { $engine->addDocument(new Search\Document($article->title, $article->content, '')); } echo json_encode(true); } else { echo json_encode(false); }