Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All facets. #10

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 22 additions & 0 deletions module/VuFind/src/VuFind/Controller/AjaxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1334,4 +1334,26 @@ protected function getResultsManager()
{
return $this->getServiceLocator()->get('VuFind\SearchResultsPluginManager');
}

/**
* Return all facet values for the total expansion module
*
* @return \Zend\Http\Response
*/
public function getAllFacetValuesAjax() {
$query = $this->getRequest()->getQuery();
if(empty($query['facetFields'])) {
return $this->output($this->translate('Empty field'), self::STATUS_ERROR);
}
$sm = $this->getSearchManager();
$params = $sm->setSearchClassId('Solr')->getParams();
$params->initFromRequest($this->getRequest()->getQuery());
foreach ($this->params()->fromQuery('hf', array()) as $hf) {
$params->getOptions()->addHiddenFilter($hf);
}
$results = $sm->setSearchClassId('Solr')->getResults($params);
$facets = $results->getFullFieldFacets($query['facetFields'], true, -1, 'count');

return $this->output($facets, self::STATUS_OK);
}
}
29 changes: 29 additions & 0 deletions themes/blueprint/js/check_all_facets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
function loadAllFacets() {
var expandedFacets = ['authorStr','topic'];
var facet_length = <?=$this->facet_limit ?> | 0;
for(var j=0;j<expandedFacets.length;j++) {
var url = path + '/AJAX/json<?=html_entity_decode($results->getUrlQuery()->getParams()) ?>&method=getAllFacetValues&facetFields[]=' + encodeURIComponent(expandedFacets[j]);
$.getJSON(url, function (data) {
for(var i in data.data) {
var allFacets = {
'label': data.data[i].data.label,
'list' : data.data[i].data.list.slice(facet_length)
};
if(allFacets.list.length > 0) {
var html = '<dl class="narrowList navmenu offscreen" id="allGroupHidden_'+allFacets.label+'">';
var url_base = '<?=$this->currentPath().$results->getUrlQuery()->getParams() ?>';
for(var i=0;i<allFacets.list.length;i++) {
html += '<dd><a href="'+url_base+'&filter[]='+allFacets.label+':'+encodeURI(allFacets.list[i].value)+'">'+allFacets.list[i].displayText+'</a> ('+allFacets.list[i].count+')</dd>';
}
html += '<dd><a href="#" onclick="lessFacets(\''+allFacets.label+'\'); return false;"><?=$this->transEsc('less')?> ...</a></dd></dl>';
$(html).insertAfter('#narrowGroupHidden_'+allFacets.label);
$('#narrowGroupHidden_'+allFacets.label).append('<dd><a href="#" onclick="allFacets(\''+allFacets.label+'\'); return false;"><?=$this->transEsc('all')?> ...</a></dd>')
}
}
});
}
}

$(document).ready(function() {
loadAllFacets();
});
6 changes: 6 additions & 0 deletions themes/blueprint/js/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ function moreFacets(name) {
function lessFacets(name) {
$("#more"+name).show();
$("#narrowGroupHidden_"+name).addClass("offscreen");
$("#allGroupHidden_"+name).addClass("offscreen");
}

function allFacets(name) {
$("#more"+name).hide();
$("#allGroupHidden_"+name).removeClass("offscreen");
}

function filterAll(element, formId) {
Expand Down
2 changes: 1 addition & 1 deletion themes/blueprint/templates/search/results.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
// Load Javascript dependencies into header:
$this->headScript()->appendFile("check_item_statuses.js");
$this->headScript()->appendFile("check_save_statuses.js");
$this->headScript()->appendFile("check_all_facets.js");
?>
<div class="<?=$this->layoutClass('mainbody')?>">
<? if (($recordTotal = $this->results->getResultTotal()) > 0): // only display these at very top if we have results ?>
Expand Down Expand Up @@ -125,4 +126,3 @@
<? /* End Narrow Search Options */ ?>

<div class="clear"></div>