improve search

This commit is contained in:
John Bintz 2009-09-21 20:53:51 -04:00
parent 40b3d22820
commit a6e1438231
4 changed files with 56 additions and 29 deletions

View File

@ -2,6 +2,7 @@
class WDTSTranscriptManager { class WDTSTranscriptManager {
var $key = null; var $key = null;
var $search_key = null;
var $post_id = null; var $post_id = null;
var $allow_multiple = false; var $allow_multiple = false;
@ -68,12 +69,22 @@ class WDTSTranscriptManager {
$transcripts = $new_transcripts; $transcripts = $new_transcripts;
} }
$this->_update_search_field($transcripts);
return update_post_meta($this->post_id, $this->key, $transcripts); return update_post_meta($this->post_id, $this->key, $transcripts);
} }
} }
return false; return false;
} }
function _update_search_field($transcripts) {
if (!empty($this->search_key)) {
$search_lines = array();
foreach ($transcripts as $transcript) { $search_lines[] = $transcript['transcript']; }
update_post_meta($this->post_id, $this->search_key, implode(" ", $search_lines));
}
}
function delete_transcript($language = null) { function delete_transcript($language = null) {
return $this->_delete_transcript_by_field('language', $language); return $this->_delete_transcript_by_field('language', $language);
} }
@ -94,6 +105,8 @@ class WDTSTranscriptManager {
} }
} }
$this->_update_search_field($new_transcripts);
update_post_meta($this->post_id, $this->key, $new_transcripts); update_post_meta($this->post_id, $this->key, $new_transcripts);
return $deleted_transcript; return $deleted_transcript;
} }

View File

@ -9,6 +9,7 @@ class WDTSQueuedTranscript extends WDTSTranscriptManager {
class WDTSApprovedTranscript extends WDTSTranscriptManager { class WDTSApprovedTranscript extends WDTSTranscriptManager {
var $key = "approved_transcripts"; var $key = "approved_transcripts";
var $search_key = "approved_transcripts_words";
} }
?> ?>

View File

@ -80,7 +80,7 @@ class WhatDidTheySayAdmin {
$search = get_query_var('s'); $search = get_query_var('s');
if (!empty($search)) { if (!empty($search)) {
$where .= $wpdb->prepare(" OR ($wpdb->postmeta.meta_key = %s ", 'approved_transcripts'); $where .= $wpdb->prepare(" OR ($wpdb->postmeta.meta_key = %s ", 'approved_transcripts_words');
$search = addslashes_gpc($search); $search = addslashes_gpc($search);
$where .= " AND $wpdb->postmeta.meta_value LIKE '%$search%') "; $where .= " AND $wpdb->postmeta.meta_value LIKE '%$search%') ";
} }

View File

@ -14,6 +14,7 @@ class WDTSTranscriptTest extends PHPUnit_Framework_TestCase {
$this->w = new WDTSTranscriptManager(1); $this->w = new WDTSTranscriptManager(1);
$this->w->key = "test"; $this->w->key = "test";
$this->w->search_key = "test_search";
} }
function testSaveTranscript() { function testSaveTranscript() {
@ -36,6 +37,8 @@ class WDTSTranscriptTest extends PHPUnit_Framework_TestCase {
get_post_meta(1, $this->w->key, true) get_post_meta(1, $this->w->key, true)
); );
$this->assertEquals("this is a transcript", get_post_meta(1, $this->w->search_key, true));
$this->w->save_transcript(array( $this->w->save_transcript(array(
'language' => 'en', 'language' => 'en',
'transcript' => 'this is another transcript' 'transcript' => 'this is another transcript'
@ -53,6 +56,8 @@ class WDTSTranscriptTest extends PHPUnit_Framework_TestCase {
get_post_meta(1, $this->w->key, true) get_post_meta(1, $this->w->key, true)
); );
$this->assertEquals("this is another transcript", get_post_meta(1, $this->w->search_key, true));
$this->w->save_transcript(array( $this->w->save_transcript(array(
'language' => 'fr', 'language' => 'fr',
'transcript' => "il s'agit d'une nouvelle transcription" 'transcript' => "il s'agit d'une nouvelle transcription"
@ -76,6 +81,8 @@ class WDTSTranscriptTest extends PHPUnit_Framework_TestCase {
get_post_meta(1, $this->w->key, true) get_post_meta(1, $this->w->key, true)
); );
$this->assertEquals("this is another transcript il s'agit d'une nouvelle transcription", get_post_meta(1, $this->w->search_key, true));
$this->w->allow_multiple = true; $this->w->allow_multiple = true;
$this->w->save_transcript(array( $this->w->save_transcript(array(
@ -106,6 +113,8 @@ class WDTSTranscriptTest extends PHPUnit_Framework_TestCase {
), ),
get_post_meta(1, $this->w->key, true) get_post_meta(1, $this->w->key, true)
); );
$this->assertEquals("this is another transcript il s'agit d'une nouvelle transcription this is yet another transcript", get_post_meta(1, $this->w->search_key, true));
} }
function testDeleteTranscript() { function testDeleteTranscript() {
@ -129,6 +138,8 @@ class WDTSTranscriptTest extends PHPUnit_Framework_TestCase {
'key' => 1 'key' => 1
), ),
), get_post_meta(1, $this->w->key, true)); ), get_post_meta(1, $this->w->key, true));
$this->assertEquals("il s'agit d'une nouvelle transcription", get_post_meta(1, $this->w->search_key, true));
} }
function testDeleteTranscriptByKey() { function testDeleteTranscriptByKey() {
@ -160,6 +171,8 @@ class WDTSTranscriptTest extends PHPUnit_Framework_TestCase {
'key' => 1 'key' => 1
), ),
), get_post_meta(1, $this->w->key, true)); ), get_post_meta(1, $this->w->key, true));
$this->assertEquals("il s'agit d'une nouvelle transcription", get_post_meta(1, $this->w->search_key, true));
} }
function testGetLanguages() { function testGetLanguages() {