Changeset e1377e9
- Timestamp:
- 08/31/10 18:47:18 (21 months ago)
- Branches:
- ('master', '8434b8322dd6f8ff37c17bd45b94e7a826f86b53')('vitrine', 'afe109c61a407808bd54d88bcccb1cde726a010a')
- Children:
- f3f37e8a5be17f14731449f26b5ab1e7cc6c85d4
- Parents:
- f2cb64b2836c21c04a38954812e396eab23b9017
- git-author:
- Benoit Grégoire <benoitg@coeus.ca>2010-08-31 18:47:18-04:00
- git-committer:
- Benoit Grégoire <benoitg@coeus.ca>2010-08-31 18:47:18-04:00
- Location:
- html
- Files:
-
- 2 edited
-
classes/SearchEngine.php (modified) (13 diffs)
-
tests/VocabRelationshipNavigationTest.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
html/classes/SearchEngine.php
rf2cb64b re1377e9 169 169 } 170 170 171 /** SQL fragment to limit a query to the candidate LO t haking the virtual host's themes and languages171 /** SQL fragment to limit a query to the candidate LO taking the virtual host's themes and languages 172 172 * in consideration. Note that this query will return null if there 173 173 * are no virtual host restrictions … … 480 480 //var_dump($this->theme_limit_array); 481 481 foreach ($this->theme_limit_array as $theme_limit) { 482 $sql_theme_limit_join = self :: getSqlLomThemeJoin();483 482 //pretty_print_r($theme_limit); 484 483 $term_id = $theme_limit['theme']->getId(); … … 548 547 $sql_or_array = array(); 549 548 foreach ($this->theme_limit_array as $theme_limit) { 550 $sql_theme_limit_join = self :: getSqlLomThemeJoin( );549 $sql_theme_limit_join = self :: getSqlLomThemeJoin($theme_limit['recursive']); 551 550 //pretty_print_r($theme_limit); 552 551 $sql_theme_limit_where = self :: getSqlThemeLimitWhereSingle($theme_limit['theme'], $theme_limit['recursive']); … … 616 615 * @return true 617 616 */ 618 static private function getSqlLomThemeJoinHelper($navLevel, $initialLeftTable, $finalTable, &$sql, Array &$selectListArray, $finalJoin=true, $joinBackwards=false) {617 static private function getSqlLomThemeJoinHelper($navLevel, $initialLeftTable, $finalTable, $recursive, &$sql, Array &$selectListArray, $finalJoin=true, $joinBackwards=false) { 619 618 if($finalJoin) { 620 619 $finalJoinTable = $finalTable; … … 624 623 } 625 624 if($navLevel>1) { 626 self::getSqlLomThemeJoinHelper($navLevel-1, $initialLeftTable, $finalJoinTable, $ sql, $selectListArray, false, $joinBackwards);625 self::getSqlLomThemeJoinHelper($navLevel-1, $initialLeftTable, $finalJoinTable, $recursive, $sql, $selectListArray, false, $joinBackwards); 627 626 } 628 627 if($navLevel==1) { … … 737 736 $vocIdcoalesceParts[]="{$table}.vdex_4_vocabulary_identifier"; 738 737 $termIdcoalesceParts[]="{$table}.vdex_6_1_identifier"; 739 $finalJoinConditionParts[]="({$finalJoinTable}.vdex_4_vocabulary_identifier={$table}.vdex_4_vocabulary_identifier AND {$finalJoinTable}.vdex_6_1_identifier={$table}.vdex_6_1_identifier)"; 738 if($recursive) { 739 $finalJoinConditionParts[]="({$finalJoinTable}.vdex_4_vocabulary_identifier={$table}.vdex_4_vocabulary_identifier AND {$finalJoinTable}.ns_left>={$table}.ns_left AND {$finalJoinTable}.ns_right<={$table}.ns_right)"; 740 } 741 else{ 742 $finalJoinConditionParts[]="({$finalJoinTable}.vdex_4_vocabulary_identifier={$table}.vdex_4_vocabulary_identifier AND {$finalJoinTable}.vdex_6_1_identifier={$table}.vdex_6_1_identifier)"; 743 744 } 740 745 } 741 746 /* Re-joining with vocabulary_term is essential to exploit the nested-set structure later */ … … 762 767 * BUT there may be exceptions. Example: One may want to search by keywords including all navigated terms. 763 768 * */ 764 static private function getSqlLomThemeJoin( ) {769 static private function getSqlLomThemeJoin($recursive) { 765 770 $retval = null; 766 771 … … 781 786 $selectListArray=array(); 782 787 $sqlJoin = null; 783 self::getSqlLomThemeJoinHelper(2, 'initial_theme_limit_terms', 'theme_limit_terms', $ sqlJoin, $selectListArray);788 self::getSqlLomThemeJoinHelper(2, 'initial_theme_limit_terms', 'theme_limit_terms', $recursive, $sqlJoin, $selectListArray); 784 789 $selectList = implode(", \n ", $selectListArray); 785 790 $sql = "SELECT $selectList \n"; … … 795 800 $sqlJoin=null; 796 801 797 self::getSqlLomThemeJoinHelper(2, 'initial_theme_limit_terms', 'theme_limit_terms', $ sqlJoin, $selectListArray, true, false);802 self::getSqlLomThemeJoinHelper(2, 'initial_theme_limit_terms', 'theme_limit_terms', $recursive, $sqlJoin, $selectListArray, true, false); 798 803 799 804 $retval .= " $sqlJoin \n"; … … 874 879 875 880 // Limit to specific theme$this->additional_join_string 876 $sql_theme_limit_where = self :: getSqlThemeLimitWhere( );881 $sql_theme_limit_where = self :: getSqlThemeLimitWhere(null, true); 877 882 if (!empty ($sql_theme_limit_where)) { 878 $sql_theme_limit_join = self :: getSqlLomThemeJoin( );883 $sql_theme_limit_join = self :: getSqlLomThemeJoin(true); 879 884 } else { 880 885 $sql_theme_limit_join = null; //No need to join if there are no themes to restrict to. … … 911 916 $sql_1_5 = "\n(SELECT lom_id, lom_status_identifier, value, {$this->value_match_table}.rank, '1_5' as element, CAST({$this->value_match_table}.langstring_entries_id AS integer) as source_langstring_value_id FROM lom NATURAL JOIN lom_1_5_keywords_has_langstrings NATURAL JOIN langstrings NATURAL JOIN {$this->value_match_table}) \n"; 912 917 /* lom_9_2_taxon_path, vocabulaires VDEX */ 913 $sql_9_2_vdex = "\n(SELECT lom_id, lom_status_identifier, value, {$this->value_match_table}.rank, '9_2' as element, CAST({$this->value_match_table}.langstring_entries_id AS integer) as source_langstring_value_id FROM lom " . $this->getSqlLomThemeJoin( ) . " JOIN vocabularies ON (theme_limit_terms.vdex_4_vocabulary_identifier=vocabularies.vdex_4_vocabulary_identifier) JOIN {$this->value_match_table} ON (theme_limit_terms.vdex_6_3_caption={$this->value_match_table}.langstrings_id OR theme_limit_terms.vdex_6_4_description={$this->value_match_table}.langstrings_id) ) \n";918 $sql_9_2_vdex = "\n(SELECT lom_id, lom_status_identifier, value, {$this->value_match_table}.rank, '9_2' as element, CAST({$this->value_match_table}.langstring_entries_id AS integer) as source_langstring_value_id FROM lom " . $this->getSqlLomThemeJoin(true) . " JOIN vocabularies ON (theme_limit_terms.vdex_4_vocabulary_identifier=vocabularies.vdex_4_vocabulary_identifier) JOIN {$this->value_match_table} ON (theme_limit_terms.vdex_6_3_caption={$this->value_match_table}.langstrings_id OR theme_limit_terms.vdex_6_4_description={$this->value_match_table}.langstrings_id) ) \n"; 914 919 /* lom_9_2_taxon_path, lom_9_2_2_taxons */ 915 920 $sql_9_2_manual = "\n((SELECT lom_id, lom_status_identifier, value, {$this->value_match_table}.rank, '9_2' as element, CAST({$this->value_match_table}.langstring_entries_id AS integer) as source_langstring_value_id AS source_langstring_value_id FROM lom NATURAL JOIN lom_has_lom_9_classification NATURAL JOIN lom_9_classification NATURAL JOIN lom_9_classification_has_lom_9_2_taxon_path NATURAL JOIN lom_9_2_taxon_path NATURAL JOIN lom_9_2_taxon_path_has_lom_9_2_2_taxons NATURAL JOIN lom_9_2_2_taxons JOIN {$this->value_match_table} ON (lom_9_2_2_taxons.lom_9_2_2_2_entry_langstrings_id={$this->value_match_table}.langstrings_id) ) \n"; … … 1003 1008 public function getNewestLOs($nb_objects = 5) { 1004 1009 global $db; 1005 $sql_theme_limit_where = self :: getSqlThemeLimitWhereSingle( );1010 $sql_theme_limit_where = self :: getSqlThemeLimitWhereSingle(null, true); 1006 1011 if (!empty ($sql_theme_limit_where)) { 1007 $sql_theme_limit_join = self :: getSqlLomThemeJoin( );1012 $sql_theme_limit_join = self :: getSqlLomThemeJoin(true); 1008 1013 } else { 1009 1014 $sql_theme_limit_join = null; //No need to join if there are no themes to restrict to. … … 1036 1041 } 1037 1042 $sql_candidate_lom_join = $this->getSqlVirtualHostCandidateLomJoin(); 1038 $sql_theme_limit_join = self :: getSqlLomThemeJoin( );1043 $sql_theme_limit_join = self :: getSqlLomThemeJoin($recursive); 1039 1044 $sql_theme_limit_where = self :: getSqlThemeLimitWhereSingle($theme, $recursive); 1040 1045 1041 1046 $sql = "SELECT count(DISTINCT(lom_id)) as count FROM lom $sql_candidate_lom_join $sql_theme_limit_join WHERE 1=1 $only_valid_where $sql_theme_limit_where"; 1042 $db->ExecuterSqlResUnique($sql, $row, true);1047 $db->ExecuterSqlResUnique($sql, $row, false); 1043 1048 return $row['count']; 1044 1049 } -
html/tests/VocabRelationshipNavigationTest.php
rf0daea6 re1377e9 9 9 class VocabRelationshipImportTest extends PHPUnit_Framework_TestCase 10 10 { 11 private $fixTurePersistent = true;11 private $fixTurePersistent = false; 12 12 13 13 private $pivotVocIdStr='pivotVoc'; 14 14 private $rVoc1IdStr='rVoc1'; 15 15 private $rVoc2IdStr='rVoc2'; 16 16 17 17 protected function setUp() 18 18 { … … 47 47 } 48 48 } 49 49 50 50 private function addAllLos($create=true) { 51 51 $los = array(); … … 66 66 return $los; 67 67 } 68 68 69 69 /** 70 70 * @param $oaiId string example: 'oai:eureka.coeus.ca:r1' … … 94 94 } 95 95 96 private function getThemeLOArray(Theme $theme ) {96 private function getThemeLOArray(Theme $theme, $recursive) { 97 97 $searchEngine = new SearchEngine(); 98 98 $searchEngine->setSearchLomStatus(null); 99 99 //$searchEngine->setSqlAdditionalWhereString(SearchEngine::ONLY_VALID_WHERE_SQL); 100 100 101 $searchEngine->addThemeLimit('AND', $theme, false);101 $searchEngine->addThemeLimit('AND', $theme, $recursive); 102 102 $searchEngine->executeSearch(); 103 103 $fiches_array = $searchEngine->getResultLOs(); … … 110 110 return $retval; 111 111 } 112 112 113 113 private function deleteEverything() 114 114 { … … 136 136 } 137 137 } 138 138 139 139 protected function tearDown() 140 140 { … … 143 143 } 144 144 } 145 145 146 146 /** Normally i'd do more than one test, but the fixtures are unbearably slow */ 147 public function test NoRegressionWhenVocabularyNavigationIsTurnedOff()148 { 149 $this->assertEquals($this->pivotVocIdStr, $this->pivotVoc->getId());147 public function testVocabularyNavigationWorks() 148 { 149 $this->assertEquals($this->pivotVocIdStr, $this->pivotVoc->getId()); 150 150 $this->assertEquals($this->rVoc1IdStr, $this->rVoc1->getId()); 151 151 $this->assertEquals($this->rVoc2IdStr, $this->rVoc2->getId()); 152 152 153 /* Check that the resources have been put in the right vocabularies, and that there are no regressi ngif navigation is disabled */153 /* Check that the resources have been put in the right vocabularies, and that there are no regression if navigation is disabled */ 154 154 global $NAVIGATE_VOC_RELATIONS_ENABLED; 155 155 $NAVIGATE_VOC_RELATIONS_ENABLED = false; 156 $this->assertEquals(array('oai:eureka.coeus.ca:r1'), $this->getThemeLOArray(Theme::getObject(array('rVoc1T1', 'rVoc1')))); 157 $this->assertEquals(array('oai:eureka.coeus.ca:r2'), $this->getThemeLOArray(Theme::getObject(array('rVoc1T2', 'rVoc1')))); 158 $this->assertEquals(array('oai:eureka.coeus.ca:r3'), $this->getThemeLOArray(Theme::getObject(array('pivotVocT1', 'pivotVoc')))); 159 $this->assertEquals(array('oai:eureka.coeus.ca:r4'), $this->getThemeLOArray(Theme::getObject(array('pivotVocT2', 'pivotVoc')))); 160 $this->assertEquals(array('oai:eureka.coeus.ca:r5'), $this->getThemeLOArray(Theme::getObject(array('pivotVocT3', 'pivotVoc')))); 161 $this->assertEquals(array('oai:eureka.coeus.ca:r6'), $this->getThemeLOArray(Theme::getObject(array('rVoc2T1', 'rVoc2')))); 162 $this->assertEquals(array('oai:eureka.coeus.ca:r7'), $this->getThemeLOArray(Theme::getObject(array('rVoc2T2', 'rVoc2')))); 163 $this->assertEquals(array('oai:eureka.coeus.ca:r8'), $this->getThemeLOArray(Theme::getObject(array('rVoc2T3', 'rVoc2')))); 164 $this->assertEquals(array('oai:eureka.coeus.ca:r9'), $this->getThemeLOArray(Theme::getObject(array('rVoc2T4', 'rVoc2')))); 165 $this->assertEquals(array('oai:eureka.coeus.ca:r10'), $this->getThemeLOArray(Theme::getObject(array('rVoc2T5', 'rVoc2')))); 166 $this->assertEquals(array('oai:eureka.coeus.ca:r11'), $this->getThemeLOArray(Theme::getObject(array('rVoc2T6', 'rVoc2')))); 167 $this->assertEquals(array('oai:eureka.coeus.ca:r12'), $this->getThemeLOArray(Theme::getObject(array('rVoc2T7', 'rVoc2')))); 168 $this->assertEquals(array('oai:eureka.coeus.ca:r13'), $this->getThemeLOArray(Theme::getObject(array('pivotVocT4', 'pivotVoc')))); 169 } 170 171 public function testVocabularyNavigationWorks() 172 { 173 global $NAVIGATE_VOC_RELATIONS_ENABLED; 156 $this->assertEquals(array('oai:eureka.coeus.ca:r1'), $this->getThemeLOArray(Theme::getObject(array('rVoc1T1', 'rVoc1')), false)); 157 $this->assertEquals(array('oai:eureka.coeus.ca:r2'), $this->getThemeLOArray(Theme::getObject(array('rVoc1T2', 'rVoc1')), false)); 158 $this->assertEquals(array('oai:eureka.coeus.ca:r3'), $this->getThemeLOArray(Theme::getObject(array('pivotVocT1', 'pivotVoc')), false)); 159 $this->assertEquals(array('oai:eureka.coeus.ca:r4'), $this->getThemeLOArray(Theme::getObject(array('pivotVocT2', 'pivotVoc')), false)); 160 $this->assertEquals(array('oai:eureka.coeus.ca:r5'), $this->getThemeLOArray(Theme::getObject(array('pivotVocT3', 'pivotVoc')), false)); 161 $this->assertEquals(array('oai:eureka.coeus.ca:r6'), $this->getThemeLOArray(Theme::getObject(array('rVoc2T1', 'rVoc2')), false)); 162 $this->assertEquals(array('oai:eureka.coeus.ca:r7'), $this->getThemeLOArray(Theme::getObject(array('rVoc2T2', 'rVoc2')), false)); 163 $this->assertEquals(array('oai:eureka.coeus.ca:r8'), $this->getThemeLOArray(Theme::getObject(array('rVoc2T3', 'rVoc2')), false)); 164 $this->assertEquals(array('oai:eureka.coeus.ca:r9'), $this->getThemeLOArray(Theme::getObject(array('rVoc2T4', 'rVoc2')), false)); 165 $this->assertEquals(array('oai:eureka.coeus.ca:r10'), $this->getThemeLOArray(Theme::getObject(array('rVoc2T5', 'rVoc2')), false)); 166 $this->assertEquals(array('oai:eureka.coeus.ca:r11'), $this->getThemeLOArray(Theme::getObject(array('rVoc2T6', 'rVoc2')), false)); 167 $this->assertEquals(array('oai:eureka.coeus.ca:r12'), $this->getThemeLOArray(Theme::getObject(array('rVoc2T7', 'rVoc2')), false)); 168 $this->assertEquals(array('oai:eureka.coeus.ca:r13'), $this->getThemeLOArray(Theme::getObject(array('pivotVocT4', 'pivotVoc')), false)); 169 174 170 $NAVIGATE_VOC_RELATIONS_ENABLED = true; 175 171 $expected = array('oai:eureka.coeus.ca:r1'); 176 $this->assertEquals($expected, $this->getThemeLOArray(Theme::getObject(array('rVoc1T1', 'rVoc1')))); 172 $this->assertEquals($expected, $this->getThemeLOArray(Theme::getObject(array('rVoc1T1', 'rVoc1')), true)); 173 174 $expected = array( 175 'oai:eureka.coeus.ca:r2', 176 'oai:eureka.coeus.ca:r4', 177 'oai:eureka.coeus.ca:r5', 178 'oai:eureka.coeus.ca:r7', 179 'oai:eureka.coeus.ca:r8', 180 'oai:eureka.coeus.ca:r9', 181 'oai:eureka.coeus.ca:r13' 182 ); 183 sort($expected); 184 $this->assertEquals($expected, $this->getThemeLOArray(Theme::getObject(array('rVoc1T2', 'rVoc1')),false), "Non-recursive navigation is broken!"); 177 185 178 186 $expected = array('oai:eureka.coeus.ca:r2', 179 'oai:eureka.coeus.ca:r4',180 'oai:eureka.coeus.ca:r5',181 'oai:eureka.coeus.ca:r7',182 'oai:eureka.coeus.ca:r8',183 'oai:eureka.coeus.ca:r9',184 'oai:eureka.coeus.ca:r12',185 'oai:eureka.coeus.ca:r13'186 );187 sort($expected);188 $this->assertEquals($expected, $this->getThemeLOArray(Theme::getObject(array('rVoc1T2', 'rVoc1'))));189 190 $expected = array('oai:eureka.coeus.ca:r3');191 $this->assertEquals($expected, $this->getThemeLOArray(Theme::getObject(array('pivotVocT1', 'pivotVoc'))), "Backward relationships must not be followed!");187 'oai:eureka.coeus.ca:r4', 188 'oai:eureka.coeus.ca:r5', 189 'oai:eureka.coeus.ca:r7', 190 'oai:eureka.coeus.ca:r8', 191 'oai:eureka.coeus.ca:r9', 192 'oai:eureka.coeus.ca:r12', 193 'oai:eureka.coeus.ca:r13' 194 ); 195 sort($expected); 196 $this->assertEquals($expected, $this->getThemeLOArray(Theme::getObject(array('rVoc1T2', 'rVoc1')),true), "Recursive navigation is broken!"); 197 198 $expected = array('oai:eureka.coeus.ca:r3'); 199 $this->assertEquals($expected, $this->getThemeLOArray(Theme::getObject(array('pivotVocT1', 'pivotVoc')),true), "Backward relationships must not be followed!"); 192 200 } 193 201 }
Note: See TracChangeset
for help on using the changeset viewer.
