Skip to content

Commit cdd9710

Browse files
giovannialbero1992Marek Hernik
authored and
Marek Hernik
committed
Added Reindex and deprecated CrossIndex (ruflin#1311) (ruflin#1315)
added changelog entry and asserts to config test added SpanOrTest added SpanMulti span functions in dsl query updated removed unnecessary attributes reverted docker ip range Changelog update Changelog update
1 parent 3b111b2 commit cdd9710

14 files changed

+932
-10
lines changed

CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,19 @@ All notable changes to this project will be documented in this file based on the
1212

1313
### Added
1414

15+
- Added `\Elastica\Query\Span*` for proximity searches [#304](https://github.com/ruflin/Elastica/issues/304)
1516
- Parameter `filter_path` for response filtering (e.g. `$index->search($query, ['filter_path' => 'hits.hits._source'])`)
1617
- Add support for Health parameters for Cluster\Health endpoint (new prop : delayed_unassigned_shards, number_of_pending_tasks, number_of_in_flight_fetch, task_max_waiting_in_queue_millis, active_shards_percent_as_number)
1718
- Add support for querystring in Type. this allow to use `update_all_types` in type mapping in order to resolve conflicts between fields in different types. [Conflicts between fields in different types](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html#merging-conflicts)
1819
- Added `\Elastica\Query\ParentId` to avoid join with parent documents [#1287](https://github.com/ruflin/Elastica/issues/1287)
20+
- Added `\Elastica\Reindex` for reindexing between indices [#1311](https://github.com/ruflin/Elastica/issues/1311)
1921

2022
### Improvements
2123

2224
- Added support for `other_bucket` and `other_bucket_key` paramters on `Elastica\Aggregation\Filters`
2325

2426
### Deprecated
25-
27+
- Deprecated `Tool\CrossIndex` use `\Elastica\Reindex` instead [#1311](https://github.com/ruflin/Elastica/issues/1311)
2628

2729
## [Unreleased](https://github.com/ruflin/Elastica/compare/5.1.0...5.2.0)
2830

lib/Elastica/Query/SpanMulti.php

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
namespace Elastica\Query;
3+
4+
use Elastica\Exception\InvalidException;
5+
6+
/**
7+
* SpanMulti query.
8+
*
9+
* @author Marek Hernik <[email protected]>
10+
*
11+
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-near-query.html
12+
*/
13+
class SpanMulti extends SpanQuery
14+
{
15+
/**
16+
* Constructs a SpanMulti query object.
17+
*
18+
* @param AbstractQuery $match OPTIONAL
19+
*/
20+
public function __construct(AbstractQuery $match = null)
21+
{
22+
if ($match) {
23+
$this->setMatch($match);
24+
}
25+
}
26+
27+
/**
28+
* Set match part to query.
29+
*
30+
* @param AbstractQuery $match
31+
*
32+
* @throws InvalidException
33+
*
34+
* @return $this
35+
*/
36+
public function setMatch(AbstractQuery $match)
37+
{
38+
if (!in_array(get_class($match), [Wildcard::class, Fuzzy::class, Prefix::class, Regexp::class])) {
39+
throw new InvalidException(
40+
'Invalid parameter. Has to be instance of WildcardQuery or FuzzyQuery or PrefixQuery od RegexpQuery'
41+
);
42+
}
43+
44+
return $this->setParams(['match' => $match]);
45+
}
46+
}

lib/Elastica/Query/SpanNear.php

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
namespace Elastica\Query;
3+
4+
use Elastica\Exception\InvalidException;
5+
6+
/**
7+
* SpanNear query.
8+
*
9+
* @author Marek Hernik <[email protected]>
10+
*
11+
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-near-query.html
12+
*/
13+
class SpanNear extends SpanQuery
14+
{
15+
/**
16+
* Constructs a SpanNear query object.
17+
*
18+
* @param SpanQuery[] $clauses OPTIONAL
19+
* @param int $slop OPTIONAL maximum proximity
20+
* @param bool $inOrder OPTIONAL true if order of searched clauses is important
21+
*/
22+
public function __construct(array $clauses = [], $slop = 1, $inOrder = false)
23+
{
24+
if (!empty($clauses)) {
25+
foreach ($clauses as $clause) {
26+
if (!is_subclass_of($clause, SpanQuery::class)) {
27+
throw new InvalidException(
28+
'Invalid parameter. Has to be array or instance of Elastica\Query\SpanQuery'
29+
);
30+
}
31+
}
32+
}
33+
$this->setParams(['clauses' => $clauses]);
34+
$this->setSlop($slop);
35+
$this->setInOrder($inOrder);
36+
}
37+
38+
/**
39+
* @param int $slop
40+
*/
41+
public function setSlop($slop)
42+
{
43+
$this->setParam('slop', $slop);
44+
}
45+
46+
/**
47+
* @param bool $inOrder
48+
*/
49+
public function setInOrder($inOrder)
50+
{
51+
$this->setParam('in_order', $inOrder);
52+
}
53+
54+
/**
55+
* Add clause part to query.
56+
*
57+
* @param SpanQuery $clause
58+
*
59+
* @throws InvalidException If not valid query
60+
*
61+
* @return $this
62+
*/
63+
public function addClause($clause)
64+
{
65+
if (!is_subclass_of($clause, SpanQuery::class)) {
66+
throw new InvalidException('Invalid parameter. Has to be array or instance of Elastica\Query\SpanQuery');
67+
}
68+
69+
return $this->addParam('clauses', $clause);
70+
}
71+
}

lib/Elastica/Query/SpanOr.php

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
namespace Elastica\Query;
3+
4+
use Elastica\Exception\InvalidException;
5+
6+
/**
7+
* SpanOr query.
8+
*
9+
* @author Marek Hernik <[email protected]>
10+
*
11+
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-term-query.html
12+
*/
13+
class SpanOr extends SpanQuery
14+
{
15+
/**
16+
* Constructs a SpanOr query object.
17+
*
18+
* @param SpanQuery[] $clauses OPTIONAL
19+
*/
20+
public function __construct(array $clauses = [])
21+
{
22+
if (!empty($clauses)) {
23+
foreach ($clauses as $clause) {
24+
if (!is_subclass_of($clause, SpanQuery::class)) {
25+
throw new InvalidException(
26+
'Invalid parameter. Has to be array or instance of Elastica\Query\SpanQuery'
27+
);
28+
}
29+
}
30+
}
31+
$this->setParams(['clauses' => $clauses]);
32+
}
33+
34+
/**
35+
* Add clause part to query.
36+
*
37+
* @param SpanQuery $clause
38+
*
39+
* @throws InvalidException If not valid query
40+
*
41+
* @return $this
42+
*/
43+
public function addClause($clause)
44+
{
45+
if (!is_subclass_of($clause, SpanQuery::class)) {
46+
throw new InvalidException('Invalid parameter. Has to be array or instance of Elastica\Query\SpanQuery');
47+
}
48+
49+
return $this->addParam('clauses', $clause);
50+
}
51+
}

lib/Elastica/Query/SpanQuery.php

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
namespace Elastica\Query;
3+
4+
/**
5+
* Span query.
6+
*
7+
* @author Marek Hernik <[email protected]>
8+
*
9+
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/span-queries.html
10+
*/
11+
class SpanQuery extends AbstractQuery
12+
{
13+
14+
}

lib/Elastica/Query/SpanTerm.php

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
namespace Elastica\Query;
3+
4+
/**
5+
* SpanTerm query.
6+
*
7+
* @author Marek Hernik <[email protected]>
8+
*
9+
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-term-query.html
10+
*/
11+
class SpanTerm extends SpanQuery
12+
{
13+
/**
14+
* Constructs the SpanTerm query object.
15+
*
16+
* @param string $field
17+
* @param string $value
18+
* @param float $boost OPTIONAL Boost value (default = 1)
19+
*/
20+
public function __construct($field, $value, $boost = 1.0)
21+
{
22+
$this->setRawTerm($field, $value, $boost);
23+
}
24+
25+
/**
26+
* Sets the query expression for a key with its boost value.
27+
*
28+
* @param string $field
29+
* @param string $value
30+
* @param float $boost
31+
*
32+
* @return $this
33+
*/
34+
public function setRawTerm($field, $value, $boost = 1.0)
35+
{
36+
return $this->setParam($field, ['value' => $value, 'boost' => $boost]);
37+
}
38+
}

lib/Elastica/QueryBuilder/DSL/Query.php

+29-9
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
use Elastica\Query\Range;
2727
use Elastica\Query\Regexp;
2828
use Elastica\Query\SimpleQueryString;
29+
use Elastica\Query\SpanMulti;
30+
use Elastica\Query\SpanNear;
31+
use Elastica\Query\SpanOr;
32+
use Elastica\Query\SpanTerm;
2933
use Elastica\Query\Term;
3034
use Elastica\Query\Terms;
3135
use Elastica\Query\Type;
@@ -365,17 +369,23 @@ public function span_first()
365369
*/
366370
public function span_multi_term()
367371
{
368-
throw new NotImplementedException();
372+
return new SpanMulti();
369373
}
370374

371375
/**
372376
* span near query.
373377
*
378+
* @param array $clauses
379+
* @param int $slop
380+
* @param bool $inOrder
381+
*
382+
* @return SpanNear
383+
*
374384
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-near-query.html
375385
*/
376-
public function span_near()
386+
public function span_near($clauses = [], $slop = 1, $inOrder = false)
377387
{
378-
throw new NotImplementedException();
388+
return new SpanNear($clauses, $slop, $inOrder);
379389
}
380390

381391
/**
@@ -389,23 +399,33 @@ public function span_not()
389399
}
390400

391401
/**
392-
* span or query.
402+
* span_or query.
403+
*
404+
* @param array $clauses
405+
*
406+
* @return SpanOr
393407
*
394408
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-or-query.html
395409
*/
396-
public function span_or()
410+
public function span_or($clauses = [])
397411
{
398-
throw new NotImplementedException();
412+
return new SpanOr($clauses);
399413
}
400414

401415
/**
402-
* span term query.
416+
* span_term query.
417+
*
418+
* @param string $key
419+
* @param string $value
420+
* @param float $boost
421+
*
422+
* @return SpanTerm
403423
*
404424
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-term-query.html
405425
*/
406-
public function span_term()
426+
public function span_term($key = '', $value = null, $boost = 1.0)
407427
{
408-
throw new NotImplementedException();
428+
return new SpanTerm($key, $value, $boost);
409429
}
410430

411431
/**

0 commit comments

Comments
 (0)