Download the PHP package foryoufeng/elasticsearch without Composer
On this page you can find all versions of the php package foryoufeng/elasticsearch. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download foryoufeng/elasticsearch
More information about foryoufeng/elasticsearch
Files in foryoufeng/elasticsearch
Package elasticsearch
Short Description Laravel, Lumen and Native php elasticseach query builder to build complex queries using an elegant syntax
License MIT
Homepage https://github.com/foryoufeng
Informations about the package elasticsearch
Laravel, Lumen and Native php elasticseach query builder to build complex queries/laravel使用elasticseach进行全文检索
中文文档
- Keeps you away from wasting your time by replacing array queries with a simple and elegant syntax you will love.
- Elasticsearch data model for types and indices inspired from laravel eloquent.
- Feeling free to create, drop, mapping and reindexing through easy artisan console commands.
- Lumen framework support.
- Native php and composer based applications support.
- Can be used as a laravel scout driver.
- Dealing with multiple elasticsearch connections at the same time.
- Awesome pagination based on LengthAwarePagination.
- Caching queries using a caching layer over query builder built on laravel cache.
- you also can see basemkhirat/elasticsearch && elastic/elasticsearch-php
Requirements
-
php
>= 5.6.6 laravel/laravel
>= 5. orlaravel/lumen
>= 5. orcomposer application
Documentation
Installation
Laravel Installation
1) Install package using composer.
2) Add package service provider (< laravel 5.5).
3) Add package alias (< laravel 5.5).
4) Publishing.
Configuration (Laravel & Lumen)
After publishing, two configuration files will be created.
config/es.php
where you can add more than one elasticsearch server.
Usage as a Laravel Scout driver
First, follow Laravel Scout installation.
All you have to do is updating these lines in config/scout.php
configuration file.
Have a look at laravel Scout documentation.
Scout search
now you can use between or in and so on method such as
// more infomation you can see the test code
ScoutSearchTest.php.
Elasticsearch data model
Each index type has a corresponding "Model" which is used to interact with that type. Models allow you to query for data in your types or indices, as well as insert new documents into the type.
Basic usage
The above example will use the default connection and default index in es.php
. You can override both in the next example.
Retrieving Models
Once you have created a model and its associated index type, you are ready to start retrieving data from your index. For example:
Adding Additional Constraints
The all
method will return all of the results in the model's type. Each elasticsearch model serves as a query builder, you may also add constraints to queries, and then use the get()
method to retrieve the results:
Retrieving Single Models
Inserting Models
To create a new document, simply create a new model instance, set attributes on the model, then call the save()
method:
Updating Models
The save()
method may also be used to update models that already exist. To update a model, you should retrieve it, set any attributes you wish to update, and then call the save method.
Deleting Models
To delete a model, call the delete()
method on a model instance:
Query Scopes
Scopes allow you to define common sets of constraints that you may easily re-use throughout your application. For example, you may need to frequently retrieve all posts that are considered "popular". To define a scope, simply prefix an Eloquent model method with scope.
Scopes should always return a Query instance.
Once the scope has been defined, you may call the scope methods when querying the model. However, you do not need to include the scope prefix when calling the method. You can even chain calls to various scopes, for example:
Accessors & Mutators
Defining An Accessor
To define an accessor
, create a getFooAttribute method on your model where Foo
is the "studly" cased name of the column you wish to access. In this example, we'll define an accessor for the title
attribute. The accessor will automatically be called by model when attempting to retrieve the value of the title
attribute:
As you can see, the original value of the column is passed to the accessor, allowing you to manipulate and return the value. To access the value of the accessor, you may simply access the title
attribute on a model instance:
Occasionally, you may need to add array attributes that do not have a corresponding field in your index. To do so, simply define an accessor for the value:
Once you have created the accessor, just add the value to the appends
property on the model:
Once the attribute has been added to the appends list, it will be included in model's array.
Defining A Mutator
To define a mutator, define a setFooAttribute
method on your model where Foo
is the "studly" cased name of the column you wish to access. So, again, let's define a mutator for the title
attribute. This mutator will be automatically called when we attempt to set the value of the title
attribute on the model:
The mutator will receive the value that is being set on the attribute, allowing you to manipulate the value and set the manipulated value on the model's internal $attributes
property. So, for example, if we attempt to set the title attribute to Awesome post to read
:
In this example, the setTitleAttribute function will be called with the value Awesome post to read
. The mutator will then apply the strtolower function to the name and set its resulting value in the internal $attributes array.
Attribute Casting
The $casts
property on your model provides a convenient method of converting attributes to common data types. The $casts
property should be an array where the key is the name of the attribute being cast and the value is the type you wish to cast the column to. The supported cast types are: integer
, float
, double
, string
, boolean
, object
and array
.
For example, let's cast the is_published
attribute, which is stored in our index as an integer (0 or 1) to a boolean
value:
Now the is_published
attribute will always be cast to a boolean
when you access it, even if the underlying value is stored in the index as an integer:
Usage as a query builder
Creating a new index
Creating index with custom options (optional)
Dropping index
Running queries
You can rewrite the above query to
The query builder will use the default connection, index name in configuration file es.php
.
Connection and index names in query overrides connection and index names in configuration file es.php
.
Getting document by id
Sorting
Limit and offset
Select only specific fields
Where clause
Where greater than
Where greater than or equal
Where less than
Where less than or equal
Where like
Where field exists
Where in clause
Where between clause
Where not clause
Where not greater than
Where not greater than or equal
Where not less than
Where not less than or equal
Where not like
Where not field exists
Where not in clause
Where not between clause
Search by a distance from a geo point
Search using array queries
Search the entire document
Return only first record
Return only count
Scan-and-Scroll queries
Paginate results with 5 records per page
These are all pagination methods you may use:
Getting the query array without execution
Getting the original elasticsearch response
Ignoring bad HTTP response
Query Caching (Laravel & Lumen)
Package comes with a built-in caching layer based on laravel cache.
Executing elasticsearch raw queries
Insert a new document
Bulk insert a multiple of documents at once.
Update an existing document
Incrementing field
Decrementing field
Update using script
Delete a document
Releases
See Change Log.
Author
Bugs, Suggestions
Please use Github for reporting bugs, and making comments or suggestions.
License
MIT
Have a happy searching..
All versions of elasticsearch with dependencies
elasticsearch/elasticsearch Version ^5.0|^6.0
illuminate/pagination Version *
illuminate/support Version *
symfony/var-dumper Version *
monolog/monolog Version ^1.23