Warning: chmod(): Operation not permitted in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8 [0] in function chmod in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8 [1] in function include_once in /var/www/hopeinstoughton_www/wp-settings.php on line 560 [2] in function require_once in /var/www/hopeinstoughton_www/wp-config.php on line 85 [3] in function require_once in /var/www/hopeinstoughton_www/wp-load.php on line 50 [4] in function require_once in /var/www/hopeinstoughton_www/wp-blog-header.php on line 13 [5] in function require in /var/www/hopeinstoughton_www/index.php on line 17
| Server IP : 94.177.8.99 / Your IP : 216.73.217.165 Web Server : Apache/2.4.58 (Ubuntu) System : Linux aries 6.8.0-134-generic #134-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 26 18:43:11 UTC 2026 x86_64 User : www-data ( 33) PHP Version : 8.1.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/hopeinstoughton_www/wp-content/plugins/xapian-search/lib/ |
Upload File : |
<?php
require_once __DIR__ . '/xapian.php';
//require_once __DIR__ . '/elasticsearch.php';
require_once realpath(__DIR__ . '/../../media-manager/cdn/include/vtt_class.php');
// uses remove_accents($string) from wordpress
class class_xap {
private $doctype;
private $docid;
private $content;
private $dbfilename;
private $db;
private $termgenerator = NULL;
public function DocumentType() {
if (func_num_args()) {
$this->doctype = func_get_arg(0);
return $this;
}
return $this->doctype;
}
public function DocumentId() {
if (func_num_args()) {
$this->docid = func_get_arg(0);
return $this;
}
return $this->docid;
}
public function FilenameDocument() {
if (func_num_args()) {
$filename = func_get_arg(0);
$this->content = file_get_contents($filename);
return $this;
}
return NULL;
}
public function Content() {
if (func_num_args()) {
$this->content = func_get_arg(0);
return $this;
}
return $this->content;
}
public function FilenameDatabase() {
if (func_num_args()) {
$this->dbfilename = func_get_arg(0);
return $this;
}
return $this->dbfilename;
}
// only one process can open it read/write
public function Open($readonly = TRUE) {
if (SEARCH == 'elastic') {
$this->db = new \MyElastic;
} elseif ($readonly) {
$this->db = new XapianDatabase($this->dbfilename);
} else {
$this->db = new XapianWritableDatabase($this->dbfilename, Xapian::DB_CREATE_OR_OPEN);
}
}
public function Close() {
if (isset($this->db)) {
$this->termgenerator = NULL;
}
$this->db = NULL;
return $this;
}
private function _SearchXapian($queryString) {
$enquire = new XapianEnquire($this->db);
$qp = new XapianQueryParser();
$qp->set_stemmer(new XapianStem('en'));
$qp->set_database($this->db);
$qp->set_stemming_strategy(XapianQueryParser::STEM_SOME);
$query = $qp->parse_query($queryString, XapianQueryParser::FLAG_DEFAULT | XapianQueryParser::FLAG_PARTIAL);
$enquire->set_query($query);
$matches = $enquire->get_mset(0, 300);
$res = [];
$c = $matches->size();
for($i = 0; $i < $c; $i++) {
$doc = $matches->get_document($i);
// $docid = $matches->get_docid($i);
$pct = $matches->get_document_percentage($i);
$data = json_decode($doc->get_data(), TRUE);
$snipped = $matches->snippet(join(' ', $data['body']), 220); // , NULL, XapianMSet::SNIPPET_BACKGROUND_MODEL or XapianMSet::SNIPPET_EXHAUSTIVE
$node = [
'doctype' => $data['doctype'],
'docid' => $data['docid'],
// 'id' => $docid, // don't need to know the xapian document number
'snip' => $snipped,
'pct' => $pct,
'offset' => $this->_determineSnippetOffset($data, $snipped),
];
$res[] = $node;
}
return $res;
}
public function Search($queryString) {
if (SEARCH == 'elastic') {
return $this->db->DocumentSearch($queryString);
} else {
$queryString = remove_accents($queryString);
return $this->_SearchXapian($queryString);
}
}
private function _determineSnippetOffset($data, $snipped) {
$snipped = str_replace(['...', '<b>', '</b>'], '', $snipped);
$source = join(' ', $data['body']);
if ($snipped == '') return '0:00';
$ps = strpos($source, $snipped);
if ($ps === FALSE) return '0:00';
$offset = 0;
foreach($data['body'] as $index => $line) {
$l = strlen($line) + 1;
if ($ps >= $offset && $ps < $offset + $l) {
return $data['timing'][$index];
}
$offset += $l;
}
return '0:00';
}
// load vtt, strip out times and sequence numbers
public function Reindex() {
$vtt = new vtt_class();
$content = $this->Content();
$vtt->Content($content);
$vttdata = $vtt->getEntries();
if (!count($vttdata)) return; // no transcript available
[$output, $times] = $vtt->AsReindex();
if (SEARCH == 'elastic') {
$this->db->DocumentStore($this->DocumentId(), explode("\t", $output), $times);
} else {
if (is_null($this->termgenerator)) {
$this->termgenerator = new XapianTermGenerator();
$this->termgenerator->set_stemmer(new XapianStem('en'));
}
// Add to the database
$doc = new XapianDocument();
$this->termgenerator->set_document($doc);
$safe_text = remove_accents($output);
$this->termgenerator->index_text($safe_text);
$doc->add_boolean_term('T' . $this->DocumentType());
$doc->add_boolean_term('I' . $this->DocumentId());
// store all the fields for display purposes
$payload = [
'doctype' => $this->DocumentType(),
'docid' => $this->DocumentId(),
'modified' => 0,
'timing' => $times,
'body' => explode("\t", $output),
];
$doc->set_data(json_encode($payload));
// we use the identifier to ensure each object ends up
// in the database only once no matter how many times
// we run the indexer
$idterm = 'Q' . $this->DocumentId();
$doc->add_term($idterm);
$this->db->replace_document($idterm, $doc);
}
return $this;
}
public function Remove() {
$idterm = 'Q' . $this->DocumentId();
$this->db->delete_document($idterm);
return $this;
}
}