TeamTNT\TNTSearch\Indexer\TNTIndexer::createIndex PHP Method

createIndex() public method

public createIndex ( $indexName )
    public function createIndex($indexName)
    {
        $this->indexName = $indexName;
        if (file_exists($this->config['storage'] . $indexName)) {
            unlink($this->config['storage'] . $indexName);
        }
        $this->index = new PDO('sqlite:' . $this->config['storage'] . $indexName);
        $this->index->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $this->index->exec("CREATE TABLE IF NOT EXISTS wordlist (\n                    id INTEGER PRIMARY KEY,\n                    term TEXT UNIQUE COLLATE nocase,\n                    num_hits INTEGER,\n                    num_docs INTEGER)");
        $this->index->exec("CREATE UNIQUE INDEX 'main'.'index' ON wordlist ('term');");
        $this->index->exec("CREATE TABLE IF NOT EXISTS doclist (\n                    term_id INTEGER,\n                    doc_id INTEGER,\n                    hit_count INTEGER)");
        $this->index->exec("CREATE TABLE IF NOT EXISTS fields (\n                    id INTEGER PRIMARY KEY,\n                    name TEXT)");
        $this->index->exec("CREATE TABLE IF NOT EXISTS hitlist (\n                    term_id INTEGER,\n                    doc_id INTEGER,\n                    field_id INTEGER,\n                    position INTEGER,\n                    hit_count INTEGER)");
        $this->index->exec("CREATE TABLE IF NOT EXISTS info (\n                    key TEXT,\n                    value INTEGER)");
        $this->index->exec("INSERT INTO info ( 'key', 'value') values ( 'total_documents', 0)");
        $this->index->exec("CREATE INDEX IF NOT EXISTS 'main'.'term_id_index' ON doclist ('term_id' COLLATE BINARY);");
        $connector = $this->createConnector($this->config);
        if (!$this->dbh) {
            $this->dbh = $connector->connect($this->config);
        }
        return $this;
    }

Usage Example

Ejemplo n.º 1
0
 public function createIndex($indexName)
 {
     $indexer = new TNTIndexer();
     $indexer->loadConfig($this->config);
     if ($this->dbh) {
         $indexer->setDatabaseHandle($this->dbh);
     }
     return $indexer->createIndex($indexName);
 }