Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Solr search by Department


Go to End


678 Views

Avatar
Praveen

Community Member, 49 Posts

2 October 2014 at 12:07am

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'
);

...
}