How Can I filter the Solr search results by Department?
Departments are the top level pages under which many pages will exists.
I tried by adding following changes in SolrSearchExtension.php and SolrSearchPage.php . But Pagination does not work with it
SolrSearchExtension.php
function SearchForm() {
$searchText = isset($_REQUEST['Search']) ? $_REQUEST['Search'] : 'Search';
$fields = new FieldSet(
new TextField("Search", "", $searchText)
new DropdownField("PageID", "", DataObject::get("SiteTree", "\"ShowInMenus\" = 1 AND \"ParentID\" = 0 AND Title NOT IN ('Technical Support','Forum','Wiki')")->map("ID", "Title",
"Please Select"))
);
$actions = new FieldSet(
new FormAction('results', 'Search')
);
return new SearchForm($this->owner, "SearchForm", $fields, $actions);
}
SolrSearchPage.php
function results($data = null, $form = null){
.....
$pageId = isset($_GET['PageID']) ? Convert::raw2xml($_GET['PageID']) : '';
if($query) {
$result = $query->getDataObjects();
if(!empty($pageId)) {
foreach($result as $key => $page)
{
$temp = $page;
while($temp->Parent) {
$temp = $temp->Parent();
}
if($temp->ID != $pageId) {
$result->remove($page);
}
}
}
} else {
$result = new DataObjectSet();
}
$data = array(
'Results' => $result,
'Query' => $term,
'Title' => 'Search Results'
);
...
}