r52641 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r52640‎ | r52641 | r52642 >
Date:19:30, 1 July 2009
Author:dale
Status:deferred
Tags:
Comment:
replace u800 in search results
Modified paths:
  • /trunk/extensions/MetavidWiki/includes/MV_Index.php (modified) (history)
  • /trunk/extensions/MetavidWiki/includes/specials/MV_SpecialMediaSearch.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MetavidWiki/includes/MV_Index.php
@@ -30,7 +30,7 @@
3131 if ( $mvTitle != null )
3232 $this->mvTitle = $mvTitle;
3333 }
34 -
 34+
3535 function countMVDInRange( $stream_id, $start_time = null, $end_time = null, $mvd_type = 'all' ) {
3636 global $mvDefaultClipLength;
3737 $dbr =& wfGetDB( DB_SLAVE );
@@ -51,7 +51,7 @@
5252 $dbr =& wfGetDB( DB_SLAVE );
5353 // set up select vars:
5454 $conds = $vars = array();
55 - $from_tables = '';
 55+ $from_tables = '';
5656 //
5757 // set mvd_type if empty:
5858 if ( $mvd_type == null )$mvd_type = 'all';
@@ -61,7 +61,7 @@
6262 // add in base from:
6363 $from_tables .= $dbr->tableName( 'mv_mvd_index' );
6464 $conds = array( 'stream_id' => $stream_id );
65 - // print_r($smw_properties);
 65+ // print_r($smw_properties);
6666 if ( $mvd_type != 'all' ) {
6767 $mvd_type = ( is_object( $mvd_type ) ) ? get_object_vars( $mvd_type ):$mvd_type;
6868 if ( is_array( $mvd_type ) ) {
@@ -80,25 +80,25 @@
8181 // print "Start time: $start_time END TIME: $end_time\n";
8282 if ( $end_time != null )
8383 $conds[] = 'start_time <= ' . $dbr->addQuotes( $end_time );
84 -
 84+
8585 if ( $start_time != null )
8686 $conds[] = 'end_time >= ' . $dbr->addQuotes( $start_time );
87 -
 87+
8888 // add in ordering
8989 if ( !isset( $options['ORDER BY'] ) )
9090 $options['ORDER BY'] = 'start_time ASC';
91 -
 91+
9292 // add in limit
9393 if ( !isset( $options['LIMIT'] ) )
9494 $options['LIMIT'] = 200;
95 -
 95+
9696 // run query:
9797 $result = $dbr->select( $from_tables,
9898 $vars,
9999 $conds,
100100 __METHOD__,
101101 $options );
102 -
 102+
103103 //print $dbr->lastQuery();
104104 //die;
105105 return MV_Index::getMVDMeta( $result, $getText, $smw_properties);
@@ -106,19 +106,19 @@
107107 function getMVDMeta( &$result, $getText = false, $smw_properties = ''){
108108 $dbr =& wfGetDB( DB_SLAVE );
109109 if ( $dbr->numRows( $result ) == 0 )return array();
110 -
 110+
111111 $do_cat_lookup = $do_smw_lookup = false;
112112 if( !is_array($smw_properties) ){
113113 $smw_properties = explode( ',', $smw_properties );
114 - }
 114+ }
115115 foreach($smw_properties as $propKey){
116116 if($propKey == 'category')
117117 $do_cat_lookup=true;
118 -
 118+
119119 if($propKey=='Speech_by'|| $propKey=='Bill')
120120 $do_smw_lookup=true;
121 -
122 - }
 121+
 122+ }
123123 //get the results with meta
124124 $ret_ary = array();
125125 $from_tables = $vars = $options = array();
@@ -126,7 +126,7 @@
127127 $or = '';
128128 while ( $row = $dbr->fetchObject( $result ) ) {
129129 $ret_ary[$row->id] = $row;
130 - // init array:
 130+ // init array:
131131 if ( $do_cat_lookup ) {
132132 if ( !isset( $ret_ary[$row->id]->category ) )
133133 $ret_ary[$row->id]->category = array();
@@ -143,23 +143,23 @@
144144 $dbr->tableName( 'categorylinks' ) . '.cl_from = ' .
145145 $dbr->tableName( 'mv_mvd_index' ) . '.mv_page_id' .
146146 ' ) ';
147 -
 147+
148148 $vars = array( 'cl_from', 'cl_to' );
149 -
 149+
150150 $options['LIMIT'] = 2000; // max average 5 categories per page
151151
152152 $result_cat = $dbr->select( $from_tables,
153153 $vars,
154154 $conds,
155155 __METHOD__,
156 - $options );
157 -
 156+ $options );
 157+
158158 while ( $cat_row = $dbr->fetchObject( $result_cat ) ) {
159159 $ret_ary[$cat_row->cl_from]->category[] = $cat_row->cl_to;
160160 }
161 - }
162 - // slow epecialy for lots of query results but join Query is crazy complicated for SMW >= 1.2
163 - // (and I have not been able to construct it without hitting exessive number of rows in the EXPLIN)
 161+ }
 162+ // slow especially for lots of query results but join Query is crazy complicated for SMW >= 1.2
 163+ // (and I have not been able to construct it without hitting expensive number of rows in the EXPLIN)
164164 // @@todo these queries should be merged with semantic wiki Ask with some ~special~ keywords for fulltext search
165165 if ( $do_smw_lookup ) {
166166 $smwStore =& smwfGetStore();
@@ -167,7 +167,7 @@
168168 $rowTitle = Title::newFromText( $row->wiki_title, MV_NS_MVD );
169169 foreach ( $smw_properties as $propKey ) {
170170 if ( $propKey != 'category' ) {
171 - // init property:
 171+ // init property:
172172 $row->$propKey = '';
173173 $propTitle = Title::newFromText( $propKey, SMW_NS_PROPERTY );
174174 $smwProps = $smwStore->getPropertyValues( $rowTitle, $propTitle );
@@ -183,59 +183,59 @@
184184 // print_r($ret_ary);
185185 // die;
186186
187 -
 187+
188188 // print $dbr->lastQuery();
189189 // die;
190190 // echo $sql;
191191 // $result =& $dbr->query( $sql, 'MV_Index:time_index_query');
192192 return $ret_ary;
193 - }
194 - //gets an Annotative layer that encapsulates the mvTilte
 193+ }
 194+ //gets an Annotative layer that encapsulates the mvTilte
195195 static function getParentAnnotativeLayers(& $mvTitle){
196 - //first check if we are in range of the cache:
 196+ //first check if we are in range of the cache:
197197 if(count(self::$annoCache)!=0){
198198 foreach(self::$annoCache as $aMVD){
199 - if( $aMVD->start_time <= $mvTitle->getStartTimeSeconds() &&
200 - $aMVD->start_time <= $mvTitle->getEndTimeSeconds() &&
201 - $aMVD->end_time >= $mvTitle->getEndTimeSeconds() &&
202 - $aMVD->end_time >= $mvTitle->getEndTimeSeconds() &&
 199+ if( $aMVD->start_time <= $mvTitle->getStartTimeSeconds() &&
 200+ $aMVD->start_time <= $mvTitle->getEndTimeSeconds() &&
 201+ $aMVD->end_time >= $mvTitle->getEndTimeSeconds() &&
 202+ $aMVD->end_time >= $mvTitle->getEndTimeSeconds() &&
203203 $aMVD->stream_id == $mvTitle->getStreamId() ){
204 - //just return the cached result (faster than the set of db queries below)
 204+ //just return the cached result (faster than the set of db queries below)
205205 return $aMVD;
206206 }
207207 }
208208 }
209 -
 209+
210210 $dbr =& wfGetDB( DB_SLAVE );
211211 $from_tables = $dbr->tableName( 'mv_mvd_index' );
212212 $vars = '`mv_page_id` as `id`, `wiki_title`,`mvd_type`, `stream_id`, `start_time`,`end_time`,`view_count`';
213213 $cond = array( 'stream_id' => $mvTitle->getStreamId() ,
214 - 'mvd_type' => 'Anno_en'
 214+ 'mvd_type' => 'Anno_en'
215215 );
216 -
 216+
217217 $cond[] = ' `start_time` <= ' . $mvTitle->getStartTimeSeconds() ;
218218 $cond[] = ' `start_time` <= ' . $mvTitle->getEndTimeSeconds() ;
219 -
 219+
220220 $cond[] = ' `end_time` >= ' . $mvTitle->getStartTimeSeconds() ;
221 - $cond[] = ' `end_time` >= ' . $mvTitle->getEndTimeSeconds() ;
222 -
 221+ $cond[] = ' `end_time` >= ' . $mvTitle->getEndTimeSeconds() ;
 222+
223223 $res = $dbr->select( $from_tables,
224224 $vars,
225225 $cond,
226 - __METHOD__,
227 - array( 'LIMIT' => 1 ) //just get one result
 226+ __METHOD__,
 227+ array( 'LIMIT' => 1 ) //just get one result
228228 );
229229 //print $dbr->lastQuery();
230230 //die;
231231 $aMvd_rows = MV_Index::getMVDMeta($res, false, 'Speech_by,Bill,category');
232 - //returns the result in array set to current:
233 - $aMvd = end($aMvd_rows );
 232+ //returns the result in array set to current:
 233+ $aMvd = end($aMvd_rows );
234234 if(!isset(self::$annoCache[ $aMvd->id ])){
235235 self::$annoCache[ $aMvd->id ] = $aMvd;
236 - };
 236+ };
237237 return $aMvd;
238238 }
239 -
 239+
240240 /*@@todo figure another way to get at this data...this is not a very fast query: */
241241 function getMVDTypeInRange( $stream_id, $start_time = null, $end_time = null ) {
242242 $dbr =& wfGetDB( DB_SLAVE );
@@ -274,8 +274,8 @@
275275 $wgRequest, $mvDo_SQL_CALC_FOUND_ROWS, $mvMediaSearchResultsLimit;
276276
277277 global $mvSpokenByInSearchResult, $mvCategoryInSearchResult, $mvBillInSearchResult;
278 -
279 -
 278+
 279+
280280 // init vars
281281 $from_tables = '';
282282 $vars = $conds = $options = array();
@@ -284,15 +284,15 @@
285285 $vars_top = $conds_top = $options_top = array();
286286
287287 $do_top_range_query = false;
288 -
289288
 289+
290290 $dbr =& wfGetDB( DB_SLAVE );
291291 // organize the queries (group full-text searches and category/attributes)
292292 // if the attribute is not a numerical just add it to the fulltext query
293293 $ftq_match_asql = $last_person_aon = $ftq_match = $ftq = $snq = $toplq = $toplq_cat = $date_range_join = $date_range_where = $asql = ''; // top query and full text query =''
294294 if ( $filters == '' )return array();
295295 $ftq_match_asql = $date_cond = '';
296 -
 296+
297297 $date_range_join = true;
298298
299299 // $selOpt = ($mvDo_SQL_CALC_FOUND_ROWS)?'SQL_CALC_FOUND_ROWS':'';
@@ -321,9 +321,9 @@
322322 }
323323 // add to the fulltext query:
324324 switch( $f['t'] ) {
325 - case 'speech_by':
 325+ case 'speech_by':
326326 case 'spoken_by':
327 - $skey = str_replace('_', ' ', $f['t']);
 327+ $skey = str_replace('_', ' ', $f['t']);
328328 // skip if empty value:
329329 if ( trim( $f['v'] ) == '' )continue;
330330 // if we have an OR set prev to OR
@@ -444,7 +444,7 @@
445445 $dbr->tableName( 'mv_stream_files' ) . '.stream_id ' .
446446 ' AND (' . $dbr->tableName( 'mv_stream_files' ) . '.file_desc_msg = ' .
447447 $dbr->addQuotes( $mvDefaultVideoQualityKey ) .
448 - //' OR '. $dbr->tableName( 'mv_stream_files' ) .'.file_desc_msg = ' .
 448+ //' OR '. $dbr->tableName( 'mv_stream_files' ) .'.file_desc_msg = ' .
449449 // $dbr->addQuotes( $mvDefaultFlashQualityKey ) .
450450 ')'.
451451 ') ';
@@ -462,7 +462,7 @@
463463 ' AND ' . $dbr->tableName( 'smw_relations' ) . '.relation_title = \'Spoken_By\'' .
464464 ') ';
465465 }*/
466 -
 466+
467467 // add conditions to last condition element (cuz we have to manually mannage and or):
468468
469469 $conds[count( $conds )] = ' ' . $dbr->tableName( 'mv_mvd_index' ) . '.mvd_type = \'ht_en\' ' .
@@ -551,18 +551,18 @@
552552 MV_Index::insert_merge_range( $stream_groups[$row->stream_id], $stream_groups, $row );
553553 }
554554 }
555 -
 555+
556556 if( $mvCategoryInSearchResult){
557557 $or='';
558558 $conds='';
559559 $options=array();
560 - //build the category query conditions:
 560+ //build the category query conditions:
561561 foreach($ret_ary as $row){
562562 if ( !isset( $ret_ary[$row->id]->category ) )
563563 $ret_ary[$row->id]->categories = array();
564 -
 564+
565565 $conds .= $or . ' cl_from =' . $dbr->addQuotes( $row->id );
566 - $or = ' OR ';
 566+ $or = ' OR ';
567567 }
568568 //do the lookup:
569569 $from_tables = $dbr->tableName( 'categorylinks' );
@@ -571,8 +571,8 @@
572572 $dbr->tableName( 'categorylinks' ) . '.cl_from = ' .
573573 $dbr->tableName( 'mv_mvd_index' ) . '.mv_page_id' .
574574 ' ) ';
575 -
576 - $vars = array( 'cl_from', 'cl_to' );
 575+
 576+ $vars = array( 'cl_from', 'cl_to' );
577577 $options['LIMIT'] = 2000; // max avarage 5 categories per page
578578
579579 $result_cat = $dbr->select( $from_tables,
@@ -584,30 +584,30 @@
585585 $ret_ary[$cat_row->cl_from]->categories[$cat_row->cl_to] = true;
586586 }
587587 }
588 -
589 - if( $mvSpokenByInSearchResult || $mvBillInSearchResult ){
590 - // slow especially for lots of query results but join Query is crazy complicated for SMW >= 1.2
591 - // (and I have not been able to construct it without hitting exessive number of rows in the EXPLIN)
592 - // @@todo these queries should be merged with semantic wiki Ask with some ~special~ keywords for fulltext search
 588+
 589+ if( $mvSpokenByInSearchResult || $mvBillInSearchResult ){
 590+ // slow especially for lots of query results but join Query is crazy complicated for SMW >= 1.2
 591+ // (and I have not been able to construct it without hitting exessive number of rows in the EXPLIN)
 592+ // @@todo these queries should be merged with semantic wiki Ask with some ~special~ keywords for fulltext search
593593 $smwStore =& smwfGetStore();
594594 foreach ( $ret_ary as & $row ) {
595595 //@@todo this is all very hackish but this is because SMW changed the db schema causing a few hacks:
596 - // obviously this should be rewritten to use some SMW based query system.
 596+ // obviously this should be rewritten to use some SMW based query system.
597597 $smw_properties=array();
598598 if($mvSpokenByInSearchResult && strtolower(substr($row->wiki_title,0,2))=='ht')
599599 $smw_properties[]='Spoken_By';
600 -
 600+
601601 if($mvSpokenByInSearchResult && strtolower(substr($row->wiki_title,0,4))=='anno')
602602 $smw_properties[]='Speech_by';
603 -
 603+
604604 if($mvBillInSearchResult)
605 - $smw_properties[]='Bill';
606 -
607 -
608 - $rowTitle = Title::newFromText( $row->wiki_title, MV_NS_MVD );
 605+ $smw_properties[]='Bill';
 606+
 607+
 608+ $rowTitle = Title::newFromText( $row->wiki_title, MV_NS_MVD );
609609 foreach ( $smw_properties as $propKey ) {
610 - if ( $propKey != 'category' ) {
611 - //print "on key: $propKey";
 610+ if ( $propKey != 'category' ) {
 611+ //print "on key: $propKey";
612612 $propTitle = Title::newFromText( $propKey, SMW_NS_PROPERTY );
613613 $smwProps = $smwStore->getPropertyValues( $rowTitle, $propTitle );
614614 // just a temp hack .. we need to think about this abstraction a bit..
@@ -618,18 +618,18 @@
619619 $row->spoken_by = $v->getXSDValue();
620620 }else if($propKey=='Bill'){
621621 $row->bills=array();
622 - foreach($smwProps as $v){
 622+ foreach($smwProps as $v){
623623 $row->bills[$v->getXSDValue()] = true;
624 - }
 624+ }
625625 }
626626 }
627627 }
628 - }
 628+ }
629629 }
630630 }
631 -
 631+
632632 return $ret_ary;
633 - }
 633+ }
634634 function numResultsFound() {
635635 if ( isset( $this->numResultsFound ) ) {
636636 return $this->numResultsFound;
Index: trunk/extensions/MetavidWiki/includes/specials/MV_SpecialMediaSearch.php
@@ -479,7 +479,7 @@
480480 $mvStreamTitle = Title :: MakeTitle( MV_NS_STREAM, $mvTitle->getNearStreamName( 0 ) );
481481 }
482482 // $mvTitle->getStreamName() .'/'.$mvTitle->getStartTime() .'/'. $mvTitle->getEndTime() );
483 - $mvd_text = $mvd->text;
 483+ $mvd_text = str_replace(array('u800','u82e'),'', $mvd->text);
484484
485485 $o .= '<li class="result">
486486 <span class="vid_img" id="mvimg_' . htmlspecialchars( $mvd->id ) . '">
@@ -493,7 +493,7 @@
494494 $sk->makeKnownLinkObj( $mvStreamTitle, $mvTitle->getStreamNameText() .
495495 ' :: ' . $mvTitle->getTimeDesc() ) .
496496 '</h4>
497 - <p>Matching Phrase:' . $this->termHighlight( $mvd->text, implode( '|', $this->getTerms() ), 1, 100 ) . ' </p>
 497+ <p>Matching Phrase:' . $this->termHighlight( $mvd_text, implode( '|', $this->getTerms() ), 1, 100 ) . ' </p>
498498 <span class="by">' . $mvd_cnt_links . '</span>
499499 <span class="by">' . $mvd_cat_links . '</span>
500500 <span class="by">' . $mvd_bill_links . '</span>

Status & tagging log