Tuskfish API V1.1.2
  • Package
  • Class

Packages

  • content
  • core
  • database
  • installation
  • security
  • user
  • utilities

Classes

  • TfArticle
  • TfAudio
  • TfBlock
  • TfBlockHandler
  • TfCollection
  • TfCollectionHandler
  • TfContentControllerFactory
  • TfContentHandler
  • TfContentHandlerFactory
  • TfContentObject
  • TfContentObjectController
  • TfDownload
  • TfImage
  • TfRss
  • TfSearchContent
  • TfStatic
  • TfTag
  • TfTagHandler
  • TfTaglinkHandler
  • TfVideo

Traits

  • TfContentTypes

Class TfSearchContent

Provides search functionality for the content module, returning mixed content objects.

Package: content
Copyright: Simon Wilkinson 2013+ (https://tuskfish.biz)
License: GNU General Public License (GPL) V2
Author: Simon Wilkinson simon@isengard.biz
Version: Release: 1.0
Since: 1.1
Var: TfValidator $validator Instance of the Tuskfish data validator class.
Var: TfDatabase $db Instance of the Tuskfish database class.
Var: TfPreference $preference Instance of the Tuskfish site preferences class.
Var: array $searchTerms Search terms provided by user.
Var: array $escapedSearchTerms XSS escaped copies of the search terms, used for display.
Var: int $limit Number of records to retrieve in a single page view.
Var: int $offset Starting point for reading records from a result set.
Var: string $operator Type of search, options are 'AND', 'OR' and 'exact'.
Located at trust_path/modules/content/class/TfSearchContent.php

Methods summary

public
# __construct( TfValidator $validator, TfDatabase $db, TfPreference $preference )

Constructor.

Constructor.

Parameters

$validator
An instance of the Tuskfish data validator class.
$db
An instance of the database class.
$preference
An instance of the Tuskfish site preferences class.
public object|boolean
# searchContent( )

Provides global search functionality for content objects.

Provides global search functionality for content objects.

Escaping of search terms is handled through use of a PDO prepared statement with named placeholders; search terms are inserted indirectly by binding them to the placeholders. Search terms must NEVER be inserted into a query directly (creates an SQL injection vulnerability), otherwise do us all a favour and go shoot yourself now.

Search terms have entity encoding (htmlspecialchars) applied on the teaser and description fields (only) to ensure consistency with the entity encoding treatment that these HTML fields have been subjected to, otherwise searches involving entities will not return results.

Returns

object|boolean
Content objects if results found, false if no results or on failure.
public
# setLimit( integer $limit )

Set a limit on the number of results to retrieve.

Set a limit on the number of results to retrieve.

Usually this will be the number of objects you want to display in a single page view, as it is related to pagination, for example a search may return 50 results but you only want to display 10 per page.

Parameters

$limit
Number of objects to retrieve.
public
# setOffset( integer $offset )

Set a starting point for retrieving objects from a result set.

Set a starting point for retrieving objects from a result set.

Related to pagination, for example you have 50 search results and display 10 per page, and are currently viewing the third page of results, you would set this as 29.

Parameters

$offset
Starting point to retrieve objects from a result set.
public
# setOperator( string $operator )

Set the search type operator (AND, OR or exact).

Set the search type operator (AND, OR or exact).

Determines whether the search terms will be used inclusively (OR), exclusively (AND) or exactly.

Parameters

$operator
AND, OR or exact.
public
# setSearchTerms( string $searchTerms )

Set and escape search terms for use in a query.

Set and escape search terms for use in a query.

As some content fields require entities to be encoded (the HTML fields, ie. teaser, description and icon) and others don't, both encoded and unencoded copies of the terms are required for a comprehensive database search. Terms that do not meet the minimum length preference requirement are discarded.

Note that search operator MUST be set before the search terms are set, otherwise the default AND operator will be used.

Parameters

$searchTerms
Search terms provided by user.

Properties summary

protected $validator
#
protected $db
#
protected $preference
#
protected $searchTerms
#
protected $escapedSearchTerms
#
protected $limit
#
protected $offset
#
protected $operator
#
Tuskfish API V1.1.2 API documentation generated by ApiGen