Skip to content

Commit

Permalink
Fix index histogram minlen parameter for metadata keys
Browse files Browse the repository at this point in the history
This includes a test for the minlen parameter for metadata keys
  • Loading branch information
michitux committed Jul 28, 2012
1 parent 92a5d12 commit 9a9b579
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
19 changes: 19 additions & 0 deletions _test/tests/inc/indexer_histogram.test.php
@@ -0,0 +1,19 @@
<?php
/**
* Tests the histogram function of the indexer.
*
* @author Michael Hamann <michael@content-space.de>
*/
class indexer_histogram_test extends DokuWikiTest {
function test_minlength() {
$indexer = idx_get_indexer();
$indexer->addMetaKeys('histo1', 'testkey', array('foo', 'bar', 'foobar'));
$indexer->addMetaKeys('histo2', 'testkey', array('bar', 'testing'));
$indexer->addMetaKeys('histo3', 'testkey', array('foo', 'foobar'));
$histogram4 = $indexer->histogram(1, 0, 4, 'testkey');
$this->assertEquals(array('foobar' => 2, 'testing' => 1), $histogram4);
$histogram2 = $indexer->histogram(1, 0, 2, 'testkey');
$this->assertEquals(array('foobar' => 2, 'testing' => 1, 'foo' => 2, 'bar' => 2), $histogram2);
}

}
8 changes: 5 additions & 3 deletions inc/indexer.php
Expand Up @@ -755,13 +755,15 @@ public function histogram($min=1, $max=0, $minlen=3, $key=null) {
$val_idx = array();
foreach ($index as $wid => $line) {
$freq = $this->countTuples($line);
if ($freq >= $min && (!$max || $freq <= $max) && strlen($val) >= $minlen)
if ($freq >= $min && (!$max || $freq <= $max))
$val_idx[$wid] = $freq;
}
if (!empty($val_idx)) {
$words = $this->getIndex($metaname.'_w', '');
foreach ($val_idx as $wid => $freq)
$result[$words[$wid]] = $freq;
foreach ($val_idx as $wid => $freq) {
if (strlen($words[$wid]) >= $minlen)
$result[$words[$wid]] = $freq;
}
}
}
else {
Expand Down

0 comments on commit 9a9b579

Please sign in to comment.