Changeset e1377e9


Ignore:
Timestamp:
08/31/10 18:47:18 (21 months ago)
Author:
Benoit Grégoire <benoitg@…>
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
Message:

All tests now pass for vocabulary navigation

Location:
html
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • html/classes/SearchEngine.php

    rf2cb64b re1377e9  
    169169    } 
    170170 
    171     /** SQL fragment to limit a query to the candidate LO thaking the virtual host's themes and languages 
     171    /** SQL fragment to limit a query to the candidate LO taking the virtual host's themes and languages 
    172172     * in consideration.  Note that this query will return null if there 
    173173     * are no virtual host restrictions 
     
    480480        //var_dump($this->theme_limit_array); 
    481481        foreach ($this->theme_limit_array as $theme_limit) { 
    482             $sql_theme_limit_join = self :: getSqlLomThemeJoin(); 
    483482            //pretty_print_r($theme_limit); 
    484483            $term_id = $theme_limit['theme']->getId(); 
     
    548547            $sql_or_array = array(); 
    549548            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']); 
    551550                //pretty_print_r($theme_limit); 
    552551                $sql_theme_limit_where = self :: getSqlThemeLimitWhereSingle($theme_limit['theme'], $theme_limit['recursive']); 
     
    616615     * @return true 
    617616     */ 
    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) { 
    619618        if($finalJoin) { 
    620619            $finalJoinTable = $finalTable; 
     
    624623        } 
    625624        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); 
    627626        } 
    628627        if($navLevel==1) { 
     
    737736                $vocIdcoalesceParts[]="{$table}.vdex_4_vocabulary_identifier"; 
    738737                $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                } 
    740745            } 
    741746            /* Re-joining with vocabulary_term is essential to exploit the nested-set structure later */ 
     
    762767     * BUT there may be exceptions.  Example:  One may want to search by keywords including all navigated terms. 
    763768     *  */ 
    764     static private function getSqlLomThemeJoin() { 
     769    static private function getSqlLomThemeJoin($recursive) { 
    765770        $retval =  null; 
    766771 
     
    781786                $selectListArray=array(); 
    782787                $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); 
    784789                $selectList = implode(", \n ", $selectListArray); 
    785790                $sql = "SELECT $selectList \n"; 
     
    795800            $sqlJoin=null; 
    796801 
    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); 
    798803 
    799804            $retval .= " $sqlJoin \n"; 
     
    874879 
    875880        // Limit to specific theme$this->additional_join_string 
    876         $sql_theme_limit_where = self :: getSqlThemeLimitWhere(); 
     881        $sql_theme_limit_where = self :: getSqlThemeLimitWhere(null, true); 
    877882        if (!empty ($sql_theme_limit_where)) { 
    878             $sql_theme_limit_join = self :: getSqlLomThemeJoin(); 
     883            $sql_theme_limit_join = self :: getSqlLomThemeJoin(true); 
    879884        } else { 
    880885            $sql_theme_limit_join = null; //No need to join if there are no themes to restrict to. 
     
    911916            $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"; 
    912917            /* 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"; 
    914919            /* lom_9_2_taxon_path, lom_9_2_2_taxons */ 
    915920            $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"; 
     
    10031008    public function getNewestLOs($nb_objects = 5) { 
    10041009        global $db; 
    1005         $sql_theme_limit_where = self :: getSqlThemeLimitWhereSingle(); 
     1010        $sql_theme_limit_where = self :: getSqlThemeLimitWhereSingle(null, true); 
    10061011        if (!empty ($sql_theme_limit_where)) { 
    1007             $sql_theme_limit_join = self :: getSqlLomThemeJoin(); 
     1012            $sql_theme_limit_join = self :: getSqlLomThemeJoin(true); 
    10081013        } else { 
    10091014            $sql_theme_limit_join = null; //No need to join if there are no themes to restrict to. 
     
    10361041        } 
    10371042        $sql_candidate_lom_join = $this->getSqlVirtualHostCandidateLomJoin(); 
    1038         $sql_theme_limit_join = self :: getSqlLomThemeJoin(); 
     1043        $sql_theme_limit_join = self :: getSqlLomThemeJoin($recursive); 
    10391044        $sql_theme_limit_where = self :: getSqlThemeLimitWhereSingle($theme, $recursive); 
    10401045 
    10411046        $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); 
    10431048        return $row['count']; 
    10441049    } 
  • html/tests/VocabRelationshipNavigationTest.php

    rf0daea6 re1377e9  
    99class VocabRelationshipImportTest extends PHPUnit_Framework_TestCase 
    1010{ 
    11     private $fixTurePersistent = true; 
     11    private $fixTurePersistent = false; 
    1212 
    1313    private $pivotVocIdStr='pivotVoc'; 
    1414    private $rVoc1IdStr='rVoc1'; 
    1515    private $rVoc2IdStr='rVoc2'; 
    16      
     16 
    1717    protected function setUp() 
    1818    { 
     
    4747        } 
    4848    } 
    49      
     49 
    5050    private function addAllLos($create=true) { 
    5151        $los = array(); 
     
    6666        return $los; 
    6767    } 
    68      
     68 
    6969    /** 
    7070     * @param $oaiId string example:  'oai:eureka.coeus.ca:r1' 
     
    9494    } 
    9595 
    96     private function getThemeLOArray(Theme $theme) { 
     96    private function getThemeLOArray(Theme $theme, $recursive) { 
    9797        $searchEngine = new SearchEngine(); 
    9898        $searchEngine->setSearchLomStatus(null); 
    9999        //$searchEngine->setSqlAdditionalWhereString(SearchEngine::ONLY_VALID_WHERE_SQL); 
    100100 
    101         $searchEngine->addThemeLimit('AND', $theme, false); 
     101        $searchEngine->addThemeLimit('AND', $theme, $recursive); 
    102102        $searchEngine->executeSearch(); 
    103103        $fiches_array = $searchEngine->getResultLOs(); 
     
    110110        return $retval; 
    111111    } 
    112      
     112 
    113113    private function deleteEverything() 
    114114    { 
     
    136136        } 
    137137    } 
    138      
     138 
    139139    protected function tearDown() 
    140140    { 
     
    143143        } 
    144144    } 
    145      
     145 
    146146    /** Normally i'd do more than one test, but the fixtures are unbearably slow */ 
    147     public function testNoRegressionWhenVocabularyNavigationIsTurnedOff() 
    148     { 
    149         $this->assertEquals($this->pivotVocIdStr, $this->pivotVoc->getId()); 
     147    public function testVocabularyNavigationWorks() 
     148    { 
     149                $this->assertEquals($this->pivotVocIdStr, $this->pivotVoc->getId()); 
    150150        $this->assertEquals($this->rVoc1IdStr, $this->rVoc1->getId()); 
    151151        $this->assertEquals($this->rVoc2IdStr, $this->rVoc2->getId()); 
    152152 
    153         /* Check that the resources have been put in the right vocabularies, and that there are no regressing if 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 */ 
    154154        global $NAVIGATE_VOC_RELATIONS_ENABLED; 
    155155        $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         
    174170        $NAVIGATE_VOC_RELATIONS_ENABLED = true; 
    175171        $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!"); 
    177185 
    178186        $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!"); 
    192200    } 
    193201} 
Note: See TracChangeset for help on using the changeset viewer.