Source for file search-utility-defs.php

Documentation is available at search-utility-defs.php

  1. <?php
  2. /* ******************************************************************** */
  3. /* CATALYST PHP Source Code */
  4. /* -------------------------------------------------------------------- */
  5. /* This program is free software; you can redistribute it and/or modify */
  6. /* it under the terms of the GNU General Public License as published by */
  7. /* the Free Software Foundation; either version 2 of the License, or */
  8. /* (at your option) any later version. */
  9. /* */
  10. /* This program is distributed in the hope that it will be useful, */
  11. /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
  12. /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
  13. /* GNU General Public License for more details. */
  14. /* */
  15. /* You should have received a copy of the GNU General Public License */
  16. /* along with this program; if not, write to: */
  17. /* The Free Software Foundation, Inc., 59 Temple Place, Suite 330, */
  18. /* Boston, MA 02111-1307 USA */
  19. /* -------------------------------------------------------------------- */
  20. /* */
  21. /* Filename: search-utility-defs.php */
  22. /* Author: Paul Waite */
  23. /* Description: Definitions for interfacing to a search engine to */
  24. /* perform various "utility" operations. */
  25. /* The parent module which includes this module must also */
  26. /* include the underlying defs module for the search */
  27. /* engine itself, eg: lucene, solr etc. */
  28. /* */
  29. /* ******************************************************************** */
  30. /** @package search *//**
  31. * The lucene purge message class. This class allows you to remove all
  32. * items from the SearchEngine index. Take care!
  33. * @package search
  34. */
  35. class searchengine_purger extends searchengine_purgemsg {
  36. // .....................................................................
  37. /** Constructor
  38. * Make a new SearchEngine index purger. This message is provided to allow
  39. * you to delete all items from the SearchEngine index.
  40. * @param string $application Optional application specifier
  41. * @param string $host Hostname or IP of SearchEngine server
  42. * @param string $port Port of SearchEngine server
  43. */
  44. function searchengine_purger($application="?", $host="", $port="") {
  45. $this->searchengine_purgemsg($application, $host, $port);
  46. } // searchengine_purger
  47. // .....................................................................
  48. /**
  49. * Make SearchEngine purge the index.
  50. * @param integer $timeoutsecs Override for timeout in seconds
  51. * @return boolean True if command was successful.
  52. */
  53. function execute($timeoutsecs="") {
  54. return $this->send($timeoutsecs);
  55. } // execute
  56.  
  57. } // searchengine_purger class
  58. // ----------------------------------------------------------------------
  59.  
  60. /**
  61. * The SearchEngine utility message class. Used for special SearchEngine
  62. * operations.
  63. * @package search
  64. */
  65. class searchengine_utilitycmd extends searchengine_utilitymsg {
  66. /** Constructor
  67. * @param string $utilitycmd Command for this utility message.
  68. * @param string $application Optional application specifier
  69. * @param string $host Hostname or IP of SearchEngine server
  70. * @param string $port Port of SearchEngine server
  71. */
  72. function searchengine_utilitycmd($utilitycmd="", $application="?", $host="", $port="") {
  73. $this->searchengine_utilitymsg($utilitycmd, $application, $host, $port);
  74. } // searchengine_utilitycmd
  75. // .....................................................................
  76. /**
  77. * Make SearchEngine execute the given utility command.
  78. * @param integer $timeoutsecs Override for timeout in seconds
  79. * @return boolean True if command was successful.
  80. */
  81. function execute($timeoutsecs="") {
  82. return $this->send($timeoutsecs);
  83. } // execute
  84.  
  85. } // searchengine_utilitycmd class
  86. // ----------------------------------------------------------------------
  87.  
  88. /**
  89. * Function to optimize the SearchEngine index. This would commonly
  90. * be used after a batch of items have been indexed.
  91. * @param string $application Application name/domain name for searching in
  92. * @param string $host Hostname or IP of SearchEngine server
  93. * @param string $port Port of SearchEngine server
  94. * @return boolean True if the operation was successful.
  95. */
  96. function searchengine_optimize($application="?", $host="", $port="") {
  97. $optimizer = new searchengine_utilitycmd("OPTIMIZE", $application, $host, $port);
  98. $optimizer->execute(SOCK_FOREVER);
  99. return $optimizer->response->valid;
  100. } // searchengine_optimize
  101. // ----------------------------------------------------------------------
  102.  
  103. /**
  104. * Function to make a backup of the SearchEngine index. This would commonly
  105. * be used after a batch of items have been successfully optimized (which
  106. * indicates a sound index).
  107. * @param string $application Application name/domain name for searching in
  108. * @param string $host Hostname or IP of SearchEngine server
  109. * @param string $port Port of SearchEngine server
  110. * @return boolean True if the operation was successful.
  111. */
  112. function searchengine_backup($application="?", $host="", $port="") {
  113. $backup = new searchengine_utilitycmd("BACKUP", $application, $host, $port);
  114. $backup->execute(SOCK_FOREVER);
  115. return $backup->response->valid;
  116. } // searchengine_backup
  117. // ----------------------------------------------------------------------
  118.  
  119. /**
  120. * Function to purge the SearchEngine index of all indexes to documents. Yes,
  121. * I'll repeat that - it DELETES ALL DOCUMENTS FROM THE INDEX, permanently,
  122. * finito, shazam, ba-boom, as in "Omigod did I *really* mean to do that!?".
  123. * I guess I don't have to warn you to be careful with this, do I?
  124. * @param string $application Application name/domain name for searching in
  125. * @param string $host Hostname or IP of SearchEngine server
  126. * @param string $port Port of SearchEngine server
  127. * @return boolean True if the purging operation was successful.
  128. */
  129. function searchengine_purge($application="?", $host="", $port="") {
  130. $purgative = new searchengine_purger($application, $host, $port);
  131. $purgative->execute(SOCK_FOREVER);
  132. return $purgative->response->valid;
  133. } // searchengine_purge
  134. // ----------------------------------------------------------------------
  135.  
  136. /**
  137. * Function to check the SearchEngine index for 'health'. This determines
  138. * that the search engine server is alive, and can access the number of
  139. * documents in its index (which is what it goes and does).
  140. * @param string $application Application name/domain name for searching in
  141. * @param string $host Hostname or IP of SearchEngine server
  142. * @param string $port Port of SearchEngine server
  143. * @return boolean True if the index is healthy.
  144. */
  145. function searchengine_healthcheck($application="?", $host="", $port="") {
  146. $health = new searchengine_utilitycmd("HEALTHCHECK", $application, $host, $port);
  147. $health->execute(SOCK_FOREVER);
  148. return $health->response->valid;
  149. } // searchengine_healthcheck
  150. // ----------------------------------------------------------------------
  151.  
  152. /**
  153. * Function to acquire the SearchEngine index codument count. This is
  154. * similar to the healthcheck function, since it uses the same utility
  155. * command, but it just returns the numeric result that the command goes
  156. * and acquires as part of testing whether the server is alive.
  157. * @param string $application Application name/domain name for searching in
  158. * @param string $host Hostname or IP of SearchEngine server
  159. * @param string $port Port of SearchEngine server
  160. * @return mixed The number of documents, else FALSE if server is dead.
  161. */
  162. function searchengine_documentcount($application="?", $host="", $port="") {
  163. $result = false;
  164. $count = new searchengine_utilitycmd("HEALTHCHECK", $application, $host, $port);
  165. $count->execute(SOCK_FOREVER);
  166. if ($count->response->valid) {
  167. if (isset($count->response->tag_data["NumDocs"])) {
  168. $result = intval( $count->response->tag_data["NumDocs"]);
  169. }
  170. }
  171. return $result;
  172. } // searchengine_documentcount
  173. // ----------------------------------------------------------------------
  174.  
  175. ?>

Documentation generated by phpDocumentor 1.3.0RC3