PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Richard Carson   Ssearch   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Ssearch
Search and rank text results in an array
Author: By
Last change: Merge branch 'master' of gitlab.richardcarson.ca:rscarson/libphonetiq
Date: 10 years ago
Size: 842 bytes
 

Contents

Class file image Download
<?php
   
include("libphonetiq.class.php");
   
   
#Search query
   
$query = "firewall training";
   
   
#Set of data
   
$data = array(
       
'McAfee training'=>array(
           
'Course Name'=>'McAfee Training Course V1',
           
'Product'=>'McAfee Antivirus'
       
),

       
'Sponge class'=>array(
           
'Course Name'=>'Sponges 101',
           
'Product'=>'Mayonaise'
       
),

       
'Train spotting'=>array(
           
'Course Name'=>'Spotting trains for dummies',
           
'Product'=>'Trains'
       
)
    );

   
$engine = new PhonetiQ();
   
$start = microtime(true);
    print
"Searching in dataset for '$query'... <br/>";
   
$engine->begin($query);
    foreach (
$data as $key=>$row)
    {
       
$score = $engine->next($row);
        if (
$score === false)
            print
"&nbsp; $key - Not in results <br/>";
        else
            print
"&nbsp; $key - $score <br/>";
    }
    print
"Finished in " . (microtime(true) - $start);
?>