diff --git a/docs/en/02_Developer_Guides/12_Search/01_Searchcontext.md b/docs/en/02_Developer_Guides/12_Search/01_Searchcontext.md index d3479993d..e2ec9cd03 100644 --- a/docs/en/02_Developer_Guides/12_Search/01_Searchcontext.md +++ b/docs/en/02_Developer_Guides/12_Search/01_Searchcontext.md @@ -1,41 +1,45 @@ +title: Scaffolding with SearchContext +summary: Configure the search form within ModelAdmin using the SearchContext class. + # SearchContext -## Introduction +[api:SearchContext] manages searching of properties on one or more [api:DataObject] types, based on a given set of +input parameters. [api:SearchContext] is intentionally decoupled from any controller-logic, it just receives a set of +search parameters and an object class it acts on. -Manages searching of properties on one or more `[api:DataObject]` types, based on a given set of input parameters. -`[api:SearchContext]` is intentionally decoupled from any controller-logic, -it just receives a set of search parameters and an object class it acts on. +The default output of a [api:SearchContext] is either a [api:SQLQuery] object for further refinement, or a +[api:DataObject] instance. -The default output of a `[api:SearchContext]` is either a `[api:SQLQuery]` object for further refinement, or a -`[api:DataObject]` instance. - -In case you need multiple contexts, consider namespacing your request parameters by using `FieldList->namespace()` on -the $fields constructor parameter. - -`[api:SearchContext]` is mainly used by `[ModelAdmin](/reference/modeladmin)`, our generic data administration interface. Another -implementation can be found in generic frontend search forms through the [genericviews](http://silverstripe.org/generic-views-module) module. +
+[api:SearchContext] is mainly used by [ModelAdmin](../customising_the_cms/modeladmin). +
## Usage -Getting results +Defining search-able fields on your DataObject. :::php - singleton('MyDataObject')->getDefaultSearchContext(); + getDefaultSearchContext()` -method, we're building our own `getCustomSearchContext()` variant. +*after* the search entry (with a `GreaterThanFilter`). :::php + 'Text' 'HiddenProperty' => 'Text', @@ -46,10 +50,12 @@ method, we're building our own `getCustomSearchContext()` variant. $fields = $this->scaffoldSearchFields(array( 'restrictFields' => array('PublicProperty','MyDate') )); + $filters = array( 'PublicProperty' => new PartialMatchFilter('PublicProperty'), 'MyDate' => new GreaterThanFilter('MyDate') ); + return new SearchContext( $this->class, $fields, @@ -58,24 +64,43 @@ method, we're building our own `getCustomSearchContext()` variant. } } +
+See the [SearchFilter](../model/searchfilters) documentation for more information about filters to use such as the +`GreaterThanFilter`. +
+ +
+In case you need multiple contexts, consider name-spacing your request parameters by using `FieldList->namespace()` on +the `$fields` constructor parameter. +
+ ### Generating a search form from the context :::php + getCustomSearchContext(); $fields = $context->getSearchFields(); + $form = new Form($this, "SearchForm", $fields, new FieldList( new FormAction('doSearch') ) ); + return $form; } + public function doSearch($data, $form) { $context = singleton('MyDataObject')->getCustomSearchContext(); $results = $context->getResults($data); + return $this->customise(array( 'Results' => $results ))->renderWith('Page_results'); @@ -83,110 +108,13 @@ method, we're building our own `getCustomSearchContext()` variant. } -### Pagination +## Related Documentation -For pagination records on multiple pages, you need to wrap the results in a -`PaginatedList` object. This object is also passed the generated `SQLQuery` -in order to read page limit information. It is also passed the current -`SS_HTTPRequest` object so it can read the current page from a GET var. - - :::php - public function getResults($searchCriteria = array()) { - $start = ($this->request->getVar('start')) ? (int)$this->request->getVar('start') : 0; - $limit = 10; - - $context = singleton('MyDataObject')->getCustomSearchContext(); - $query = $context->getQuery($searchCriteria, null, array('start'=>$start,'limit'=>$limit)); - $records = $context->getResults($searchCriteria, null, array('start'=>$start,'limit'=>$limit)); - - if($records) { - $records = new PaginatedList($records, $this->request); - $records->setPageStart($start); - $records->setPageLength($limit); - $records->setTotalItems($query->unlimitedRowCount()); - } - - return $records; - } - - -notice that if you want to use this getResults function, you need to change the function doSearch for this one: - - :::php - public function doSearch($data, $form) { - $context = singleton('MyDataObject')->getCustomSearchContext(); - $results = $this->getResults($data); - return $this->customise(array( - 'Results' => $results - ))->renderWith(array('Catalogo_results', 'Page')); - } - - -The change is in **$results = $this->getResults($data);**, because you are using a custom getResults function. - -Another thing you cant forget is to check the name of the singleton you are using in your project. the example uses -**MyDataObject**, you need to change it for the one you are using - -For more information on how to paginate your results within the template, see [Tutorial: Site Search](/tutorials/4-site-search). - - -### The Pagination Template - -to show the results of your custom search you need at least this content in your template, notice that -Results.PaginationSummary(4) defines how many pages the search will show in the search results. something like: - -**Next 1 2 *3* 4 5 … 558** - - - :::ss - <% if $Results %> - - <% else %> -

Sorry, your search query did not return any results.

- <% end_if %> - - <% if $Results.MoreThanOnePage %> -
-

- <% if $Results.NotFirstPage %> - - <% end_if %> - - - <% loop $Results.PaginationSummary(4) %> - <% if $CurrentBool %> - $PageNum - <% else %> - <% if $Link %> - $PageNum - <% else %> - … - <% end_if %> - <% end_if %> - <% end_loop %> - - - <% if $Results.NotLastPage %> - - <% end_if %> -

-
- <% end_if %> - - -## Available SearchFilters - -See `[api:SearchFilter]` API Documentation +* [ModelAdmin](../customising_the_cms/modeladmin) +* [Tutorial: Site Search](/tutorials/site_search) ## API Documentation -`[api:SearchContext]` -## Related +* [api:SearchContext] +* [api:DataObject] -* [ModelAdmin](/reference/modeladmin) -* [RestfulServer module](https://github.com/silverstripe/silverstripe-restfulserver) -* [Tutorial: Site Search](/tutorials/4-site-search) diff --git a/docs/en/02_Developer_Guides/12_Search/02_FulltextSearch.md b/docs/en/02_Developer_Guides/12_Search/02_FulltextSearch.md new file mode 100644 index 000000000..11fdb7c20 --- /dev/null +++ b/docs/en/02_Developer_Guides/12_Search/02_FulltextSearch.md @@ -0,0 +1,44 @@ +title: Fulltext Search +summary: Fulltext search allows sophisticated searching on text content. + +# FulltextSearchable + +Fulltext search allows advanced search criteria for searching words within a text based data column. While basic +Fulltext search can be achieved using the built-in [api:MySQLDatabase] class a more powerful wrapper for Fulltext +search is provided through a module. + +
+See the [FulltextSearch Module](https://github.com/silverstripe-labs/silverstripe-fulltextsearch/). This module provides +a high level wrapper for running advanced search services such as Solr, Lucene or Sphinx in the backend rather than +`MySQL` search. +
+ +## Adding Fulltext Support to MySQLDatabase + +The [api:MySQLDatabase] class defaults to creating tables using the InnoDB storage engine. As Fulltext search in MySQL +requires the MyISAM storage engine, any DataObject you wish to use with Fulltext search must be changed to use MyISAM +storage engine. + +You can do so by adding this static variable to your class definition: + + :::php + 'ENGINE=MyISAM' + ); + } + +The [api:FulltextSearchable] extension will add the correct `Fulltext` indexes to the data model. + +
+The [api:SearchForm] and [api:FulltextSearchable] API's are currently hard coded to be specific to `Page` and `File` +records and cannot easily be adapted to include custom `DataObject` instances. To include your custom objects in the +default site search, have a look at those extensions and modify as required. +
+ +## API Documentation + +* [api:FulltextSearchable] \ No newline at end of file diff --git a/docs/en/02_Developer_Guides/12_Search/index.md b/docs/en/02_Developer_Guides/12_Search/index.md index d8255d379..fac71a014 100644 --- a/docs/en/02_Developer_Guides/12_Search/index.md +++ b/docs/en/02_Developer_Guides/12_Search/index.md @@ -1,44 +1,8 @@ +title: Search summary: Provide your users with advanced search functionality. +introduction: Give users the ability to search your applications. Fulltext search for Page Content (and other attributes like "Title") can be easily added to SilverStripe. -# Search +See the [Site Search Tutorial](/tutorials/site_search) for a detailed walk through of adding basic Search to your +website. -## Searching for Pages (and Files) - -Fulltext search for page content (and other attributes like "Title" or "MetaTags") can be easily added to SilverStripe. -See [Tutorial: Site Search](/tutorials/site_search) for details. - -## Searching for DataObjects - -The `[api:SearchContext]` class provides a good base implementation that you can hook into your own controllers. -A working implementation of searchable DataObjects can be seen in the [ModelAdmin](../customising_the_cms/modeladmin) class. - -[SearchContext](/searchcontext) goes into more detail about setting up a default search form for `[api:DataObject]`s. - -## Fulltext search on DataObjects - -The `[api:MySQLDatabase]` class now defaults to creating tables using the InnoDB storage engine. As Fulltext search in -MySQL requires the MyISAM storage engine, any DataObject you wish to use with Fulltext search must be changed to use -MyISAM storage engine. - -You can do so by adding this static variable to your class definition: - - :::php - private static $create_table_options = array( - 'MySQLDatabase' => 'ENGINE=MyISAM' - ); - -## Searching for Documents - -SilverStripe does not have a built-in method to search through file content (e.g. in PDF or DOC format). You can either -extract any textual file content into the `[File](api:File)->Content` property, or use a dedicated search service like -the [Full module](http://silverstripe.org/sphinx-module). - -## Related - -* [ModelAdmin](/reference/modeladmin) -* [RestfulServer module](https://github.com/silverstripe/silverstripe-restfulserver) -* [Tutorial: Site Search](/tutorials/4-site-search) -* [SearchContext](/reference/searchcontext) -* [genericviews module](http://silverstripe.org/generic-views-module) -* [sphinx module](http://silverstripe.org/sphinx-module) -* [lucene module](http://silverstripe.org/lucene-module) \ No newline at end of file +[CHILDREN] \ No newline at end of file