search
[ class tree: search ] [ index: search ] [ all elements ]

Source for file cmd_line_reindex.php

Documentation is available at cmd_line_reindex.php

  1. <?php
  2. /**
  3.  * Command Line Site Reindex
  4.  * Created with stub from jht001 and help from KainX (Thanks to you both)
  5.  * 
  6.  * This script is designed to be called from the command line to allow you
  7.  * to reindex all the liberty content on your site.
  8.  * 
  9.  * cmd_line_reindex takes up to three optional arguments
  10.  * Argument 1 - ContentType
  11.  *         This is the type of content you wish to reindex using the content type guids
  12.  *         "pages" will attempt to reindex all content
  13.  *             Content Type Guids allowed (so far):
  14.  *             bitarticle, bitblogpost, bitcomment, bitpage, bituser, fisheyegallery, fisheyeimage
  15.  * 
  16.  * Argument 2 - Silent
  17.  *         Silent = no messages displayed to the console
  18.  * 
  19.  * Argument 3 - UnindexedOnly
  20.  *         UnindexedOnly = Only index content that isn't already in the index. This function
  21.  *             is useful for sites that import data from other sites.
  22.  *             Note: This function employs sub-selects in the SQL. This will break
  23.  *                   MySQL 3.x - however works fine on MySQL 4.x, Postgres, Firebird and MSSQL.
  24.  * 
  25.  * Examples:
  26.  * 
  27.  *        php cmd_line_reindex            // reindexes all content on your site with messages
  28.  *        php cmd_line_reindex pages silent unindexedonly // Indexes entire site, no messages - and only content not in the index yet
  29.  *        php cmd_line_reindex bitarticle unindexedonly // Indexes only articles that haven't been indexed yet
  30.  *
  31.  * I have run the "unindexedonly" option several times in a row and was told it attempted to
  32.  * reindex 20 pieces of content each time.
  33.  *
  34.  * @package search
  35.  */
  36.  
  37. /**
  38.  * Define Server Variables so script won't puke on command line
  39.  */ 
  40. $_SERVER['SERVER_NAME']     'batch';
  41. $_SERVER['HTTP_HOST']       'batch';
  42. $_SERVER['HTTP_USER_AGENT''batch';
  43. $_SERVER['SCRIPT_URL']      'batch';
  44. $_SERVER['SERVER_SOFTWARE''batch';
  45. $HTTP_SERVER_VARS['HTTP_USER_AGENT''batch';
  46.  
  47. require_once'../kernel/setup_inc.php' );
  48. require_onceLIBERTY_PKG_PATH.'LibertyBase.php');
  49. require_onceSEARCH_PKG_PATH.'refresh_functions.php');
  50.  
  51. $whatToIndex   "pages";
  52. $unindexedOnly false;
  53. $silent        false;
  54. if (isset($argc)) {  // we are running from the command line.
  55.     if ($argc 1{
  56.         for ($i 1$i $argc$i++{
  57.             $arg strtolower($argv[$i]);
  58.             switch ($arg{
  59.                 case "silent" :
  60.                     $silent true;
  61.                     break;
  62.                 case "unindexedonly" :
  63.                     $unindexedOnly true// only index content that hasn't been indexed yet
  64.                     break;
  65.                 default :
  66.                     $whatToIndex $arg;
  67.                     break;
  68.             }
  69.         }
  70.         $time_start microtime_float();
  71.         if (!$silentecho "\nBeginning Reindex of $whatToIndex ...\n";
  72.         if (!$silent && $unindexedOnlyecho "Warning: unindexed only flag set. Will break MySQL 3.x because of sub-selects\n";
  73.         $count    rebuild_index($whatToIndex$unindexedOnly);
  74.         $time_end microtime_float();
  75.         $time     number_format($time_end $time_start4);
  76.         if (!$silentecho "Index rebuild complete.\n";
  77.         if (!$silentecho "Attempted to index $count pieces of content\n";
  78.         if (!$silentecho "(Note: Some content may not be indexable. This is normal)\n";
  79.         if (!$silentecho "Execution time: $time seconds\n";
  80.         die();
  81.     }
  82. else {
  83.         // Don't allow this to be run from the web.
  84.         header("location: ../index.php" );
  85. }
  86.  
  87. function microtime_float({
  88.    list($usec$secexplode(" "microtime());
  89.    return ((float)$usec + (float)$sec);
  90. }
  91. ?>

Documentation generated on Wed, 29 Jul 2015 13:56:14 +0000 by phpDocumentor 1.5.0-lsces