From 548cbfad8b2a4856fc8df0c82c3ae28cc27f5084 Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Tue, 28 Oct 2014 18:42:27 +1300 Subject: [PATCH] Clean up search documentation --- .../12_Search/01_Searchcontext.md | 79 +++++++++++++------ .../12_Search/02_FulltextSearch.md | 44 +++++++++++ .../en/02_Developer_Guides/12_Search/index.md | 46 ++--------- 3 files changed, 102 insertions(+), 67 deletions(-) create mode 100644 docs/en/02_Developer_Guides/12_Search/02_FulltextSearch.md 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 1ad87380e..f8bb44cef 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:SQLSelect]` 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,31 +64,49 @@ 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'); } } - ### Pagination For pagination records on multiple pages, you need to wrap the results in a @@ -182,11 +206,14 @@ Results.PaginationSummary(4) defines how many pages the search will show in the See `[api:SearchFilter]` API Documentation + +## Related 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