[ Index ]
 

Code source de SPIP Agora 1.4

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/Agora1-4/ecrire/include/sevenseas/SearchEngine/ -> mnogosearch.php (source)

   1  <?php
   2  /*****************************************************
   3  * This file is part of Agora, web based content management system.
   4  *
   5  * Agora 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; version 2 of the License.
   8  *
   9  * Agora is distributed in the hope that it will be useful,
  10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  * GNU General Public License for more details (file "COPYING").
  13  *
  14  * Copyright © Arnaud Martin, Antoine Pitrou et Philippe Rivière.
  15  * List of authors detailed in "copyright_fr.html" file.
  16  * E-mail : agora@sig.premier-ministre.gouv.fr
  17  * Web site : http://www.agora.gouv.fr
  18  *****************************************************/
  19  // Implementation class for MnoGoSearch.
  20  //
  21  
  22  require_once dirname(__FILE__). "/../SearchEngine.php";
  23  
  24  require_once dirname(__FILE__). "/../tools.inc.php";
  25  require_once dirname(__FILE__). "/../conf/mnogosearch.inc.php";
  26  
  27  /**
  28   * Implementation class for MnoGoSearch.
  29   * This implementation posts a search query
  30   * to a .idq file served by MnoGoSearch.
  31   * Before calling search method, in any script, include
  32   * the configuration script defining the needed constants
  33   * to interface MnoGoSearch. (Temporary solution).
  34   */
  35  class SearchEngine_MnoGoSearch extends SearchEngine {
  36  
  37      // {{{ constructor
  38  
  39      /**
  40       * Constructor for this implementation, used by the MnoGoSearch factory method
  41       * @access  private
  42       */
  43  	function SearchEngine_MnoGoSearch () {
  44          $par = get_parent_class($this);
  45          $res = $this->$par();
  46  
  47          if (PEAR::isError($res)) {
  48              die ($res->getMessage());
  49          }
  50      }
  51  
  52      // }}}
  53  
  54      // {{{ _computeQuery()
  55  
  56      /**
  57       * Implementation for MnoGoSearch
  58       *
  59       * @param   Array       query parameters
  60       * @return  String      XML result stream validating the indexresults.xsd XML Schema
  61       * @access  private
  62       */
  63      function &_computeQuery ($queryParameters) {
  64          $queryToGet = $this->_computePostFields($queryParameters);
  65          $xmlStream = &sendToHostNoHeader(MNOGOSEARCH_ADDRESS, MNOGOSEARCH_PORT, '', IDX_SRVR_IDQ, $queryToGet);
  66  
  67          return $xmlStream;
  68      }
  69  
  70      // }}}
  71  
  72      // {{{ _computePostFields()
  73  
  74      /**
  75       * This method computes the data to post given the query parameters
  76       * @param   Array   $queryParameters containing the query parameters
  77       * @return  String  representing the data ready to be posted as is
  78       * @access  private
  79       */
  80  	function _computePostFields ($queryParameters) {
  81          $textQuery = $this->_prepareTextQuery($queryParameters["textquery"]);
  82  
  83          if (isset($queryParameters["maxresults"])) {
  84              $resultLimit = "&ps=" . urlencode($queryParameters["maxresults"]);
  85          }
  86          else {
  87              $resultLimit = "&ps=100";
  88          }
  89  
  90          $dataToPost = "q=" . urlencode($textQuery);
  91          $dataToPost .= $resultLimit . '&wm=sub';
  92          return $dataToPost;
  93      }
  94  
  95      // }}}
  96  
  97      // {{{ _prepareTextQuery()
  98  
  99      /**
 100       * This methods prepare a text query so that it is represented as MnoGoSearch
 101       * uses it.
 102       * @param   String  $query Query that needs to be modified
 103       * @return  String  modified query
 104       * @access  private
 105       */
 106  	function _prepareTextQuery ($query) {
 107          require_once dirname(__FILE__). "/../../indexer/Indexer_Utils.php";
 108          $query = Indexer_Utils::nettoyer_chaine_indexation($query);
 109          $regs = Indexer_Utils::separateurs_indexation(true). " ";
 110  
 111          $query = strtr($query, $regs, ereg_replace('.', ' ', $regs));
 112  
 113          $rows = Indexer_Utils::spip_split(" +", $query);
 114  
 115          for ($i = 0; $i < count($rows); $i++) {
 116              if (strlen($rows[$i]) <= 3) {
 117                  unset ($rows[$i]);
 118              }
 119          }
 120  
 121          $query = join('|', $rows);
 122          return $query;
 123      }
 124  
 125  // }}}
 126  
 127  }
 128  ?>


Généré le : Sat Feb 24 14:40:03 2007 par Balluche grâce à PHPXref 0.7