Permalink
Browse files

Merge branch 'master' of github.com:ruflin/Elastica

  • Loading branch information...
2 parents 3460fc4 + a63e9e7 commit 4fb60d3f32ce5faa039706faa0073f82b88b7b72 @ruflin committed Feb 24, 2013
Showing with 99 additions and 31 deletions.
  1. +1 −1 README.markdown
  2. +25 −5 build.xml
  3. +1 −1 composer.json
  4. +16 −0 lib/Elastica/ResultSet.php
  5. +6 −0 lib/Elastica/Search.php
  6. +34 −24 test/bin/run_elasticsearch.sh
  7. +16 −0 test/lib/Elastica/Test/SearchTest.php
View
2 README.markdown
@@ -25,7 +25,7 @@ The version numbers are consistent with elasticsearch. The version number 0.16.0
Compatibility
-------------
-Elastica is tested with PHP 5.3 and later. Versions prior and equal to v0.19.8.0 are compatible with PHP 5.2
+Elastica is tested with PHP 5.3.3 and later. Versions prior and equal to v0.19.8.0 are compatible with PHP 5.2
File indexing
-------------
View
30 build.xml
@@ -8,11 +8,11 @@
<sequential>
<antcall target="pdepend"/>
<antcall target="phpmd-ci"/>
+ <antcall target="phpcb"/>
</sequential>
<antcall target="phpcpd"/>
<antcall target="phpcs-ci"/>
- <antcall target="phpdoc"/>
- <antcall target="phpcb"/>
+ <antcall target="phpdoc-ci"/>
</parallel>
</target>
@@ -22,6 +22,7 @@
<delete dir="${basedir}/build/coverage"/>
<delete dir="${basedir}/build/logs"/>
<delete dir="${basedir}/build/pdepend"/>
+ <delete dir="${basedir}/build/docs"/>
<delete file="${basedir}/cache.properties"/>
</target>
@@ -30,6 +31,7 @@
<mkdir dir="${basedir}/build/code-browser"/>
<mkdir dir="${basedir}/build/coverage"/>
<mkdir dir="${basedir}/build/logs"/>
+ <mkdir dir="${basedir}/build/docs"/>
<mkdir dir="${basedir}/build/pdepend"/>
</target>
@@ -55,6 +57,13 @@
</exec>
</target>
+ <target name="composer" depends="prepare" description="Install dependencies">
+ <exec executable="composer">
+ <arg value="--dev"></arg>
+ <arg value="install"></arg>
+ </exec>
+ </target>
+
<target name="lint">
<apply executable="php" failonerror="true">
<arg value="-lf"/>
@@ -71,7 +80,7 @@
</apply>
</target>
- <target name="phpunit" depends="prepare">
+ <target name="phpunit" depends="composer">
<exec executable="phpunit" dir="${basedir}/test" failonerror="off" />
</target>
@@ -121,6 +130,17 @@
<target name="phpdoc">
<exec executable="phpdoc">
<arg line="run" />
+ <arg line="-d lib/" />
+ <arg line="-t build/docs" />
+ </exec>
+ </target>
+
+ <target name="phpdoc-ci">
+ <exec executable="phpdoc">
+ <arg line="run" />
+ <arg line="-d lib/" />
+ <arg line="-t build/docs" />
+ <arg line="-q" />
</exec>
</target>
@@ -132,7 +152,7 @@
</exec>
</target>
- <target name="build" depends="prepare,lint,parallelTasks,phpunit"/>
+ <target name="build" depends="prepare,composer,lint,parallelTasks,phpunit"/>
<!-- Checkstyle with human output -->
<target name="phpcs">
@@ -187,7 +207,7 @@
<arg line="install phpunit/phploc" />
</exec>
<exec executable="pear">
- <arg line="install channel://pear.phpdoc.org/phpDocumentor-2.0.0a2" />
+ <arg line="install phpdoc/phpDocumentor-alpha" />
</exec>
<exec executable="pear">
<arg line="install PHP_CodeSniffer" />
View
2 composer.json
@@ -12,7 +12,7 @@
}
],
"require": {
- "php": ">=5.3.0"
+ "php": ">=5.3.3"
},
"require-dev": {
"phpunit/phpunit": "3.7.*",
View
16 lib/Elastica/ResultSet.php
@@ -48,6 +48,11 @@ class ResultSet implements \Iterator, \Countable
protected $_took = 0;
/**
+ * @var boolean
+ */
+ protected $_timed_out = false;
+
+ /**
* @var int
*/
protected $_totalHits = 0;
@@ -76,6 +81,7 @@ protected function _init(Response $response)
$result = $response->getData();
$this->_totalHits = isset($result['hits']['total']) ? $result['hits']['total'] : 0;
$this->_took = isset($result['took']) ? $result['took'] : 0;
+ $this->_timed_out = !empty($result['timed_out']);
if (isset($result['hits']['hits'])) {
foreach ($result['hits']['hits'] as $hit) {
$this->_results[] = new Result($hit);
@@ -138,6 +144,16 @@ public function getTotalTime()
}
/**
+ * Returns true iff the query has timed out
+ *
+ * @return bool Timed out
+ */
+ public function hasTimedOut()
+ {
+ return (bool) $this->_timed_out;
+ }
+
+ /**
* Returns response object
*
* @return \Elastica\Response Response object
View
6 lib/Elastica/Search.php
@@ -20,6 +20,9 @@ class Search implements SearchableInterface
const OPTION_ROUTING = 'routing';
const OPTION_PREFERENCE = 'preference';
const OPTION_VERSION = 'version';
+ const OPTION_TIMEOUT = 'timeout';
+ const OPTION_FROM = 'from';
+ const OPTION_SIZE = 'size';
/*
* Search types
@@ -257,6 +260,9 @@ protected function _validateOption($key)
case self::OPTION_ROUTING:
case self::OPTION_PREFERENCE:
case self::OPTION_VERSION:
+ case self::OPTION_TIMEOUT:
+ case self::OPTION_FROM:
+ case self::OPTION_SIZE:
return true;
}
View
58 test/bin/run_elasticsearch.sh
@@ -1,37 +1,47 @@
#!/bin/bash
+check_port_http_code() {
+ http_code=`echo $(curl -s -o /dev/null -w "%{http_code}" "http://localhost:$1")`
+ return `test $http_code = "$2"`
+}
+
wget http://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-${ES_VER}.tar.gz
tar -xzf elasticsearch-${ES_VER}.tar.gz
-sed 's/# index.number_of_shards: 1/index.number_of_shards: 2/' elasticsearch-${ES_VER}/config/elasticsearch.yml > elasticsearch-${ES_VER}/config/elasticsearch.yml
-sed 's/# index.number_of_replicas: 0/index.number_of_replicas: 0/' elasticsearch-${ES_VER}/config/elasticsearch.yml > elasticsearch-${ES_VER}/config/elasticsearch.yml
-sed 's/# discovery.zen.ping.multicast.enabled: false/discovery.zen.ping.multicast.enabled: false/' elasticsearch-${ES_VER}/config/elasticsearch.yml > elasticsearch-${ES_VER}/config/elasticsearch.yml
+
elasticsearch-${ES_VER}/bin/plugin -install elasticsearch/elasticsearch-mapper-attachments/${ES_MAPPER_ATTACHMENTS_VER}
elasticsearch-${ES_VER}/bin/plugin -install elasticsearch/elasticsearch-transport-thrift/${ES_TRANSPORT_THRIFT_VER}
export JAVA_OPTS="-server"
-elasticsearch-${ES_VER}/bin/elasticsearch &
-elasticsearch-${ES_VER}/bin/elasticsearch &
-elasticsearch-${ES_VER}/bin/elasticsearch &
-
-echo "Waiting until elasticsearch node 1 is ready on port 9200"
-while [[ -z `curl -s 'http://localhost:9200' ` ]]
-do
- echo -n "."
- sleep 2s
-done
-echo "Waiting until elasticsearch node 2 is ready on port 9201"
-while [[ -z `curl -s 'http://localhost:9201' ` ]]
-do
- echo -n "."
- sleep 2s
-done
-
-echo "Waiting until elasticsearch node 3 is ready on port 9202"
-while [[ -z `curl -s 'http://localhost:9202' ` ]]
+for i in 0 1 2
do
- echo -n "."
- sleep 2s
+ echo "Setup node #$i"
+
+ let "http_port = 9200 + $i"
+ let "thrift_port = 9500 + $i"
+
+ config_yml=elasticsearch-${ES_VER}/config/elasticsearch-$http_port.yml
+
+ echo "Creating config $config_yml"
+
+ cp elasticsearch-${ES_VER}/config/elasticsearch.yml $config_yml
+
+ echo "index.number_of_shards: 2" >> $config_yml
+ echo "index.number_of_replicas: 0" >> $config_yml
+ echo "discovery.zen.ping.multicast.enabled: false" >> $config_yml
+ echo "http.port: $http_port" >> $config_yml
+ echo "thrift.port: $thrift_port" >> $config_yml
+
+ echo "Starting server on http port: $http_port"
+
+ elasticsearch-${ES_VER}/bin/elasticsearch -Des.config=$config_yml &
+
+ while ! check_port_http_code $http_port 200; do
+ echo -n "."
+ sleep 2s
+ done
+ echo ""
+ echo "Server #$i is up"
done
echo "three elasticsearch nodes are up"
View
16 test/lib/Elastica/Test/SearchTest.php
@@ -6,6 +6,8 @@
use Elastica\Document;
use Elastica\Query\MatchAll;
use Elastica\Query\QueryString;
+use Elastica\Query\CustomScore;
+use Elastica\Script;
use Elastica\Search;
use Elastica\Test\Base as BaseTest;
@@ -271,6 +273,14 @@ public function testArrayConfigSearch()
$resultSet = $search->search('test', array('limit' => 2));
$this->assertEquals(2, $resultSet->count());
+ //Array with size
+ $resultSet = $search->search('test', array('size' => 2));
+ $this->assertEquals(2, $resultSet->count());
+
+ //Array with from
+ $resultSet = $search->search('test', array('from' => 10));
+ $this->assertEquals(10, $resultSet->current()->getId());
+
//Array with routing
$resultSet = $search->search('test', array('routing' => 'r1,r2'));
$this->assertEquals(10, $resultSet->count());
@@ -283,6 +293,12 @@ public function testArrayConfigSearch()
$resultSet = $search->search('test', array('limit' => 5, 'search_type' => 'count'));
$this->assertTrue(($resultSet->count() === 0) && $resultSet->getTotalHits() === 11);
+ //Timeout - this one is a bit more tricky to test
+ $script = new Script('Thread.sleep(100); return _score;');
+ $query = new CustomScore($script, 'test');
+ $resultSet = $search->search($query, array('timeout' => 50));
+ $this->assertTrue($resultSet->hasTimedOut());
+
// Throws InvalidException
$resultSet = $search->search('test', array('invalid_option' => 'invalid_option_value'));
}

0 comments on commit 4fb60d3

Please sign in to comment.