Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ The built-in SilverStripe search form is a very simple search engine. This plugi

# Requirements

* SilverStripe 4
* Silverstripe 6
* For Silverstripe 4/5 see 1.x


# Usage
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
]
},
"require": {
"silverstripe/cms": "^4 || ^5",
"silverstripe/framework": "^4 || ^5",
"silverstripe/vendor-plugin": "^1 || ^2"
"silverstripe/cms": "^6",
"silverstripe/framework": "^6",
"silverstripe/vendor-plugin": "^3"
},
"minimum-stability": "dev"
}
35 changes: 20 additions & 15 deletions src/IndexPageContentForSearchTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,36 @@
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Core\Config\Config;
use SilverStripe\ORM\Queries\SQLUpdate;
use SilverStripe\PolyExecution\PolyOutput;
use Symfony\Component\Console\Input\InputInterface;

class IndexPageContentForSearchTask extends BuildTask
{
protected $title = 'Index Page Content for Search';
protected string $title = 'Index Page Content for Search';
protected static string $description = 'Collate all page content from elements and save to a field for search. Add optional query string, "reindex=true" to reindex all pages.';

protected $description = 'Collate all page content from elements and save to a field for search. Add optional query string, "reindex=true" to reindex all pages.';

public function run($request)
public function execute(InputInterface $input, PolyOutput $output): int
{
$reindex = $request->getVar('reindex');
$offset = $request->getVar('offset') ? $request->getVar('offset') : NULL;
$limit = $request->getVar('limit') ? $request->getVar('limit') : 10;
$reindex = $input->getArgument('reindex');
$offset = $input->getArgument('offset') ? $input->getArgument('offset') : NULL;
$limit = $input->getArgument('limit') ? $input->getArgument('limit') : 10;

// select all sitetree items
$items = SiteTree::get()->limit($limit, $offset);
echo 'Running...<br />';
echo 'limit: ' . $limit . '<br />';
echo 'offset: ' . $offset . '<br />';
$output->writeln('Running...');
$output->writeln('limit: ' . $limit);
$output->writeln('offset: ' . $offset);
// echo 'count ' . $items->Count(). '<br />';

if(!$reindex) {
if (!$reindex) {
$items = $items->filter(['ElementalSearchContent' => null]);
echo 'Running - generating first index...<br />';
$output->writeln('Running - generating first index...');
}

if(!$items->count()) {
echo 'No items to update.<br />';
if (!$items->count()) {
$output->writeln('No items to update.');
return 0; // success

} else {

foreach ($items as $item) {
Expand Down Expand Up @@ -61,8 +64,10 @@ public function run($request)
$update->execute();
}

echo '<p>Page ' . $item->Title . ' indexed.</p>' . PHP_EOL;
$output->writeln('Page ' . $item->Title . ' indexed.');
}

return 0; // success
}
}

Expand Down
22 changes: 9 additions & 13 deletions src/SearchControllerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,19 @@
namespace PlasticStudio\Search;

use Exception;
use SilverStripe\ORM\DataExtension;
use SilverStripe\Core\Extension;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\FormAction;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\CheckboxSetField;
use SilverStripe\Forms\ListboxField;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\HiddenField;
use SilverStripe\View\Requirements;
use SilverStripe\Control\Controller;
use SilverStripe\Core\Config\Config;

class SearchControllerExtension extends DataExtension {
class SearchControllerExtension extends Extension {

private static $allowed_actions = array(
'SearchForm',
'BasicSearchForm',
'AdvancedSearchForm'
);

Expand All @@ -29,7 +25,7 @@ class SearchControllerExtension extends DataExtension {
*
* @return Form
**/
public function SearchForm(){
public function BasicSearchForm(){

// create our search form fields
$fields = FieldList::create();
Expand All @@ -48,13 +44,13 @@ public function SearchForm(){
// don't do action here, set below for 404 error page fix
// fix breaks pagination, reinstating
$actions = FieldList::create(
FormAction::create("doSearchForm")->setTitle($submit_button_text)
FormAction::create("doBasicSearchForm")->setTitle($submit_button_text)
);

// now build the actual form object
$form = Form::create(
$controller = $this->owner,
$name = 'SearchForm',
$name = 'BasicSearchForm',
$fields = $fields,
$actions = $actions
)->addExtraClass('search-form')
Expand Down Expand Up @@ -198,7 +194,7 @@ public function AdvancedSearchForm(){
$submit_button_text = Config::inst()->get('PlasticStudio\Search\SearchPageController', 'submit_button_text');
}
$actions = FieldList::create(
FormAction::create("doSearchForm")->setTitle($submit_button_text)
FormAction::create("doBasicSearchForm")->setTitle($submit_button_text)
);

// now build the actual form object
Expand All @@ -218,10 +214,10 @@ public function AdvancedSearchForm(){
/**
* Process the submitted search form. All we're really doing is redirecting to our structured URL
* @param $data = array (post data)
* @param $form = obj (the originating SearchForm object)
* @param $form = obj (the originating BasicSearchForm object)
* @return HTTPRedirect
**/
public function doSearchForm($data, $form){
public function doBasicSearchForm($data, $form){

$page = SearchPage::get()->first();
if (!$page){
Expand Down
4 changes: 2 additions & 2 deletions src/SearchPageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace PlasticStudio\Search;

use PageController;
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\PaginatedList;
use SilverStripe\Model\List\ArrayList;
use SilverStripe\Model\List\PaginatedList;
use SilverStripe\ORM\DB;
use SilverStripe\Core\Config\Config;
use SilverStripe\View\Requirements;
Expand Down
7 changes: 3 additions & 4 deletions src/SiteTreeSearchExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Core\Config\Config;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\ORM\DataExtension;
use SilverStripe\Core\Extension;
use SilverStripe\View\SSViewer;
use SilverStripe\Versioned\Versioned;
use SilverStripe\ORM\Queries\SQLUpdate;

class SiteTreeSearchExtension extends DataExtension
class SiteTreeSearchExtension extends Extension
{

/**
Expand All @@ -23,6 +21,7 @@ class SiteTreeSearchExtension extends DataExtension

public function updateCMSFields(FieldList $fields)
{
$fields->removeByName('ElementalSearchContent');
// $fields->addFieldToTab('Root.test', TextField::create('ElementalSearchContent', 'ElementalSearchContent'));
}

Expand Down
2 changes: 1 addition & 1 deletion templates/Includes/SearchSummary.ss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

<div class="search-summary">
<p>Searched <% if $Types %><% loop $Types %><% if not $IsFirst %><% if $IsLast %> and <% else %>, <% end_if %><% end_if %><em>$Label</em><% end_loop %><% else %>everything<% end_if %><% if $Query %> for <em>"$Query"</em><% end_if %> and got $Results.Count result<% if not $Results %>s<% else_if $Results.Count > 1 %>s<% end_if %></p>
<p>Searched <% if $Types %><% loop $Types %><% if not $IsFirst %><% if $IsLast %> and <% else %>, <% end_if %><% end_if %><em>$Label</em><% end_loop %><% else %>everything<% end_if %><% if $Query %> for <em>"$Query"</em><% end_if %> and got $Results.TotalItems result<% if not $Results %>s<% else_if $Results.TotalItems > 1 %>s<% end_if %></p>
</div>
6 changes: 3 additions & 3 deletions templates/PlasticStudio/Search/Layout/SearchPage.ss
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

<% include SearchSummary %>

<% if Results %>
<% if $Results %>

<div class="search-results">
<% loop Results %>
<% loop $Results %>
<% include SearchResult %>
<% end_loop %>
</div>

<% with Results %>
<% with $Results %>
<% include Pagination %>
<% end_with %>

Expand Down