burnbright/silverstripe-pagesearch

This package is not installable via Composer 1.x, please make sure you upgrade to Composer 2+. Read more about our Composer 1.x deprecation policy.

Search pages accross a SilverStripe site.

Installs: 359

Dependents: 0

Suggesters: 0

Security: 0

Stars: 9

Watchers: 3

Forks: 2

Open Issues: 0

Type:silverstripe-module

dev-master 2016-02-21 00:33 UTC

This package is auto-updated.

Last update: 2021-09-24 12:51:22 UTC


README

A simple search replacement for the default SilverStripe search functionality.

Searches will be performed on all Text,HTMLText,Varchar, and HTMLVarchar fields for the selected pagetype.

Pagetype can be specifically set with url vairalble, eg: ?pagetype=BlogEntry.

Limitations

  • Currently only tested with MySQLDatabase.
  • Does not search on relations. Use a better engine like SOLR for this.

Usage

In your Page_Controller class:

	public function SearchForm() {
		$searchText = ($this->request && $this->request->requestVar('Search')) ?
						$this->request->requestVar('Search') : 'Search';
		$form = new Form(
			$this, 'SearchForm',
			new FieldList(
				TextField::create('Search', false)
					->setAttribute("Placeholder", $searchText)
			),
			new FieldList(
				FormAction::create('results', 'Go')
			)
		);
		$form->setFormMethod('GET');
		$form->setTemplate('SearchForm');

		return $form;
	}

	function results($data, $form, $request) { 

		$search = PageSearch::create($request);

		$data = array(
			'Content' => '',
			'Results' => $search->results(),
			'Query' => $search->getQuery(),
			'Title' => _t('SearchForm.SearchResults', 'Search Results')
		); 
		return $this->owner->customise($data)->renderWith(array('Page_results', 'Page'));
	}

Because a DataList is returned, you can wrap it in a PaginatedList to add pagination.