[IMPR] Minor search improvements

This commit is contained in:
Tony Air 2023-04-28 19:49:03 +02:00
parent 56a58e3d6c
commit 0e70a5c690
2 changed files with 26 additions and 19 deletions

View File

@ -15,6 +15,7 @@ use SilverStripe\Control\Controller;
use SilverStripe\Control\Director; use SilverStripe\Control\Director;
use SilverStripe\Control\HTTPRequest; use SilverStripe\Control\HTTPRequest;
use SilverStripe\Core\Config\Config; use SilverStripe\Core\Config\Config;
use SilverStripe\ErrorPage\ErrorPage;
use SilverStripe\Forms\FieldList; use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form; use SilverStripe\Forms\Form;
use SilverStripe\Forms\FormAction; use SilverStripe\Forms\FormAction;
@ -93,7 +94,7 @@ class PageController extends ContentController
__FUNCTION__, __FUNCTION__,
FieldList::create( FieldList::create(
TextField::create('q', 'Search ...') TextField::create('q', 'Search ...')
->setAttribute('placeholder', 'Search ' . $config->getField('Title') . ' Website') ->setAttribute('placeholder', 'What are you looking for?')
), ),
FieldList::create( FieldList::create(
FormAction::create( FormAction::create(
@ -135,6 +136,7 @@ class PageController extends ContentController
$pages = SiteTree::get()->filterAny([ $pages = SiteTree::get()->filterAny([
'Title:PartialMatch' => $term, 'Title:PartialMatch' => $term,
'Content:PartialMatch' => $term, 'Content:PartialMatch' => $term,
'ClassName:not' => ErrorPage::class,
])->sort('Created DESC'); ])->sort('Created DESC');
$results->merge($pages); $results->merge($pages);
@ -166,7 +168,12 @@ class PageController extends ContentController
); );
foreach ($elements as $element) { foreach ($elements as $element) {
$page = $element->Page(); $page = $element->getPage();
if (!$element->hasMethod('getPage')) {
continue;
}
if (! $page) { if (! $page) {
continue; continue;
} }

View File

@ -10,29 +10,29 @@
<div class="element element-search-results"> <div class="element element-search-results">
<div class="element-container {$Top.DefaultContainer}"> <div class="element-container {$Top.DefaultContainer}">
<% if $Results %> <% if $Results %>
<div id="SearchAccordion{$ID}"> <div id="SearchAccordion{$ID}" class="accordion accordion-flush">
<% loop $Results %> <% loop $Results %>
<div class="card"> <div class="accordion-item">
<div class="card-header" id="Heading{$ID}{$Up.ID}"> <h3 class="accordion-header">
<h3 <button
class="mb-0 a" class="accordion-button collapsed"
type="button"
data-bs-toggle="collapse" data-bs-toggle="collapse"
data-bs-target="#Collapse{$ID}{$Up.ID}" data-bs-target="#Collapse{$ID}{$Up.ID}"
aria-expanded="false" aria-expanded="false"
aria-controls="Collapse{$ID}{$Up.ID}" aria-controls="Collapse{$ID}{$Up.ID}"
> >
$Title $Title
<i class="fas fa-plus accordion-icon pull-right"></i> </button>
</h3> </h3>
</div>
<div <div
id="Collapse{$ID}{$Up.ID}" id="Collapse{$ID}{$Up.ID}"
class="collapse" class="accordion-collapse collapse"
aria-labelledby="Heading{$ID}{$Up.ID}" aria-labelledby="Heading{$ID}{$Up.ID}"
data-bs-parent="#SearchAccordion{$Up.ID}" data-bs-parent="#SearchAccordion{$Up.ID}"
> >
<div class="card-body"> <div class="accordion-body">
<p>$Summary(100)</p> <p>$Summary(100)</p>
<a href="{$Link}">Learn More</a> <a href="{$Link}">Learn More</a>
</div> </div>
@ -41,7 +41,7 @@
<% end_loop %> <% end_loop %>
</div> </div>
<% else %> <% else %>
<h3>Nothing was found.</h3> <h3 class="alert alert-danger not-found">Nothing was found.</h3>
<% end_if %> <% end_if %>
</div> </div>
</div> </div>