|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Definition of eZSearchLog class 00004 // 00005 // Created on: <08-Aug-2002 10:27:21 bf> 00006 // 00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00008 // SOFTWARE NAME: eZ Publish 00009 // SOFTWARE RELEASE: 4.0.x 00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS 00011 // SOFTWARE LICENSE: GNU General Public License v2.0 00012 // NOTICE: > 00013 // This program is free software; you can redistribute it and/or 00014 // modify it under the terms of version 2.0 of the GNU General 00015 // Public License as published by the Free Software Foundation. 00016 // 00017 // This program is distributed in the hope that it will be useful, 00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 // GNU General Public License for more details. 00021 // 00022 // You should have received a copy of version 2.0 of the GNU General 00023 // Public License along with this program; if not, write to the Free 00024 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00025 // MA 02110-1301, USA. 00026 // 00027 // 00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00029 // 00030 00031 /*! 00032 \class eZSearchLog ezsearchlog.php 00033 \brief eZSearchLog handles logging of search phrases 00034 00035 */ 00036 00037 //include_once( 'lib/ezdb/classes/ezdb.php' ); 00038 00039 class eZSearchLog 00040 { 00041 /*! 00042 Logs a search query so that we can retrieve statistics afterwords. 00043 */ 00044 static function addPhrase( $phrase, $returnCount ) 00045 { 00046 $db = eZDB::instance(); 00047 $db->begin(); 00048 00049 //include_once( 'lib/ezi18n/classes/ezchartransform.php' ); 00050 $trans = eZCharTransform::instance(); 00051 $phrase = $trans->transformByGroup( trim( $phrase ), 'lowercase' ); 00052 00053 $phrase = $db->escapeString( $phrase ); 00054 00055 // find or store the phrase 00056 $phraseRes = $db->arrayQuery( "SELECT id FROM ezsearch_search_phrase WHERE phrase='$phrase'" ); 00057 00058 if ( count( $phraseRes ) == 1 ) 00059 { 00060 $phraseID = $phraseRes[0]['id']; 00061 $db->query( "UPDATE ezsearch_search_phrase 00062 SET phrase_count = phrase_count + 1, 00063 result_count = result_count + $returnCount 00064 WHERE id = $phraseID" ); 00065 } 00066 else 00067 { 00068 $db->query( "INSERT INTO 00069 ezsearch_search_phrase ( phrase, phrase_count, result_count ) 00070 VALUES ( '$phrase', 1, $returnCount )" ); 00071 00072 /* when breaking BC: delete next line */ 00073 $phraseID = $db->lastSerialID( 'ezsearch_search_phrase', 'id' ); 00074 } 00075 00076 /* when breaking BC: delete next lines */ 00077 /* ezsearch_return_count is not used any more by eZ Publish 00078 but perhaps someone else added some functionality... */ 00079 $time = time(); 00080 // store the search result 00081 $db->query( "INSERT INTO 00082 ezsearch_return_count ( phrase_id, count, time ) 00083 VALUES ( '$phraseID', '$returnCount', '$time' )" ); 00084 /* end of BC breaking delete*/ 00085 00086 $db->commit(); 00087 } 00088 00089 /*! 00090 Returns the most frequent search phrases, which did not get hits. 00091 */ 00092 static function mostFrequentPhraseArray( $parameters = array( ) ) 00093 { 00094 $db = eZDB::instance(); 00095 00096 $query = 'SELECT phrase_count, result_count / phrase_count AS result_count, id, phrase 00097 FROM ezsearch_search_phrase 00098 ORDER BY phrase_count DESC'; 00099 00100 return $db->arrayQuery( $query, $parameters ); 00101 } 00102 00103 /*! 00104 \static 00105 Removes all stored phrases and search match counts from the database. 00106 */ 00107 static function removeStatistics() 00108 { 00109 $db = eZDB::instance(); 00110 $query = "DELETE FROM ezsearch_search_phrase"; 00111 $db->query( $query ); 00112 /* when breaking BC: delete those two lines */ 00113 $query = "DELETE FROM ezsearch_return_count"; 00114 $db->query( $query ); 00115 } 00116 } 00117 00118 ?>