This repository has been archived by the owner on Apr 6, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:yhahn/searchlight
- Loading branch information
Showing
13 changed files
with
282 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
/** | ||
* Facet plugin class for language. | ||
*/ | ||
class SearchlightFacetLanguage extends SearchlightFacet { | ||
/** | ||
* Override of query(). | ||
* Merges null value filtering with the site default language. | ||
*/ | ||
function query(&$query) { | ||
// Filter the query if there is an active facet value. | ||
if (isset($this->value)) { | ||
$default = language_default('language'); | ||
if (empty($this->value) || $this->value === $default) { | ||
$query->search_filter[] = array( | ||
'field' => $this->name, | ||
'operator' => 'IN', | ||
'args' => array('', $default), | ||
); | ||
} | ||
else { | ||
$query->search_filter[] = array( | ||
'field' => $this->name, | ||
'operator' => '=', | ||
'args' => array($this->value), | ||
); | ||
} | ||
} | ||
|
||
// Add this facet to be built by the backend. | ||
$limit = isset($this->options['items']) ? $this->options['items'] : 5; | ||
$query->add_search_facet($this->name, $limit); | ||
} | ||
|
||
/** | ||
* Override of render(). | ||
* Merges null value facet with the site default language facet. | ||
*/ | ||
function render($query, $delta) { | ||
switch ($delta) { | ||
case 'active': | ||
if (isset($this->value)) { | ||
$items = array($this->value => array('id' => $this->value)); | ||
} | ||
break; | ||
case 'facets': | ||
if (!isset($this->value)) { | ||
$items = $query->get_search_facet($this->name); | ||
} | ||
break; | ||
} | ||
if (!empty($items) && $this->viewInit($query)) { | ||
$default = language_default('language'); | ||
if (isset($items[$default], $items[''])) { | ||
$items[$default]['count'] = $items[$default]['count'] + $items['']['count']; | ||
unset($items['']); | ||
} | ||
return $this->viewRenderItems($items); | ||
} | ||
return array(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.