Skip to content

Commit

Permalink
temporary commit
Browse files Browse the repository at this point in the history
  • Loading branch information
micgro42 committed Mar 22, 2018
1 parent d09b5b6 commit 94ff64e
Showing 1 changed file with 113 additions and 11 deletions.
124 changes: 113 additions & 11 deletions inc/Ui/Search.php
Expand Up @@ -192,27 +192,112 @@ protected function addSearchAssistanceElements(Form $searchForm, array $parsedQu
protected function addNamespaceSelector(Form $searchForm, array $parsedQuery)
{
$baseNS = empty($parsedQuery['ns']) ? '' : $parsedQuery['ns'][0];
$namespaces = [];
$searchForm->addTagOpen('div')->addClass('search-results-form__subwrapper');


if ($baseNS) {
$searchForm->addRadioButton('namespace', '(no namespace FIXME)')->val('');
$parts = [$baseNS => count($this->fullTextResults)];
$searchForm->addTagOpen('div');
$searchForm->addHTML('current: ');
$newQuery = ft_queryUnparser_simple(
$this->parsedQuery['and'],
[],
[],
[],
[]
);
$searchForm->addTagOpen('a')
->attrs([
'href' => wl($newQuery, ['do' => 'search'], false, '&')
])
;
$searchForm->addHTML('(no namespace FIXME)');
$searchForm->addTagClose('a');

$parts = [];
$upperNameSpace = $baseNS;
while ($upperNameSpace = getNS($upperNameSpace)) {
$parts[$upperNameSpace] = 0;
$parts[$upperNameSpace] = noNS($upperNameSpace);
}
$currentNS = array_reverse($parts);

foreach ($currentNS as $ns => $nsName) {
$searchForm->addHTML(' : ');
$newQuery = ft_queryUnparser_simple(
$this->parsedQuery['and'],
[],
[],
[$ns],
[]
);
$searchForm->addTagOpen('a')
->attrs([
'href' => wl($newQuery, ['do' => 'search'], false, '&')
])
;
$searchForm->addHTML($nsName);
$searchForm->addTagClose('a');
}
$namespaces = array_reverse($parts);
};
$searchForm->addHTML(' : ' . noNS($baseNS));

$searchForm->addTagClose('div');
}


$namespaces = array_merge($namespaces, $this->getAdditionalNamespacesFromResults($baseNS));
$searchForm->addTagOpen('div');
$searchForm->addHTML('first level ns below current: ');
$topNS = $this->getAdditionalNamespacesFromResults($baseNS);

foreach ($namespaces as $extraNS => $count) {
foreach ($topNS as $extraNS => $count) {
$searchForm->addHTML(' ');
$label = $extraNS . ($count ? " ($count)" : '');
$namespaceCB = $searchForm->addRadioButton('namespace', $label)->val($extraNS);
if ($extraNS === $baseNS) {
$namespaceCB->attr('checked', true);
$newQuery = ft_queryUnparser_simple(
$this->parsedQuery['and'],
[],
[],
[$extraNS],
[]
);

$searchForm->addTagOpen('a')
->attrs([
'href' => wl($newQuery, ['do' => 'search'], false, '&')
])
;
$searchForm->addHTML($label);
$searchForm->addTagClose('a');
}
$searchForm->addTagClose('div');


$searchForm->addTagOpen('div');
$searchForm->addHTML('top ns below current: ');
$topNS = $this->getTopNamespacesFromResults($baseNS);
$NUMBER_OF_TOP_NS = 5;
foreach ($topNS as $extraNS => $count) {
if ($NUMBER_OF_TOP_NS-- === 0) {
break;
}
$searchForm->addHTML(' ');

$label = $extraNS . ($count ? " ($count)" : '');
$newQuery = ft_queryUnparser_simple(
$this->parsedQuery['and'],
[],
[],
[$extraNS],
[]
);
$searchForm->addTagOpen('a')
->attrs([
'href' => wl($newQuery, ['do' => 'search'], false, '&')
])
;
$searchForm->addHTML($label);
$searchForm->addTagClose('a');

}
$searchForm->addTagClose('div');


$searchForm->addTagClose('div');
}
Expand Down Expand Up @@ -247,6 +332,23 @@ protected function getAdditionalNamespacesFromResults($baseNS)
return $namespaces;
}

protected function getTopNamespacesFromResults($baseNS)
{
$namespaces = [];
foreach ($this->fullTextResults as $page => $numberOfHits) {
$namespace = getNS($page);
while ($namespace && $namespace !== $baseNS) {
if (empty($namespaces[$namespace])) {
$namespaces[$namespace] = 0;
}
$namespaces[$namespace] += 1;
$namespace = getNS($namespace);
}
}
arsort($namespaces);
return $namespaces;
}

/**
* Build the intro text for the search page
*
Expand Down

0 comments on commit 94ff64e

Please sign in to comment.