From 903b5b80403eb17c9ac1a0a950ba9730de9af6fd Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Tue, 25 Mar 2014 14:17:14 -0400 Subject: [PATCH] Improved test coverage. --- module/VuFind/tests/fixtures/spell/query1 | Bin 0 -> 141 bytes module/VuFind/tests/fixtures/spell/spell1 | Bin 0 -> 2402 bytes .../Search/Solr/SpellingProcessorTest.php | 159 ++++++++++++++++++ 3 files changed, 159 insertions(+) create mode 100755 module/VuFind/tests/fixtures/spell/query1 create mode 100755 module/VuFind/tests/fixtures/spell/spell1 diff --git a/module/VuFind/tests/fixtures/spell/query1 b/module/VuFind/tests/fixtures/spell/query1 new file mode 100755 index 0000000000000000000000000000000000000000..7f5895751aa30d1b854e953e5f8fa46b1c467bd6 GIT binary patch literal 141 zcmeabGBUAJ3M+NX%u5MQO)N^zhzTrBEvkf&N>;{J)x}nZrdCP}S`39C36I3Ql$_Ke zCF^1<ODiSEoE*2z)SQ%J5Z@4J5=>ceNl|8AI#?8_IlZVfHz_AoA-yOQM1zG5!HV+> PQi~Ex@`2|0S=RypkmoGX literal 0 HcmV?d00001 diff --git a/module/VuFind/tests/fixtures/spell/spell1 b/module/VuFind/tests/fixtures/spell/spell1 new file mode 100755 index 0000000000000000000000000000000000000000..9eec9b3affd1ce671893f93224e8c2cbc8a8024c GIT binary patch literal 2402 zcmeH}%}(nu5QTXZ<Rz;(P1<y_0;De3RHD*dWs@H_7!n8UL|jzm-I*~4lHhySEV}H} zpXbcX@hE$U17LrKomAC9<hp#wZu0U;s46>jjn3|cdG3@E*`4WBc6b&|Q$C3DiNOj^ z1`=QwR~Nm|tzqdca1QKR>-=qBJc_bsz=Kr+r@tT}NOK4Y*#N8c&=!qg7>eC3YG`-e zpemM1yd^dED%0n>-ye@g^b`*;yak5ZzGEAVp@>e)dZ)z;9Se!ZqRdd&!t}CJlnAAr zCMqIeubswp7I%U){ltHc?xrXmQO&3D39<(ES;8C$hzLCdR$Y1#9uu<iBfTG45fb^4 zTFZ~#&V+4<i2X$2O=5GbJp|TXyYbCZSYYD;a6GoZQsKmB2)D8lKjYeEM>LtqmMYo) z7kOKxSrfv)3^<u1N^@z@zB6e!m2q@tbq)2KHA0STzwl~;;iXq`)IZEh{{3mz=wDt% z8};4+bF7c5^fbmkI9b>SH>)w^g!tTQM<!d-h-EKB`zCyLbxht=%P}X^%Q0;shX790 zRy>Pq<7E)q-p}K&op3qvFAwc8Bg#%yIUU`fx0P+PeSha|^}VUj+v>cne%-bz@QY;} F-vPaJ>fitX literal 0 HcmV?d00001 diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/Search/Solr/SpellingProcessorTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/Search/Solr/SpellingProcessorTest.php index 7b72fc8f0bc..359c0d461c2 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/Search/Solr/SpellingProcessorTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/Search/Solr/SpellingProcessorTest.php @@ -69,6 +69,154 @@ class SpellingProcessorTest extends TestCase $this->assertEquals(5, $sp->getSpellingLimit()); } + /** + * Test suggestion processing. + * + * @return void + */ + public function testSuggestionProcessing() + { + $sp = new SpellingProcessor(); + $spelling = $this->getFixture('spell1'); + $query = $this->getFixture('query1'); + $this->assertEquals( + array( + 'grumble' => array( + 'freq' => 2, + 'suggestions' => array( + 'grumbler' => 4, + 'rumble' => 40, + 'crumble' => 15, + ), + ), + 'grimble' => array( + 'freq' => 7, + 'suggestions' => array( + 'trimble' => 110, + 'gribble' => 21, + 'grimsley' => 24 + ), + ), + ), + $sp->getSuggestions($spelling, $query) + ); + } + + /** + * Test suggestion processing. + * + * @return void + */ + public function testSuggestionProcessingWithNonDefaultLimit() + { + $config = new Config(array('limit' => 5)); + $sp = new SpellingProcessor($config); + $spelling = $this->getFixture('spell1'); + $query = $this->getFixture('query1'); + $this->assertEquals( + array( + 'grumble' => array( + 'freq' => 2, + 'suggestions' => array( + 'grumbler' => 4, + 'rumble' => 40, + 'crumble' => 15, + 'trumble' => 13, + 'brumble' => 3, + ), + ), + 'grimble' => array( + 'freq' => 7, + 'suggestions' => array( + 'trimble' => 110, + 'gribble' => 21, + 'grimsley' => 24, + 'grimalde' => 8, + ), + ), + ), + $sp->getSuggestions($spelling, $query) + ); + } + + /** + * Test basic suggestions. + * + * @return void + */ + public function testBasicSuggestions() + { + $suggestions = array( + 'grumble' => array( + 'freq' => 2, + 'suggestions' => array( + 'grumbler' => 4, + 'rumble' => 40, + 'crumble' => 15, + ), + ), + 'grimble' => array( + 'freq' => 7, + 'suggestions' => array( + 'trimble' => 110, + 'gribble' => 21, + 'grimsley' => 24 + ), + ), + ); + $spelling = $this->getFixture('spell1'); + $query = $this->getFixture('query1'); + $params = $this->getServiceManager()->get('VuFind\SearchParamsPluginManager') + ->get('Solr'); + $params->setBasicSearch($query->getString(), $query->getHandler()); + $sp = new SpellingProcessor(); + $this->assertEquals( + array( + 'grumble' => array( + 'freq' => 2, + 'suggestions' => array( + 'grumbler' => array( + 'freq' => 4, + 'new_term' => 'grumbler', + 'expand_term' => '(grumble OR grumbler)', + ), + 'rumble' => array( + 'freq' => 40, + 'new_term' => 'rumble', + 'expand_term' => '(grumble OR rumble)', + ), + 'crumble' => array( + 'freq' => 15, + 'new_term' => 'crumble', + 'expand_term' => '(grumble OR crumble)', + ), + ), + ), + 'grimble' => array( + 'freq' => 7, + 'suggestions' => array( + 'trimble' => array( + 'freq' => 110, + 'new_term' => 'trimble', + 'expand_term' => '(grimble OR trimble)', + ), + 'gribble' => array( + 'freq' => 21, + 'new_term' => 'gribble', + 'expand_term' => '(grimble OR gribble)', + ), + 'grimsley' => array( + 'freq' => 24, + 'new_term' => 'grimsley', + 'expand_term' => '(grimble OR grimsley)', + ), + ), + ), + ), + $sp->processSuggestions($suggestions, $spelling->getQuery(), $params) + ); + } + /** * Test that spelling tokenization works correctly. * @@ -98,4 +246,15 @@ class SpellingProcessorTest extends TestCase $this->assertEquals(array('"'), $sp->tokenize('"')); $this->assertEquals(array('""'), $sp->tokenize('""')); } + + /** + * Get a fixture object + * + * @return mixed + */ + protected function getFixture($file) + { + $fixturePath = realpath(__DIR__ . '/../../../../../fixtures/spell') . '/'; + return unserialize(file_get_contents($fixturePath . $file)); + } } -- GitLab