Commit ffc0c3ee authored by Gerald Quimpo's avatar Gerald Quimpo Committed by Robert Lyon
Browse files

Bug 1694171: manually merge low level elasticsearch code from Yulia Bozhko's


   "Bug 1694171: Elasticsearch rewrite" Totara commit.

   Minimal merge only since the Totara patch does much that we don't
   need or want (e.g., ES becomes the only search engine).

   Remove elastica

   TODO: remove this TODO when faceted search is fixed, either in
   this commit or a follow-on.

Change-Id: I1a6b589900eb689e488c21d36f40729b541f1d19
Signed-off-by: default avatarGerald Quimpo <gerald@catalyst.net.nz>
parent 02e1e9f8
This diff is collapsed.
Contributing
============
Help is very welcomed. Code contributions must be done in respect of [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md).
More details on how to contribute and guidelines for [pull requests](http://elastica.io/contribute/pull-request.html) can be found [here](http://elastica.io/contribute/).
See [Coding guidelines](http://elastica.io/contribute/coding-guidelines.html) for tips on how to do so.
All changes must be documented in the [CHANGELOG.md](https://github.com/ruflin/Elastica/blob/master/CHANGELOG.md).
Issues
------
* Bugs & Feature requests: If you found a bug, open an issue on [Github](https://github.com/ruflin/Elastica/issues). Please search for already reported similary issues before opening a new one. You should include code examples (with dependencies if needed) and your Elastica version to the issue description.
* Questions & Problems: If you have questions or a specific problem, use the [Elastica Gitter](https://gitter.im/ruflin/Elastica) Chat or open an issue on [Stackoverflow](http://stackoverflow.com/questions/tagged/elastica). Make sure to assign the tag Elastica.
Setup
-----
Elastica currently allows two setups for development. Either through vagrant or docker-compose. To use the vagrant environment, run `vagrant up`. To use the docker environment, check out the Makefile for the necessary commands.
* Run your changes / tests in the virtual environment to make sure it is reproducible.
* Run the tests before creating the pull request using vagrant or docker-compose locally.
Commands
--------
To run the commands below, you must have docker-compose [installed](https://docs.docker.com/compose/install/). The first time the commands are run it takes some time to download all the partial images. From then on the commands should run very fast. The advantage in using the commands below is that no local tools and libraries have to be installed and it is guaranteed that everytone is using the same tools.
## Run Tests
To run all tests inside the docker environment, run the following command:
```
make run RUN="make phpunit"
```
If you want to run just a specific test or a one specific file, run the following command by replacing your file with the existingpath:
```
make run RUN="phpunit -c ./test lib/Elastica/Test/SearchTest.php"
```
## Check style of your code
This command will call php-cs-fixer with the predefined settings for the elastica project. No local setup of the tools is needed as everything will happen directly in the container.
```
make run RUN="make lint"
```
Coding
------
### Rules
* Pull requests are made to master. Changes are never pushed directly (without pull request) into master.
* We use the Forking Workflow. https://www.atlassian.com/git/tutorials/comparing-workflows/forking-workflow
* Follow the coding guidelines.
* Use a feature branch for every pull request. Don't open a pull request from your master branch.
### Pull Requests
* One change per pull requests: Keep your pull requests as small as possible. Only one change should happen per pull request. This makes it easier to review and provided feedback. If you have a large pull request, try to split it up in multiple smaller requests.
* Commit messages: Make sure that your commit messages have meaning and provide an understanding on what was changed without looking at the code.
* Pull requests should be opened as early as possible as pull requests are also here for communication / discussing changes. Add a comment when your pull request is ready to be merged.
* Tests: Your addition / change must be tested and the builds must be green. Test your changes locally. Add unit tests and if possible functional tests. Don't forget to add the group to your tests. The 4 available groups are @functional, @unit, @shutdown, @benchmark
* Update the CHANGELOG.md file with your changes
* Backward Compatibility breaks: In case you break backward compatibility, provide details on why this is needed.
* Merge: No one should ever merge his own pull request
### Name Spaces & Classes
Most name spaces and classes are self explanotary and use cases can be taken from classes which already exist.
#### Tool Namespace
The namespace Tool is used for making more complex functionality of Elastica available to the users. In general it maps existing functionality of Elastica and offers simplified functions.
#### Util Class
The util class is used for all static functions which are used in the Elastica library but don't access the library itself.
The MIT License (MIT)
Copyright (c) 2014 Nicolas Ruflin
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
\ No newline at end of file
Elastica in Mahara
======================
Website: http://elastica.io
Version: 2.3.1
This library is used for for interfacing with an elasticsearch server.
Dependencies:
* Elasticsearch 1.7.3
Changes:
* Removed build & test files not needed for Mahara.
* Added an option to do include the Elasticsearch Index in the URL for bulk addDocument calls
Elastica: elasticsearch PHP Client
==================================
[![Latest Stable Version](https://poser.pugx.org/ruflin/Elastica/v/stable.png)](https://packagist.org/packages/ruflin/elastica)
[![Build Status](https://secure.travis-ci.org/ruflin/Elastica.png?branch=master)](http://travis-ci.org/ruflin/Elastica)
[![codecov.io](http://codecov.io/github/ruflin/Elastica/coverage.svg?branch=master)](http://codecov.io/github/ruflin/Elastica?branch=master)
[![Dependency Status](https://www.versioneye.com/php/ruflin:elastica/dev-master/badge.svg)](https://www.versioneye.com/php/ruflin:elastica/dev-master)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/ruflin/Elastica/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/ruflin/Elastica/?branch=master)
[![Total Downloads](https://poser.pugx.org/ruflin/Elastica/downloads.png)](https://packagist.org/packages/ruflin/elastica)
[![Flattr this git repo](http://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=ruflin&url=https://github.com/ruflin/Elastica&title=Elastica&language=PHP&tags=github&category=software)
[![Join the chat at https://gitter.im/ruflin/Elastica](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/ruflin/Elastica?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
All documentation for Elastica can be found under [Elastica.io](http://Elastica.io/).
If you have questions, don't hesitate to ask them on [Stackoverflow](http://stackoverflow.com/questions/tagged/elastica) and add the Tag "Elastica" or
in our [Gitter](https://gitter.im/ruflin/Elastica) channel.
All library issues should go to the [issue tracker from github](https://github.com/ruflin/Elastica/issues).
Contributing
------------
Contributions are always welcome. For details on how to contribute, check the [CONTRIBUTING](https://github.com/ruflin/Elastica/blob/master/CONTRIBUTING.md) file.
Dependencies
------------
| Project | Version | Required |
|---------|---------|----------|
|[Elasticsearch](https://github.com/elasticsearch/elasticsearch/tree/v1.7.2)|1.7.2|yes|
|[Elasticsearch mapper attachments plugin](https://github.com/elasticsearch/elasticsearch-mapper-attachments/tree/v2.7.0)|2.7.0|no|
|[Elasticsearch thrift transport plugin](https://github.com/elasticsearch/elasticsearch-transport-thrift/tree/v2.7.0)|2.7.0|no|
|[Elasticsearch memcached transport plugin](https://github.com/elastic/elasticsearch-transport-memcached/tree/v2.7.0)|2.7.0|no|
|[Elasticsearch geocluster facet plugin](https://github.com/zenobase/geocluster-facet/tree/0.0.12)|0.0.12|no|
|[Elasticsearch image plugin](https://github.com/Jmoati/elasticsearch-image/releases/tag/1.7.1)|1.7.1|no|
This diff is collapsed.
<?php
namespace Elastica;
/**
* Base class for Script object.
*
* @author Nicolas Assing <nicolas.assing@gmail.com>
*
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting.html
*/
abstract class AbstractScript extends AbstractUpdateAction
{
/**
* @param array|null $params
* @param string $id
*/
public function __construct(array $params = null, $id = null)
{
if ($params) {
$this->setParams($params);
}
if ($id) {
$this->setId($id);
}
}
}
<?php
namespace Elastica;
/**
* Base class for things that can be sent to the update api (Document and
* Script).
*
* @author Nik Everett <nik9000@gmail.com>
*/
class AbstractUpdateAction extends Param
{
/**
* @var \Elastica\Document
*/
protected $_upsert;
/**
* Sets the id of the document.
*
* @param string $id
*
* @return $this
*/
public function setId($id)
{
return $this->setParam('_id', $id);
}
/**
* Returns document id.
*
* @return string|int Document id
*/
public function getId()
{
return ($this->hasParam('_id')) ? $this->getParam('_id') : null;
}
/**
* @return bool
*/
public function hasId()
{
return '' !== (string) $this->getId();
}
/**
* Sets lifetime of document.
*
* @param string $ttl
*
* @return $this
*/
public function setTtl($ttl)
{
return $this->setParam('_ttl', $ttl);
}
/**
* @return string
*/
public function getTtl()
{
return $this->getParam('_ttl');
}
/**
* @return bool
*/
public function hasTtl()
{
return $this->hasParam('_ttl');
}
/**
* Sets the document type name.
*
* @param string $type Type name
*
* @return $this
*/
public function setType($type)
{
if ($type instanceof Type) {
$this->setIndex($type->getIndex());
$type = $type->getName();
}
return $this->setParam('_type', $type);
}
/**
* Return document type name.
*
* @throws \Elastica\Exception\InvalidException
*
* @return string Document type name
*/
public function getType()
{
return $this->getParam('_type');
}
/**
* Sets the document index name.
*
* @param string $index Index name
*
* @return $this
*/
public function setIndex($index)
{
if ($index instanceof Index) {
$index = $index->getName();
}
return $this->setParam('_index', $index);
}
/**
* Get the document index name.
*
* @throws \Elastica\Exception\InvalidException
*
* @return string Index name
*/
public function getIndex()
{
return $this->getParam('_index');
}
/**
* Sets the version of a document for use with optimistic concurrency control.
*
* @param int $version Document version
*
* @return $this
*
* @link https://www.elastic.co/blog/versioning
*/
public function setVersion($version)
{
return $this->setParam('_version', (int) $version);
}
/**
* Returns document version.
*
* @return string|int Document version
*/
public function getVersion()
{
return $this->getParam('_version');
}
/**
* @return bool
*/
public function hasVersion()
{
return $this->hasParam('_version');
}
/**
* Sets the version_type of a document
* Default in ES is internal, but you can set to external to use custom versioning.
*
* @param int $versionType Document version type
*
* @return $this
*/
public function setVersionType($versionType)
{
return $this->setParam('_version_type', $versionType);
}
/**
* Returns document version type.
*
* @return string|int Document version type
*/
public function getVersionType()
{
return $this->getParam('_version_type');
}
/**
* @return bool
*/
public function hasVersionType()
{
return $this->hasParam('_version_type');
}
/**
* Sets parent document id.
*
* @param string|int $parent Parent document id
*
* @return $this
*
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-parent-field.html
*/
public function setParent($parent)
{
return $this->setParam('_parent', $parent);
}
/**
* Returns the parent document id.
*
* @return string|int Parent document id
*/
public function getParent()
{
return $this->getParam('_parent');
}
/**
* @return bool
*/
public function hasParent()
{
return $this->hasParam('_parent');
}
/**
* Set operation type.
*
* @param string $opType Only accept create
*
* @return $this
*/
public function setOpType($opType)
{
return $this->setParam('_op_type', $opType);
}
/**
* Get operation type.
*
* @return string
*/
public function getOpType()
{
return $this->getParam('_op_type');
}
/**
* @return bool
*/
public function hasOpType()
{
return $this->hasParam('_op_type');
}
/**
* Set percolate query param.
*
* @param string $value percolator filter
*
* @return $this
*/
public function setPercolate($value = '*')
{
return $this->setParam('_percolate', $value);
}
/**
* Get percolate parameter.
*
* @return string
*/
public function getPercolate()
{
return $this->getParam('_percolate');
}
/**
* @return bool
*/
public function hasPercolate()
{
return $this->hasParam('_percolate');
}
/**
* Set routing query param.
*
* @param string $value routing
*
* @return $this
*/
public function setRouting($value)
{
return $this->setParam('_routing', $value);
}
/**
* Get routing parameter.
*
* @return string
*/
public function getRouting()
{
return $this->getParam('_routing');
}
/**
* @return bool
*/
public function hasRouting()
{
return $this->hasParam('_routing');
}
/**
* @param array|string $fields
*
* @return $this
*/
public function setFields($fields)
{
if (is_array($fields)) {
$fields = implode(',', $fields);
}
return $this->setParam('_fields', (string) $fields);
}
/**
* @return $this
*/
public function setFieldsSource()
{
return $this->setFields('_source');
}
/**
* @return string
*/
public function getFields()
{
return $this->getParam('_fields');
}
/**
* @return bool
*/
public function hasFields()
{
return $this->hasParam('_fields');
}
/**
* @param int $num
*
* @return $this
*/
public function setRetryOnConflict($num)
{
return $this->setParam('_retry_on_conflict', (int) $num);
}
/**
* @return int
*/
public function getRetryOnConflict()
{
return $this->getParam('_retry_on_conflict');
}
/**
* @return bool
*/
public function hasRetryOnConflict()
{
return $this->hasParam('_retry_on_conflict');
}
/**
* @param string $timestamp
*
* @return $this
*/
public function setTimestamp($timestamp)
{
return $this->setParam('_timestamp', $timestamp);
}
/**
* @return int
*/
public function getTimestamp()
{
return $this->getParam('_timestamp');
}
/**
* @return bool
*/
public function hasTimestamp()
{
return $this->hasParam('_timestamp');
}
/**
* @param bool $refresh
*
* @return $this
*/
public function setRefresh($refresh = true)
{
return $this->setParam('_refresh', (bool) $refresh);
}
/**
* @return bool
*/
public function getRefresh()
{
return $this->getParam('_refresh');
}
/**
* @return bool
*/
public function hasRefresh()
{
return $this->hasParam('_refresh');
}