PHP 클래스 ElasticSource

저자: David Kullmann
상속: extends DataSource
파일 보기 프로젝트 열기: dkullmann/cakephp-elastic-search-datasource 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$Http object Holds HttpSocket Object
$columns array Elasticsearch column definition
$fullDebug string Prevents error from being thrown in CakeTestFixture
$useNestedTransactions string Prevents error from being thrown in CakeTestFixture

보호된 프로퍼티들

프로퍼티 타입 설명
$_document array The document for this transaction (for saving more than one model)
$_filterOps string Valid operators from DboSource to support
$_id string If we are in a transaction this is the id for the model we are indexing
$_listSources boolean Don't list sources by default, there's still some problems here
$_parent string Holding data for _parent.
$_queryLog string Query log
$_schema array Holds the mappings
$_transactionStarted boolean Track if we are in a transaction or not - allows saving multiple models to a document
$_type string If we are in a transaction this is the 'type' for the model indexing

공개 메소드들

메소드 설명
__call ( string $method, array $arguments ) : mixed Call HttpSocket methods
__construct ( array $config = [] ) Constructor, call the parent and setup Http
addToDocument ( Model $Model, array $document = [] ) : boolean Store a document to save later, merge it with existing model information for that document
afterParseConditions ( Model $Model, array $filters = [] ) : array Perform this check after parseConditions has completed, since parseConditions is recursive we have to perform this check in a separate method (or use a static variable or whatever, but, I think this is cleaner)
allDocuments ( ) : array Get all documents for this transaction
begin ( ) : true Begin a transaction - allows saving of multiple models pseudo-automically through _bulk API, but it's main purpose is to allow saving associated model data and multiple models (saveMany/saveAssociated)
bulkIndex ( string $type = null, array $documents = [] ) : boolean Bulk index a group of models
calculate ( Model $Model, $func, $params = null )
checkMapping ( Model $Model ) : boolean Check to see if a mapping exists
commit ( ) : boolean Save all models we have been storing
create ( Model $Model, array $fields = [], array $values = [] ) : mixed If this operation is atomic then store the model data to be created on "commit" later, this allows for saving multiple models in one document through saveAll, saveMany, and saveAssociated.
createIndex ( $index, $alias = false, $settings = [] )
createSchema ( $Schema ) : void Create schema, used in testing
currentDocument ( ) : array Get the current document
currentModel ( Model &$Model ) : Model Get/set the current model - called when requests are starting
delete ( Model $Model, array $conditions = null ) : boolean Delete a record
describe ( $model ) : array Describe a model based on it's mapping
dropIndex ( $index )
dropMapping ( Model $Model ) : boolean Delete a mapping
dropSchema ( string $Schema ) : void Drop a schema
execute ( $method = null, $type = null, $api = null, $data = [] )
filterResults ( array $results = [] ) : array Filter results from a call, parsing out the records
fullTableName ( Model | string $model, boolean $quote = true, boolean $schema = true ) : string Gets full table name including prefix
generateQuery ( Model $Model, array $queryData = [] ) : array Generate an ElasticSearch query from Cake's ORM $queryData
geo ( $key, $operator, $value )
geoBoundary ( $field, array $boundaries ) : array Creates filter for a geo boundary box
geoDistance ( $field, array $options ) : array Creates filter for a geo distance search
geoDistanceRange ( $field, $minDistance ) : array Creates filter for a geo distance range search
getColumnType ( Model $model, string $column ) : string Returns the column type of a column in the model.
getLog ( ) : void Get the query log - support for DebugKit Toolbar
getMapping ( ) : array Get the entire index mapping
getType ( Model $Model ) : void Get the useType if its set, otherwise use the table name
inTransaction ( ) : void Check to see if we are in a transacion
index ( $type, $id = null, $document = [] )
insertMulti ( $type, array $fields, array $values, $refresh = true ) : void Used by CakeTestFixture to insert many records.
isConnected ( ) : boolean Returns true to signal that the source is connected to the datastore
listSources ( $data = NULL ) : array List the types available for each index
logQuery ( string $method, string $uri, string $body, string $results = [] ) : void Log a new query if debug is on
mapModel ( Model $Model, array $description = [], $alias = true ) : boolean Map a model based on it's description from MySQL (or your own)
missing ( $key, $value )
name ( string $alias ) : string Make Elastic play nice with Model::escapeField();
parseConditions ( Model $Model, array $conditions = [] ) : array Parse the 'conditions' key of a query from CakePHP's ORM
parseMapping ( array $mapping = [], $sourcesOnly = false ) : array Parse an entire index mapping to create the schema for this datasource
parseOrder ( Model $Model, $query = [] )
parseQueryType ( $query )
query ( $method, $params, Model $Model )
range ( $key, $operator, $value )
read ( Model $Model, array $queryData = [], $recursive = NULL ) : mixed Query ElasticSearch to retrieve records
reindex ( ElasticScroll $scroll, array $options = [] ) : void Copies all documents from an index type to another
reset ( ) : void Reset our transaction state, document, id, and type
resetSequence ( string $table, string $column ) : boolean Reset a sequence based on the MAX() value of $column. Useful for resetting sequences after using insertMulti().
rollback ( ) : void Cancel this save operation/transaction
scan ( Model $model, integer $pageSize = 50, string $cursorTtl = '2m' ) : ElasticScroll Returns an iterator with all results for an index type, the results order is maintained by Elastic search for $cursorTtl time in minutes. This function is commonly used for re-indexing a type when it's internal pproperty definition change.
term ( $key, $operator, $value )
truncate ( string $type, $refresh = true ) : void Used by CakeTestFixture to truncate a type
typeToAlias ( $type ) : string Convert a pluralized table name (test_models) to an alias (TestModel)
update ( Model $Model, $fields = [], $values = [], $conditions = NULL )

보호된 메소드들

메소드 설명
_addLog ( string $data = [] ) : void Added an item to the query log
_convertAttributes ( string $attr, string $val ) : string Convert MySQL or CakePHP ORM field attributes into ElasticSearch compatible attributes
_findKey ( Model $Model, array $document = [] ) : mixed Find the key for this document
_normalizeBoolFilter ( array $filter ) : array Restructures bool filters so they have the propper formatting for Elastic Search
_parseDescription ( array $description = [], $Model = null ) : array Recursive method to map a SQL-like model description into a ElasticSearch one
_parseKey ( Model $Model, string $key, mixed $value ) : array Used to parse a key for ElasticSearch filters
_parseResponse ( CakeResponse $response ) : mixed Parse the response from ElasticSearch, throwing errors if necessary
_setupTransaction ( Model $Model, array $document = [] ) : void If we are in a new transaction, set _type and _id, if we are in an existing transaction then start a new document and set _id
_throwError ( string $info ) : void Throw the right error
_uri ( array $config ) : array Get the URI for a request

메소드 상세

__call() 공개 메소드

Call HttpSocket methods
또한 보기: ElasticSource::_parseResponse()
또한 보기: ElasticSource::_filterResults()
저자: David Kullmann
public __call ( string $method, array $arguments ) : mixed
$method string
$arguments array
리턴 mixed Results from HttpSocket calls parsed by _parseResponse and _filterResults

__construct() 공개 메소드

Constructor, call the parent and setup Http
저자: David Kullmann
public __construct ( array $config = [] )
$config array

_addLog() 보호된 메소드

Added an item to the query log
저자: David Kullmann
protected _addLog ( string $data = [] ) : void
$data string
리턴 void

_convertAttributes() 보호된 메소드

Convert MySQL or CakePHP ORM field attributes into ElasticSearch compatible attributes
저자: David Kullmann
protected _convertAttributes ( string $attr, string $val ) : string
$attr string
$val string
리턴 string ES compatible attribute

_findKey() 보호된 메소드

Find the key for this document
저자: David Kullmann
protected _findKey ( Model $Model, array $document = [] ) : mixed
$Model Model
$document array
리턴 mixed Boolean false if no key is present, otherwise the key (string/int)

_normalizeBoolFilter() 보호된 메소드

Restructures bool filters so they have the propper formatting for Elastic Search
protected _normalizeBoolFilter ( array $filter ) : array
$filter array single bool filter created by _parseKey
리턴 array

_parseDescription() 보호된 메소드

Recursive method to map a SQL-like model description into a ElasticSearch one
저자: David Kullmann
protected _parseDescription ( array $description = [], $Model = null ) : array
$description array
리턴 array Array representing ES Mapping

_parseKey() 보호된 메소드

Used to parse a key for ElasticSearch filters
저자: David Kullmann
protected _parseKey ( Model $Model, string $key, mixed $value ) : array
$Model Model
$key string
$value mixed
리턴 array ElasticSearch compatible filter

_parseResponse() 보호된 메소드

Parse the response from ElasticSearch, throwing errors if necessary
저자: David Kullmann
protected _parseResponse ( CakeResponse $response ) : mixed
$response CakeResponse
리턴 mixed boolean true or false, or body of request as array

_setupTransaction() 보호된 메소드

If we are in a new transaction, set _type and _id, if we are in an existing transaction then start a new document and set _id
저자: David Kullmann
protected _setupTransaction ( Model $Model, array $document = [] ) : void
$Model Model
$document array
리턴 void

_throwError() 보호된 메소드

Throw the right error
저자: David Kullmann
protected _throwError ( string $info ) : void
$info string
리턴 void

_uri() 보호된 메소드

Get the URI for a request
저자: David Kullmann
protected _uri ( array $config ) : array
$config array HttpSocket $config style array
리턴 array Array compatible with HttpSocket $uri for get/post/put/delete

addToDocument() 공개 메소드

Allows saveAssociated to work and allows storing multiple models in one document
저자: David Kullmann
public addToDocument ( Model $Model, array $document = [] ) : boolean
$Model Model
$document array
리턴 boolean true

afterParseConditions() 공개 메소드

Perform this check after parseConditions has completed, since parseConditions is recursive we have to perform this check in a separate method (or use a static variable or whatever, but, I think this is cleaner)
저자: David Kullmann
public afterParseConditions ( Model $Model, array $filters = [] ) : array
$Model Model
$filters array
리턴 array

allDocuments() 공개 메소드

Get all documents for this transaction
저자: David Kullmann
public allDocuments ( ) : array
리턴 array Array of documents keyed by their primary key

begin() 공개 메소드

Begin a transaction - allows saving of multiple models pseudo-automically through _bulk API, but it's main purpose is to allow saving associated model data and multiple models (saveMany/saveAssociated)
저자: David Kullmann
public begin ( ) : true
리턴 true

bulkIndex() 공개 메소드

Bulk index a group of models
저자: David Kullmann
public bulkIndex ( string $type = null, array $documents = [] ) : boolean
$type string
$documents array
리턴 boolean true on success

calculate() 공개 메소드

public calculate ( Model $Model, $func, $params = null )
$Model Model

checkMapping() 공개 메소드

Check to see if a mapping exists
저자: David Kullmann
public checkMapping ( Model $Model ) : boolean
$Model Model
리턴 boolean true if it exists

commit() 공개 메소드

Save all models we have been storing
저자: David Kullmann
public commit ( ) : boolean
리턴 boolean true on success

create() 공개 메소드

The first model to be saved in the transaction determines the type, and if more than one set of models (saveMany) are being saved then they will be stored and saved in bulk Otherwise simply index the model data given based on it's type and Id
저자: David Kullmann
public create ( Model $Model, array $fields = [], array $values = [] ) : mixed
$Model Model
$fields array
$values array
리턴 mixed boolean or array of model data

createIndex() 공개 메소드

public createIndex ( $index, $alias = false, $settings = [] )

createSchema() 공개 메소드

Create schema, used in testing
저자: David Kullmann
public createSchema ( $Schema ) : void
리턴 void

currentDocument() 공개 메소드

Get the current document
저자: David Kullmann
public currentDocument ( ) : array
리턴 array Document data

currentModel() 공개 메소드

Get/set the current model - called when requests are starting
저자: David Kullmann
public currentModel ( Model &$Model ) : Model
$Model Model
리턴 Model the current model

delete() 공개 메소드

Delete a record
저자: David Kullmann
public delete ( Model $Model, array $conditions = null ) : boolean
$Model Model
$conditions array
리턴 boolean True on success

describe() 공개 메소드

Describe a model based on it's mapping
저자: David Kullmann
public describe ( $model ) : array
리턴 array Schema

dropIndex() 공개 메소드

public dropIndex ( $index )

dropMapping() 공개 메소드

Delete a mapping
저자: David Kullmann
public dropMapping ( Model $Model ) : boolean
$Model Model
리턴 boolean true on success

dropSchema() 공개 메소드

Drop a schema
저자: David Kullmann
public dropSchema ( string $Schema ) : void
$Schema string
리턴 void

execute() 공개 메소드

public execute ( $method = null, $type = null, $api = null, $data = [] )

filterResults() 공개 메소드

Filter results from a call, parsing out the records
저자: David Kullmann
public filterResults ( array $results = [] ) : array
$results array
리턴 array Array of results

fullTableName() 공개 메소드

Gets full table name including prefix
public fullTableName ( Model | string $model, boolean $quote = true, boolean $schema = true ) : string
$model Model | string Either a Model object or a string table name.
$quote boolean Whether you want the table name quoted.
$schema boolean Whether you want the schema name included.
리턴 string Full quoted table name

generateQuery() 공개 메소드

Generate an ElasticSearch query from Cake's ORM $queryData
저자: David Kullmann
public generateQuery ( Model $Model, array $queryData = [] ) : array
$Model Model
$queryData array
리턴 array Array that can be converted to JSON for ElasticSearch

geo() 공개 메소드

public geo ( $key, $operator, $value )

geoBoundary() 공개 메소드

Creates filter for a geo boundary box
public geoBoundary ( $field, array $boundaries ) : array
$boundaries array
리턴 array

geoDistance() 공개 메소드

Creates filter for a geo distance search
public geoDistance ( $field, array $options ) : array
$options array
리턴 array

geoDistanceRange() 공개 메소드

Creates filter for a geo distance range search
public geoDistanceRange ( $field, $minDistance ) : array
리턴 array

getColumnType() 공개 메소드

according to its mapping.
public getColumnType ( Model $model, string $column ) : string
$model Model instance to be inspected
$column string The name of the model column
리턴 string Column type

getLog() 공개 메소드

Get the query log - support for DebugKit Toolbar
저자: David Kullmann
public getLog ( ) : void
리턴 void

getMapping() 공개 메소드

Get the entire index mapping
저자: David Kullmann
public getMapping ( ) : array
리턴 array ES Mapping

getType() 공개 메소드

Get the useType if its set, otherwise use the table name
저자: David Kullmann
public getType ( Model $Model ) : void
$Model Model
리턴 void

inTransaction() 공개 메소드

Check to see if we are in a transacion
저자: David Kullmann
public inTransaction ( ) : void
리턴 void

index() 공개 메소드

public index ( $type, $id = null, $document = [] )

insertMulti() 공개 메소드

You should use index instead
저자: David Kullmann
public insertMulti ( $type, array $fields, array $values, $refresh = true ) : void
$fields array
$values array
리턴 void

isConnected() 공개 메소드

Returns true to signal that the source is connected to the datastore
public isConnected ( ) : boolean
리턴 boolean True

listSources() 공개 메소드

List the types available for each index
저자: David Kullmann
public listSources ( $data = NULL ) : array
리턴 array Array of types - similar to tables in a DB

logQuery() 공개 메소드

Log a new query if debug is on
저자: David Kullmann
public logQuery ( string $method, string $uri, string $body, string $results = [] ) : void
$method string
$uri string
$body string
$results string
리턴 void

mapModel() 공개 메소드

Map a model based on it's description from MySQL (or your own)
저자: David Kullmann
public mapModel ( Model $Model, array $description = [], $alias = true ) : boolean
$Model Model
$description array
리턴 boolean true on success

missing() 공개 메소드

public missing ( $key, $value )

name() 공개 메소드

Make Elastic play nice with Model::escapeField();
public name ( string $alias ) : string
$alias string The model alias
리턴 string

parseConditions() 공개 메소드

Parse the 'conditions' key of a query from CakePHP's ORM
저자: David Kullmann
public parseConditions ( Model $Model, array $conditions = [] ) : array
$Model Model
$conditions array
리턴 array Array of filters for ElasticSearch

parseMapping() 공개 메소드

Parse an entire index mapping to create the schema for this datasource
저자: David Kullmann
public parseMapping ( array $mapping = [], $sourcesOnly = false ) : array
$mapping array
리턴 array CakePHP schema

parseOrder() 공개 메소드

public parseOrder ( Model $Model, $query = [] )
$Model Model

parseQueryType() 공개 메소드

public parseQueryType ( $query )

query() 공개 메소드

public query ( $method, $params, Model $Model )
$Model Model

range() 공개 메소드

public range ( $key, $operator, $value )

read() 공개 메소드

Query ElasticSearch to retrieve records
저자: David Kullmann
public read ( Model $Model, array $queryData = [], $recursive = NULL ) : mixed
$Model Model
$queryData array
리턴 mixed boolean false on failure or array of records on success

reindex() 공개 메소드

Copies all documents from an index type to another
public reindex ( ElasticScroll $scroll, array $options = [] ) : void
$scroll ElasticScroll Iterator with results to be copied, can be from another server.
$options array Array with following options: - toIndex: Target index name. If none provided then default configured index for this datasource will be used leave blanck wehn oyu want to copy data from one server to the other using same index name. - toType: Type name to use for storing new documents in target index (required) - transform: A callback function that will get each document before it is stored in target index. useful for adding, removing or changing any data before it is saved.
리턴 void

reset() 공개 메소드

Reset our transaction state, document, id, and type
저자: David Kullmann
public reset ( ) : void
리턴 void

resetSequence() 공개 메소드

This method should be implemented by datasources that require sequences to be used.
public resetSequence ( string $table, string $column ) : boolean
$table string The name of the table to update.
$column string The column to use when reseting the sequence value.
리턴 boolean success.

rollback() 공개 메소드

Cancel this save operation/transaction
저자: David Kullmann
public rollback ( ) : void
리턴 void

scan() 공개 메소드

Returns an iterator with all results for an index type, the results order is maintained by Elastic search for $cursorTtl time in minutes. This function is commonly used for re-indexing a type when it's internal pproperty definition change.
public scan ( Model $model, integer $pageSize = 50, string $cursorTtl = '2m' ) : ElasticScroll
$model Model The model intance to introspect to get the scrollable results
$pageSize integer as results are iterated, how large should the page be when asking Elastic Searhc for results bigger numbers make fewer requests to ElasticSearch but consume more memory and take longer to process in php
$cursorTtl string Time to keep cursor results cached in Elastic Seaach (Example: '10m' for ten minutes)
리턴 ElasticScroll result iterator with all entries for an index type.

term() 공개 메소드

public term ( $key, $operator, $value )

truncate() 공개 메소드

Used by CakeTestFixture to truncate a type
저자: David Kullmann
public truncate ( string $type, $refresh = true ) : void
$type string
리턴 void

typeToAlias() 공개 메소드

Convert a pluralized table name (test_models) to an alias (TestModel)
저자: David Kullmann
public typeToAlias ( $type ) : string
리턴 string

update() 공개 메소드

public update ( Model $Model, $fields = [], $values = [], $conditions = NULL )
$Model Model

프로퍼티 상세

$Http 공개적으로 프로퍼티

Holds HttpSocket Object
public object $Http
리턴 object

$_document 보호되어 있는 프로퍼티

The document for this transaction (for saving more than one model)
protected array $_document
리턴 array

$_filterOps 보호되어 있는 프로퍼티

Valid operators from DboSource to support
protected string $_filterOps
리턴 string

$_id 보호되어 있는 프로퍼티

If we are in a transaction this is the id for the model we are indexing
protected string $_id
리턴 string

$_listSources 보호되어 있는 프로퍼티

Don't list sources by default, there's still some problems here
protected bool $_listSources
리턴 boolean

$_parent 보호되어 있는 프로퍼티

Holding data for _parent.
protected string $_parent
리턴 string

$_queryLog 보호되어 있는 프로퍼티

Query log
protected string $_queryLog
리턴 string

$_schema 보호되어 있는 프로퍼티

Holds the mappings
protected array $_schema
리턴 array

$_transactionStarted 보호되어 있는 프로퍼티

Track if we are in a transaction or not - allows saving multiple models to a document
protected bool $_transactionStarted
리턴 boolean

$_type 보호되어 있는 프로퍼티

If we are in a transaction this is the 'type' for the model indexing
protected string $_type
리턴 string

$columns 공개적으로 프로퍼티

Elasticsearch column definition
public array $columns
리턴 array

$fullDebug 공개적으로 프로퍼티

Prevents error from being thrown in CakeTestFixture
public string $fullDebug
리턴 string

$useNestedTransactions 공개적으로 프로퍼티

Prevents error from being thrown in CakeTestFixture
public string $useNestedTransactions
리턴 string