PHP Trait Elasticquent\ElasticquentTrait

Functionality extensions for Elequent that makes working with Elasticsearch easier.
Inheritance: use trait elasticquent\ElasticquentClientTrait
Show file Open project: elasticquent/elasticquent

Protected Properties

Property Type Description
$documentScore null | integer Hit score when using data from Elasticsearch results.
$documentVersion null | integer Elasticsearch document version.
$isDocument boolean Set to true when our model is populated by a
$usesTimestampsInIndex boolean Uses Timestamps In Index

Public Methods

Method Description
addAllToIndex ( ) : array Index Documents
addToIndex ( ) : array Add to Search Index
complexSearch ( $params ) : elasticquent\ElasticquentResultCollection Perform a "complex" or custom search.
createIndex ( integer $shards = null, integer $replicas = null ) : array Create Index
deleteIndex ( ) : array Delete Index
deleteMapping ( ) : array Delete Mapping
documentScore ( ) : null | float Get Document Score
documentVersion ( ) : null | integer Document Version
dontUseTimestampsInIndex ( ) Don't Use Timestamps In Index.
getBasicEsParams ( boolean $getIdIfPossible = true, boolean $getSourceIfPossible = false, boolean $getTimestampIfPossible = false, integer $limit = null, integer $offset = null ) : array Get Basic Elasticsearch Params
getIndexDocumentData ( ) : array Get Index Document Data
getIndexSettings ( ) : array Get Index Settings
getIndexedDocument ( ) : array Get Search Document
getMapping ( ) : void Get Mapping
getMappingProperties ( ) : array Get Mapping Properties
getTypeName ( ) : string Get Type Name
hydrateElasticquentResult ( array $items, array $meta = null ) : Elasticquent\ElasticquentResultCollection Create a elacticquent result collection of models from plain arrays.
hydrateElasticsearchResult ( array $result ) : Elasticquent\ElasticquentResultCollection Create a elacticquent result collection of models from plain elasticsearch result.
hydrateRecursive ( Model $model, array $items, Illuminate\Database\Eloquent\Relations\Relation $parentRelation = null ) : Illuminate\Database\Eloquent\Collection Create a collection of models from plain arrays recursive.
isDocument ( ) : boolean Is Elasticsearch Document
loadPivotAttribute ( Model $model, Illuminate\Database\Eloquent\Relations\Relation $parentRelation = null ) Get the pivot attribute from a model.
loadRelationsAttributesRecursive ( Model $model ) Get the relations attributes from a model.
mappingExists ( ) : boolean Mapping Exists
newCollection ( array $models = [] ) : ElasticquentCollection New Collection
newElasticquentResultCollection ( array $models = [], array $meta = null ) : Elasticquent\ElasticquentResultCollection Create a new Elasticquent Result Collection instance.
newFromBuilderRecursive ( Model $model, array $attributes = [], Illuminate\Database\Eloquent\Relations\Relation $parentRelation = null ) : static Create a new model instance that is existing recursive.
newFromHitBuilder ( array $hit = [] ) : static New From Hit Builder
putMapping ( boolean $ignoreConflicts = false ) : array Put Mapping.
rebuildMapping ( ) : array Rebuild Mapping
reindex ( ) : array Re-Index All Content
removeFromIndex ( ) : array Remove From Search Index
search ( string $term = '' ) : elasticquent\ElasticquentResultCollection Search
searchByQuery ( array $query = null, array $aggregations = null, array $sourceFields = null, integer $limit = null, integer $offset = null, array $sort = null ) : elasticquent\ElasticquentResultCollection Search By Query
setMappingProperties ( array $mapping = null ) Set Mapping Properties
typeExists ( ) : boolean Type Exists.
updateIndex ( ) : array Partial Update to Indexed Document
useTimestampsInIndex ( $shouldUse = true ) Use Timestamps In Index.
usesTimestampsInIndex ( ) Uses Timestamps In Index.

Private Methods

Method Description
buildFieldsParameter ( boolean $getSourceIfPossible, boolean $getTimestampIfPossible ) : array Build the 'fields' parameter depending on given options.
isMultiLevelArray ( array $array ) : boolean Check if an array is multi-level array like [[id], [id], [id]].

Method Details

addAllToIndex() public static method

Index all documents in an Eloquent model.
public static addAllToIndex ( ) : array
return array

addToIndex() public method

Add to Search Index
public addToIndex ( ) : array
return array

complexSearch() public static method

Using this method, a custom query can be sent to Elasticsearch.
public static complexSearch ( $params ) : elasticquent\ElasticquentResultCollection
$params parameters to be passed directly to Elasticsearch
return elasticquent\ElasticquentResultCollection

createIndex() public static method

Create Index
public static createIndex ( integer $shards = null, integer $replicas = null ) : array
$shards integer
$replicas integer
return array

deleteIndex() public static method

Delete Index
public static deleteIndex ( ) : array
return array

deleteMapping() public static method

Delete Mapping
public static deleteMapping ( ) : array
return array

documentScore() public method

Get Document Score
public documentScore ( ) : null | float
return null | float

documentVersion() public method

Document Version
public documentVersion ( ) : null | integer
return null | integer

dontUseTimestampsInIndex() public method

Don't Use Timestamps In Index.
Deprecation:

getBasicEsParams() public method

Most Elasticsearch API calls need the index and type passed in a parameter array.
public getBasicEsParams ( boolean $getIdIfPossible = true, boolean $getSourceIfPossible = false, boolean $getTimestampIfPossible = false, integer $limit = null, integer $offset = null ) : array
$getIdIfPossible boolean
$getSourceIfPossible boolean
$getTimestampIfPossible boolean
$limit integer
$offset integer
return array

getIndexDocumentData() public method

Get the data that Elasticsearch will index for this particular document.
public getIndexDocumentData ( ) : array
return array

getIndexSettings() public method

Get Index Settings
public getIndexSettings ( ) : array
return array

getIndexedDocument() public method

Retrieve an ElasticSearch document for this entity.
public getIndexedDocument ( ) : array
return array

getMapping() public static method

Get Mapping
public static getMapping ( ) : void
return void

getMappingProperties() public method

Get Mapping Properties
public getMappingProperties ( ) : array
return array

getTypeName() public method

Get Type Name
public getTypeName ( ) : string
return string

hydrateElasticquentResult() public static method

Create a elacticquent result collection of models from plain arrays.
public static hydrateElasticquentResult ( array $items, array $meta = null ) : Elasticquent\ElasticquentResultCollection
$items array
$meta array
return Elasticquent\ElasticquentResultCollection

hydrateElasticsearchResult() public static method

Create a elacticquent result collection of models from plain elasticsearch result.
public static hydrateElasticsearchResult ( array $result ) : Elasticquent\ElasticquentResultCollection
$result array
return Elasticquent\ElasticquentResultCollection

hydrateRecursive() public static method

Create a collection of models from plain arrays recursive.
public static hydrateRecursive ( Model $model, array $items, Illuminate\Database\Eloquent\Relations\Relation $parentRelation = null ) : Illuminate\Database\Eloquent\Collection
$model Illuminate\Database\Eloquent\Model
$items array
$parentRelation Illuminate\Database\Eloquent\Relations\Relation
return Illuminate\Database\Eloquent\Collection

isDocument() public method

Is the data in this module sourced from an Elasticsearch document source?
public isDocument ( ) : boolean
return boolean

loadPivotAttribute() public static method

Get the pivot attribute from a model.
public static loadPivotAttribute ( Model $model, Illuminate\Database\Eloquent\Relations\Relation $parentRelation = null )
$model Illuminate\Database\Eloquent\Model
$parentRelation Illuminate\Database\Eloquent\Relations\Relation

loadRelationsAttributesRecursive() public static method

Get the relations attributes from a model.
public static loadRelationsAttributesRecursive ( Model $model )
$model Illuminate\Database\Eloquent\Model

mappingExists() public static method

Mapping Exists
public static mappingExists ( ) : boolean
return boolean

newCollection() public method

New Collection
public newCollection ( array $models = [] ) : ElasticquentCollection
$models array
return ElasticquentCollection

newElasticquentResultCollection() public method

Create a new Elasticquent Result Collection instance.
public newElasticquentResultCollection ( array $models = [], array $meta = null ) : Elasticquent\ElasticquentResultCollection
$models array
$meta array
return Elasticquent\ElasticquentResultCollection

newFromBuilderRecursive() public static method

Create a new model instance that is existing recursive.
public static newFromBuilderRecursive ( Model $model, array $attributes = [], Illuminate\Database\Eloquent\Relations\Relation $parentRelation = null ) : static
$model Illuminate\Database\Eloquent\Model
$attributes array
$parentRelation Illuminate\Database\Eloquent\Relations\Relation
return static

newFromHitBuilder() public method

Variation on newFromBuilder. Instead, takes
public newFromHitBuilder ( array $hit = [] ) : static
$hit array
return static

putMapping() public static method

Put Mapping.
public static putMapping ( boolean $ignoreConflicts = false ) : array
$ignoreConflicts boolean
return array

rebuildMapping() public static method

This will delete and then re-add the mapping for this model.
public static rebuildMapping ( ) : array
return array

reindex() public static method

Re-Index All Content
public static reindex ( ) : array
return array

removeFromIndex() public method

Remove From Search Index
public removeFromIndex ( ) : array
return array

searchByQuery() public static method

Search with a query array
public static searchByQuery ( array $query = null, array $aggregations = null, array $sourceFields = null, integer $limit = null, integer $offset = null, array $sort = null ) : elasticquent\ElasticquentResultCollection
$query array
$aggregations array
$sourceFields array
$limit integer
$offset integer
$sort array
return elasticquent\ElasticquentResultCollection

setMappingProperties() public method

Set Mapping Properties
public setMappingProperties ( array $mapping = null )
$mapping array

typeExists() public static method

Does this type exist?
public static typeExists ( ) : boolean
return boolean

updateIndex() public method

Partial Update to Indexed Document
public updateIndex ( ) : array
return array

useTimestampsInIndex() public method

Use Timestamps In Index.
public useTimestampsInIndex ( $shouldUse = true )

usesTimestampsInIndex() public method

Uses Timestamps In Index.

Property Details

$documentScore protected property

Hit score when using data from Elasticsearch results.
protected null|int $documentScore
return null | integer

$documentVersion protected property

Elasticsearch document version.
protected null|int $documentVersion
return null | integer

$isDocument protected property

Set to true when our model is populated by a
protected bool $isDocument
return boolean

$usesTimestampsInIndex protected property

Uses Timestamps In Index
protected bool $usesTimestampsInIndex
return boolean