Beispiel #1
0
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);
}
 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);
 }
Beispiel #3
0
<?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);
}