Version: current

# Class SearchFilter

Base class for filtering implementations, which work together with `SearchContext` to create or amend a query for `DataObject` instances. See `SearchContext` for more information.

  Object
  SearchFilter

### Direct known subclasses

`EndsWithFilter`, `ExactMatchFilter`, `StartsWithMultiFilter`, `SubstringFilter`, `WithinRangeFilter`, `ExactMatchFilterWithEmpty`, `ExactMatchMultiFilter`, `FulltextFilter`, `GreaterThanFilter`, `LessThanFilter`, `NegationFilter`, `PartialMatchFilter`, `StartsWithFilter`

Abstract
Package: sapphire\search
Used by: ``ModelAdmin::getModelForms()``
Located at sapphire/search/filters/SearchFilter.php

## Methods summary

`public` | # `__construct( string $fullName, mixed $value = false )` #### Parameters $fullName string $fullName Determines the name of the field, as well as the searched database column. Can contain a relation name in dot notation, which will automatically join the necessary tables (e.g. "Comments.Name" to join the "Comments" has-many relationship and search the "Name" column when applying this filter to a SiteTree class). $value mixed $value #### Overrides `Object::__construct`
`protected` | # `addRelation( string $name )` Called by constructor to convert a string pathname into a well defined relationship sequence. Called by constructor to convert a string pathname into a well defined relationship sequence. #### Parameters $name string $name
`public` | # `setModel( string $className )` Set the root model class to be selected by this search query. Set the root model class to be selected by this search query. #### Parameters $className string $className
`public` | # `setValue( string $value )` Set the current value to be filtered on. Set the current value to be filtered on. #### Parameters $value string $value
`public string` | # `getValue( )` Accessor for the current value to be filtered on. Caution: Data is not escaped. Accessor for the current value to be filtered on. Caution: Data is not escaped. #### Returns `string` string
`public string` | # `getName( )` The original name of the field. The original name of the field. #### Returns `string` string
`public string` | # `getFullName( )` The full name passed to the constructor, including any (optional) relations in dot notation. The full name passed to the constructor, including any (optional) relations in dot notation. #### Returns `string` string
`public string` | # `getDbName( )` Normalizes the field name to table mapping. Normalizes the field name to table mapping. #### Returns `string` string
`public string` | # `getDbFormattedValue( )` Return the value of the field as processed by the DBField class Return the value of the field as processed by the DBField class #### Returns `string` string
`public `SQLQuery`` | # `applyRelation( `SQLQuery` $query )` Traverse the relationship fields, and add the table mappings to the query object state. This has to be called in any overloaded SearchFilter->apply() methods manually. Traverse the relationship fields, and add the table mappings to the query object state. This has to be called in any overloaded SearchFilter->apply() methods manually. #### Parameters $query SQLQuery $query #### Returns ``SQLQuery`` SQLQuery
`abstract public `SQLQuery`` | # `apply( `SQLQuery` $query )` Apply filter criteria to a SQL query. Apply filter criteria to a SQL query. #### Parameters $query SQLQuery $query #### Returns ``SQLQuery`` SQLQuery
`public boolean` | # `isEmpty( )` Determines if a field has a value, and that the filter should be applied. Relies on the field being populated with `SearchFilter::setValue()` Determines if a field has a value, and that the filter should be applied. Relies on the field being populated with `SearchFilter::setValue()` #### Returns `boolean` boolean

### Methods inherited from Object

`__call()`, `__toString()`, `__wakeup()`, `addMethodsFrom()`, `addStaticVars()`, `addWrapperMethod()`, `add_extension()`, `add_static_var()`, `allMethodNames()`, `cacheToFile()`, `cacheToFileWithArgs()`, `clearCache()`, `combined_static()`, `create()`, `createMethod()`, `create_from_string()`, `defineMethods()`, `exists()`, `extInstance()`, `extend()`, `getCustomClass()`, `getExtensionInstance()`, `getExtensionInstances()`, `get_extensions()`, `get_static()`, `hasExtension()`, `hasMethod()`, `has_extension()`, `invokeWithExtensions()`, `is_a()`, `loadCache()`, `parentClass()`, `parse_class_spec()`, `remove_extension()`, `sanitiseCachename()`, `saveCache()`, `set_stat()`, `set_static()`, `set_uninherited()`, `stat()`, `strong_create()`, `uninherited()`, `uninherited_static()`, `useCustomClass()`

### Magic methods summary

## Properties summary

`protected string` | $model | # Classname of the inspected `DataObject` Classname of the inspected `DataObject`
`protected string` | $name | #
`protected string` | $fullName | #
`protected mixed` | $value | #
`protected string` | $relation | # Name of a has-one, has-many or many-many relation (not the classname). Set in the constructor as part of the name in dot-notation, and used in `SearchFilter::applyRelation()`. Name of a has-one, has-many or many-many relation (not the classname). Set in the constructor as part of the name in dot-notation, and used in `SearchFilter::applyRelation()`.

### Properties inherited from Object

`$class`, `$extension_instances`, `$extensions`

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -