Login   Register  
PHP Classes
elePHPant
Icontem

File: example/learn.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Cesar D. Rodas  >  Autocomplete  >  example/learn.php  >  Download  
File: example/learn.php
Role: Example script
Content type: text/plain
Description: First commit
Class: Autocomplete
Suggest words to complete search using edge n-gram
Author: By
Last change:
Date: 1 year ago
Size: 770 bytes
 

Contents

Class file image Download
<?php

require __DIR__ "/../vendor/autoload.php";

use 
crodas\Autocomplete\Autocomplete;
use 
crodas\Autocomplete\PDOConn;

$file __DIR__ '/data.db';

if (!
is_file($file)) {
    
$install true;
}

// create PDO connection
$pdo = new PDO("sqlite:$file");
// Create transaction, speed up things
$pdo->beginTransaction();
    

// create Autocomplete DBInterface
$conn = new PDOConn($pdo);

// Create suggest object
$suggest = new Autocomplete($conn);

if (!empty(
$install)) {
    
$conn->install();
}

$suggest->index("PHP"999);
$suggest->index("Python"93);
$suggest->index("Perl"83);
$suggest->index("Ruby"74);
$suggest->index("PHP Programming "600);
$suggest->index("Python Programming "500);
$suggest->index("Perl Programming "400);

$pdo->commit();