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 __construct()
 {
     $this->pdo = Env::getPDO();
     // Create the table if it does not exist
     try {
         $statement = $this->pdo->prepare("CREATE TABLE documents (id INT NOT NULL UNIQUE, title VARBINARY (255) NOT NULL, content VARBINARY (2048) NOT NULL);");
         $statement->execute();
     } catch (\Exception $e) {
         // Do nothing!
     }
     $tokenizer = new Tokenizer\PorterTokenizer();
     $this->index = new Index\MemcachedDocumentIndex(Env::get('MEMCACHED_HOST'), Env::get('MEMCACHED_PORT'));
     $this->store = new Store\SQLDocumentStore($this->pdo, $tokenizer);
 }
Example #3
0
 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 __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'));
 }