[ Index ]
 

Code source de eZ Publish 3.9.0

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

title

Body

[fermer]

/kernel/search/plugins/openfts/ -> openfts.php (source)

   1  <?php
   2  //
   3  // Definition of openFts class
   4  //
   5  // Created on: <09-Aug-2002 10:07:15 sp>
   6  //
   7  // SOFTWARE NAME: eZ publish
   8  // SOFTWARE RELEASE: 3.9.0
   9  // BUILD VERSION: 17785
  10  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
  11  // SOFTWARE LICENSE: GNU General Public License v2.0
  12  // NOTICE: >
  13  //   This program is free software; you can redistribute it and/or
  14  //   modify it under the terms of version 2.0  of the GNU General
  15  //   Public License as published by the Free Software Foundation.
  16  //
  17  //   This program is distributed in the hope that it will be useful,
  18  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  19  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20  //   GNU General Public License for more details.
  21  //
  22  //   You should have received a copy of version 2.0 of the GNU General
  23  //   Public License along with this program; if not, write to the Free
  24  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  25  //   MA 02110-1301, USA.
  26  //
  27  //
  28  
  29  /*! \file openfts.php
  30  */
  31  
  32  /*!
  33    \class openFts openfts.php
  34    \brief The class openFts does
  35  
  36  */
  37  include_once ( "lib/ezdb/classes/ezdb.php" );
  38  include_once ( "lib/ezutils/classes/ezini.php" );
  39  include_once ( 'lib/ezfile/classes/ezdir.php' );
  40  include_once ( "lib/ezutils/classes/ezdebug.php" );
  41  
  42  class openFts
  43  {
  44      /*!
  45       Constructor
  46      */
  47      function openFts()
  48      {
  49  
  50      }
  51  
  52  
  53  
  54      /*!
  55       Adds an object to the search database.
  56      */
  57      function addObject( &$contentObject, $uri )
  58      {
  59          $db =& eZDB::instance();
  60  
  61          $contentObjectID = $contentObject->attribute( 'id' );
  62  
  63          $currentVersion =& $contentObject->currentVersion();
  64  
  65          $allText = '';
  66  
  67          $sys =& eZSys::instance();
  68          $storagePath = $sys->storageDirectory;
  69  
  70          $tmpFname = tempnam ( $storagePath, "txt$contentObjectID" );
  71          $fp = fopen( $tmpFname, "w" );
  72          chmod ( $tmpFname, 0755 );
  73          foreach ( $currentVersion->attributes() as $attribute )
  74          {
  75              $classAttribute =& $attribute->contentClassAttribute();
  76              if ( $classAttribute->attribute( "is_searchable" ) == 1 )
  77              {
  78                  // strip tags
  79                  $text = strip_tags( $attribute->metaData() );
  80  
  81                  // Strip multiple whitespaces
  82                  $text = str_replace(".", " ", $text );
  83                  $text = str_replace(",", " ", $text );
  84                  $text = str_replace("'", " ", $text );
  85                  $text = str_replace("\"", " ", $text );
  86  
  87                  $text = str_replace("\n", " ", $text );
  88                  $text = str_replace("\r", " ", $text );
  89                  $text = preg_replace("(\s+)", " ", $text );
  90  
  91                  // Split text on whitespace
  92                  //$wordArray =& split( " ", $text );
  93                  fwrite( $fp, ' '.$text );
  94              }
  95          }
  96  
  97          fclose( $fp );
  98          $tmpFname = realpath( $tmpFname );
  99          eZDebugSetting::writeDebug( 'kernel-search-openfts', "/home/sp/projects/php/ezpublish3/bin/openfts/index.pl nextgen_test $contentObjectID $tmpFname","indexing command");
 100          $retStr = system( "/home/sp/projects/php/ezpublish3/bin/openfts/index.pl nextgen_test $contentObjectID $tmpFname", $foo );
 101          eZDebugSetting::writeDebug( 'kernel-search-openfts', $retStr.$foo, "error string" );
 102          //  unlink($tmpFname);
 103  
 104  
 105      }
 106  
 107      /*!
 108       \static
 109      */
 110      function removeObject( $contentObject )
 111      {
 112          $db =& eZDB::instance();
 113          $contentObjectID = $contentObject->attribute( "id" );
 114          eZDebugSetting::writeDebug( 'kernel-search-openfts', "/home/sp/projects/php/ezpublish3/bin/openfts/delete.pl nextgen_test $contentObjectID " , "delete error string" );
 115  
 116          $retStr = system( "/home/sp/projects/php/ezpublish3/bin/openfts/delete.pl nextgen_test $contentObjectID " , $foo );
 117          eZDebugSetting::writeDebug( 'kernel-search-openfts', $retStr.$foo, "delete error string" );
 118  
 119  
 120  
 121      }
 122  
 123      /*!
 124       \static
 125       Runs a query to the search engine.
 126      */
 127      function search( $searchText, $params = array() )
 128      {
 129          $db =& eZDB::instance();
 130  
 131          $nonExistingWordArray = array();
 132  
 133          if ( isset( $params['SearchContentClassID'] ) )
 134              $searchContentClassID = $params['SearchContentClassID'];
 135          else
 136              $searchContentClassID = -1;
 137  
 138          if ( isset( $params['SearchContentClassAttributeID'] ) )
 139              $searchContentClassAttributeID = $params['SearchContentClassAttributeID'];
 140          else
 141              $searchContentClassAttributeID = -1;
 142  
 143          // strip multiple spaces
 144          $searchText = preg_replace( "(\s+)", " ", $searchText );
 145          //  $searchText = preg_replace( "(\"+)", "", $searchText );
 146  
 147          // find the phrases
 148  
 149  //        $sqlPartsString = system("/home/sp/projects/php/ezpublish3/bin/openfts/search.pl nextgen_test $searchText", &$foo);
 150          $sqlPartsString = `/home/sp/projects/php/ezpublish3/bin/openfts/search.pl -p nextgen_test -z $searchText`;
 151          eZDebugSetting::writeDebug( 'kernel-search-openfts', "/home/sp/projects/php/ezpublish3/bin/openfts/search.pl nextgen_test $searchText","indexing command");
 152          $sqlPartsArray = explode('|||', $sqlPartsString );
 153          $out = $sqlPartsArray[0];
 154          $tables = $sqlPartsArray[1];
 155          $condition = $sqlPartsArray[2];
 156          $order = $sqlPartsArray[3];
 157          $searchQuery = "SELECT
 158                                  ezcontentobject.id,
 159                                  ezcontentobject.main_node_id,
 160                                  ezcontentobject.name,
 161                                  txt.tid,
 162                                  txt.txt,
 163                                  $out
 164                          FROM
 165                               txt$tables,
 166                               ezcontentobject
 167                          WHERE
 168                               $condition AND
 169                               ezcontentobject.id = txt.tid
 170                          ORDER BY $order";
 171  
 172          $searchCountQuery = "SELECT
 173                                 count(txt.tid) AS count
 174                          FROM
 175                               txt$tables,
 176                               ezcontentobject
 177                          WHERE
 178                               $condition AND
 179                               ezcontentobject.id = txt.tid ";
 180  
 181          $objectRes = array();
 182  
 183          $objectRes = $db->arrayQuery( $searchQuery );
 184          $objectCountRes = $db->arrayQuery( $searchCountQuery );
 185          $searchCount = $objectCountRes[0]['count'];
 186  
 187  //        eZDebugSetting::writeDebug( 'kernel-search-openfts', $objectRes, 'search result' );
 188  
 189          return  array( "SearchResult" => $objectRes,
 190                         "SearchCount" => $searchCount );
 191      }
 192  
 193      /*!
 194       \private
 195       \return Returns an array of words created from the input string.
 196      */
 197      function splitString( $text )
 198      {
 199          // strip quotes
 200          $text = preg_replace("#'#", "", $text );
 201          $text = preg_replace( "#\"#", "", $text );
 202  
 203          // Strip multiple whitespace
 204          $text = trim( $text );
 205          $text = preg_replace("(\s+)", " ", $text );
 206  
 207          // Split text on whitespace
 208          $wordArray = split( " ", $text );
 209  
 210          $retArray = array();
 211          foreach ( $wordArray as $word )
 212          {
 213              if ( trim( $word ) != "" )
 214              {
 215                  $retArray[] = trim( $word );
 216              }
 217          }
 218  
 219          return $retArray;
 220      }
 221  }
 222  
 223  ?>


Généré le : Sat Feb 24 10:30:04 2007 par Balluche grâce à PHPXref 0.7