function test_search_by_id_returns_single_record() { # Check that searching for an ID only gives you one result $test_items = array('TKI80868', 'TKI80039', 'TKI80875'); foreach ($test_items as $value) { $solr = new Solr(); $this->assertEqual(1, $solr->count($value), Helpers::search_link($value) . " should return only 1 result"); } }
function test_staging_urls_return_no_matches() { # Test paths for common staging urls $test_items = array('staging.internal', 'dev.internal', 'preprod'); foreach ($test_items as $value) { $solr = new Solr(); $this->assertEqual(0, $solr->count($value), "Search for " . Helpers::search_link($value) . " returns " . $solr->count() . " results, when none should be returned"); } }
function test_community_names_return_homepage_as_first_result() { # Check that first result for each query is appropriate # homepage id $test_items = array('english online' => 'TKI80868', 'assessment online' => 'TKI58274', 'assessment' => 'TKI58274', 'education for enterprise' => 'TKI45249', 'digistore' => 'TKI59990', 'alternative education' => 'TKI17383', 'digital technology guidelines' => 'TKI50586', 'dtg' => 'TKI50586', 'e-asttle' => 'TKI38879', 'education for sustainability' => 'TKI50157', 'literacy online' => 'TKI58077', 'education outside the classroom' => 'TKI58260', 'esol online' => 'TKI13739', 'gifted and talented' => 'TKI17424', 'gifted and talented online' => 'TKI17424', 'he kohinga rauemi a-ipurangi' => 'TKI50637', 'new zealand curriculum' => 'TKI46672', 'tax citizenship' => 'TKI80668', 'arts online' => 'TKI31449', 'arts' => 'TKI31449', 'educational leaders' => 'TKI57127', 'home-school partnerships' => 'TKI59527', 'home school partnerships' => 'TKI59527', 'te tere auraki' => 'TKI28409', 'success for boys' => 'TKI50135', 'software for learning' => 'TKI50191'); foreach ($test_items as $key => $value) { $solr = new Solr(); $this->assertEqual($value, $solr->first($key), "{$value} wasn't first result for query " . Helpers::search_link($key)); } }
function test_phrases_in_index_return_matches() { # Checks first that searching for the phrase inside quotes does match # If it does, checks for matches without quotes. $test_items = array('"animals in circuses"', '"This Chinese official"', '"This Taihape Area School"', '"refers to Waitangi as"', '"posted on any forum"', '"highest level of their interest and ability"'); foreach ($test_items as $value) { $solr = new Solr(); if ($solr->count($value) >= 1) { $value = trim($value, '"'); $solr = new Solr(); $this->assertNotEqual(0, $solr->count($value), Helpers::search_link($value) . " has " . $solr->count() . " results"); } } }
function assessSimilarity($array, $strict = 1, $drift = 2) { foreach ($array as $key => $value) { $solr = new Solr(); $results = $solr->search($key, count($value) * $drift); $matches = 0; foreach ($results as $pid) { if (in_array($pid, $value)) { $matches++; } } $this->assertTrue($matches * $strict >= count($value), "Search for " . Helpers::search_link($key) . " returned " . $matches . " of it's expected results in the top " . count($value) * $drift); } }
function test_legacy_paths_not_indexed_with_nonlegacy_domains() { # Searches for legacy urls on non-legacy domains, like: # gifted.tki.org.nz/m/search/ $test_domains = array('gifted.tki.org.nz', 'www.wicked.org.nz', 'assessment.tki.org.nz', 'nzcurriculum.tki.org.nz', 'secondary.tki.org.nz', 'englishonline.tki.org.nz', 'artsonline.tki.org.nz'); $test_paths = array('/e/community/ncea/', '/e/community/maorieducation/', '/e/community/pasifika/', '/m/search/', '/e/search/', '/r/literacy_numeracy/professional/teachers_notes/ready_to_read/'); foreach ($test_domains as $domain) { foreach ($test_paths as $path) { $solr = new Solr(); $query = $domain . $path; $this->assertEqual(0, $solr->count($query), Helpers::search_link($query) . " should return no results"); } } }
function test_nzmaths_where_appropriate() { # Checks that first 10 results for nzmaths related keywords # return good proportion of MZMaths items. Ensures fix for # previous function doesn't work too well. $test_items = array('ALiM school stories nzmaths', 'Algebra information', 'Attribute Blocks: Exploring Shape', 'scuba'); foreach ($test_items as $value) { $solr = new Solr(); $pids = $solr->search($value, 50); $i = 0; foreach ($pids as $id) { if (preg_match('/nzmaths/', $id)) { $i++; } } $this->assertTrue($i > 0, "Search for " . Helpers::search_link($value) . " has insufficient nzmaths items"); } }