Skip to content
Permalink
Browse files

Working indexer! In theroy fully functional!

  • Loading branch information...
mikekasprzak committed Nov 21, 2017
1 parent 8f84561 commit d524bc6728025b41d752ec591715a31f4669ce17
Showing with 63 additions and 8 deletions.
  1. +37 −4 private-search/indexer.php
  2. +26 −4 src/shrub/src/core/db_sphinx.php
@@ -4,28 +4,58 @@
const SHRUB_PATH = "../src/shrub/src";
include_once __DIR__."/".CONFIG_PATH."/config.php";
require_once __DIR__."/".SHRUB_PATH."/core/cli.php"; // Confirm CLI
require_once __DIR__."/".SHRUB_PATH."/cron.php";
require_once __DIR__."/".SHRUB_PATH."/node/node.php";
require_once __DIR__."/".SHRUB_PATH."/core/db_sphinx.php";
// Usage
if ( count($argv) < 2 ) {
echo "\nUsage: ".$argv[0]." [nodes]\n";
echo "\n";
echo " [nodes] - How many nodes to index (e.g. 100)\n";
echo "\n";
die;
}
// Important variables
$last_modified = 0;
$count = 1000;
$count = intval($argv[1]);
// Confirm the requested number of nodes is valid
if ( $count <= 0 ) {
echo "Invalid number of nodes\n";
die;
}
// Figure out where we should start from (modified date as a timestamp)
$lm = searchDB_QueryFetch("
SELECT id, modified
FROM node_rt
ORDER BY modified DESC
LIMIT 1;
");
if ( count($lm) ) {
$last_modified = intval($lm[0]['modified']);
// var_dump($lm);
}
// Get nodes
$nodes = node_GetSearchIndexes($last_modified, $count);
$ids = array_keys($nodes);
// Add placeholders for author and tag metadata
foreach ( $nodes as &$node ) {
$node['authors'] = [];
$node['tags'] = [];
}
$tags = nodeMeta_GetByKeyNode('tag', $ids);
// Fetch Authors and Tags
$authors = nodeMeta_GetByKeyNode('author', $ids);
foreach ( $authors as &$author ) {
if ( isset($nodes[$author['a']]) )
$nodes[$author['a']]['authors'][] = $author['b'];
}
$tags = nodeMeta_GetByKeyNode('tag', $ids);
foreach ( $tags as &$tag ) {
if ( isset($nodes[$tag['a']]) )
$nodes[$tag['a']]['tags'][] = $author['b'];
@@ -36,12 +66,14 @@
//print_r($tags);
//print_r($authors);
// Workaround for a bug (might not be needed anymore)
_searchDB_Connect();
// Replace the data in the search database
foreach ( $nodes as &$node ) {
// db_Echo("
searchDB_Query("
INSERT INTO node_rt (
REPLACE INTO node_rt (
id,
parent,
superparent,
@@ -81,3 +113,4 @@
)"
);
}
@@ -74,6 +74,21 @@ function _searchDB_Close() {
}
}
function _searchDB_GetAssoc() {
global $SearchDB;
$result = mysqli_use_result($SearchDB);
// $result = $st->get_result();
// _db_DebugEndQuery($st, $result);
$ret = [];
while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
$ret[] = $row;
}
return $ret;
}
// See below. This is a modified version of DoubleEscape
function searchDB_Escape( $string ) {
return strtr($string, [
@@ -132,7 +147,7 @@ function searchDB_TimeStamp( $timestamp ) {
}
function _searchDB_Query( $query, $args ) {
function _searchDB_Query( $query /*, $args*/ ) {
_searchDB_Connect();
//_db_DebugStartQuery($query);
@@ -147,11 +162,18 @@ function _searchDB_Query( $query, $args ) {
return false;
}
function searchDB_Query( $query, ...$args ) {
$ret = _searchDB_Query($query, $args);
if ( $ret ) {
function searchDB_Query( $query /*, ...$args*/ ) {
if ( $ret = _searchDB_Query($query /*, $args*/) ) {
// _db_DebugEndQuery($ret, $null);
return $ret;
}
return false;
}
function searchDB_QueryFetch( $query /*, ...$args*/ ) {
if ( _searchDB_Query($query /*, $args*/) ) {
// _db_DebugEndQuery($ret, $null);
return _searchDB_GetAssoc();
}
return false;
}

0 comments on commit d524bc6

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.