Skip to content

Commit fe76398

Browse files
committed
Merge branch 'master' into nodeinterface
2 parents 7182a10 + 0cc91db commit fe76398

7 files changed

Lines changed: 113 additions & 23 deletions

File tree

Classes/Flowpack/ElasticSearch/ContentRepositoryAdaptor/Command/NodeIndexCommandController.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public function showMappingCommand() {
132132
* This command (re-)indexes all nodes contained in the content repository and sets the schema beforehand.
133133
*
134134
* @param integer $limit Amount of nodes to index at maximum
135-
* @param bool $update if TRUE, do not throw away the index at the start. Should *only be used for development*.
135+
* @param boolean $update if TRUE, do not throw away the index at the start. Should *only be used for development*.
136136
* @param string $workspace name of the workspace which should be indexed
137137
* @return void
138138
*/
@@ -223,7 +223,7 @@ protected function indexWorkspace($workspaceName) {
223223
* @param array $dimensions
224224
* @return void
225225
*/
226-
protected function indexWorkspaceWithDimensions($workspaceName, $dimensions = array()) {
226+
protected function indexWorkspaceWithDimensions($workspaceName, array $dimensions = array()) {
227227
$context = $this->contextFactory->create(array('workspaceName' => $workspaceName, 'dimensions' => $dimensions));
228228
$rootNode = $context->getRootNode();
229229

@@ -241,6 +241,7 @@ protected function indexWorkspaceWithDimensions($workspaceName, $dimensions = ar
241241

242242
/**
243243
* @param \TYPO3\TYPO3CR\Domain\Model\NodeInterface $currentNode
244+
* @return void
244245
*/
245246
protected function traverseNodes(\TYPO3\TYPO3CR\Domain\Model\NodeInterface $currentNode) {
246247

@@ -291,4 +292,4 @@ protected function calculateDimensionCombinations() {
291292

292293
return $combinations;
293294
}
294-
}
295+
}

Classes/Flowpack/ElasticSearch/ContentRepositoryAdaptor/Eel/ElasticSearchQueryBuilder.php

Lines changed: 66 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ class ElasticSearchQueryBuilder implements QueryBuilderInterface, ProtectedConte
6262
*/
6363
protected $from;
6464

65+
/**
66+
* These fields are not accepted in a count request and must therefore be removed before doing so
67+
*
68+
* @var array
69+
*/
70+
protected $unsupportedFieldsInCountRequest = array('fields', 'sort', 'from', 'size');
71+
6572
/**
6673
* The ElasticSearch request, as it is being built up.
6774
* @var array
@@ -229,16 +236,61 @@ public function from($from) {
229236
/**
230237
* add an exact-match query for a given property
231238
*
232-
* @param $propertyName
233-
* @param $propertyValue
239+
* @param string $propertyName Name of the property
240+
* @param mixed $value Value for comparison
234241
* @return ElasticSearchQueryBuilder
235242
*/
236-
public function exactMatch($propertyName, $propertyValue) {
237-
if ($propertyValue instanceof NodeInterface) {
238-
$propertyValue = $propertyValue->getIdentifier();
243+
public function exactMatch($propertyName, $value) {
244+
if ($value instanceof NodeInterface) {
245+
$value = $value->getIdentifier();
239246
}
240247

241-
return $this->queryFilter('term', array($propertyName => $propertyValue));
248+
return $this->queryFilter('term', array($propertyName => $value));
249+
}
250+
251+
/**
252+
* add a range filter (gt) for the given property
253+
*
254+
* @param string $propertyName Name of the property
255+
* @param mixed $value Value for comparison
256+
* @return ElasticSearchQueryBuilder
257+
*/
258+
public function greaterThan($propertyName, $value) {
259+
return $this->queryFilter('range', array($propertyName => array('gt' => $value)));
260+
}
261+
262+
/**
263+
* add a range filter (gte) for the given property
264+
*
265+
* @param string $propertyName Name of the property
266+
* @param mixed $value Value for comparison
267+
* @return ElasticSearchQueryBuilder
268+
*/
269+
public function greaterThanOrEqual($propertyName, $value) {
270+
return $this->queryFilter('range', array($propertyName => array('gte' => $value)));
271+
}
272+
273+
/**
274+
* add a range filter (lt) for the given property
275+
*
276+
* @param string $propertyName Name of the property
277+
* @param mixed $value Value for comparison
278+
* @return ElasticSearchQueryBuilder
279+
*/
280+
public function lessThan($propertyName, $value) {
281+
return $this->queryFilter('range', array($propertyName => array('lt' => $value)));
282+
}
283+
284+
285+
/**
286+
* add a range filter (lte) for the given property
287+
*
288+
* @param string $propertyName Name of the property
289+
* @param mixed $value Value for comparison
290+
* @return ElasticSearchQueryBuilder
291+
*/
292+
public function lessThanOrEqual($propertyName, $value) {
293+
return $this->queryFilter('range', array($propertyName => array('lte' => $value)));
242294
}
243295

244296
/**
@@ -374,7 +426,14 @@ public function execute() {
374426
*/
375427
public function count() {
376428
$timeBefore = microtime(TRUE);
377-
$response = $this->elasticSearchClient->getIndex()->request('GET', '/_count', array(), json_encode($this->request));
429+
$request = $this->request;
430+
foreach ($this->unsupportedFieldsInCountRequest as $field) {
431+
if (isset($request[$field])) {
432+
unset($request[$field]);
433+
}
434+
}
435+
436+
$response = $this->elasticSearchClient->getIndex()->request('GET', '/_count', array(), json_encode($request));
378437
$timeAfterwards = microtime(TRUE);
379438

380439
$treatedContent = $response->getTreatedContent();

Configuration/NodeTypes.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
type: date
7777
include_in_all: false
7878
format: 'date_time_no_millis'
79-
indexing: '${(node.hiddenBeforeDateTime ? node.hiddenBeforeDateTime.format("Y-m-d\TH:i:s") + "Z" : null)}'
79+
indexing: '${(node.hiddenBeforeDateTime ? Date.format(node.hiddenBeforeDateTime, "Y-m-d\TH:i:s") + "Z" : null)}'
8080

8181

8282
'_hiddenAfterDateTime':
@@ -85,7 +85,7 @@
8585
type: date
8686
include_in_all: false
8787
format: 'date_time_no_millis'
88-
indexing: '${(node.hiddenAfterDateTime ? node.hiddenAfterDateTime.format("Y-m-d\TH:i:s") + "Z" : null)}'
88+
indexing: '${(node.hiddenAfterDateTime ? Date.format(node.hiddenAfterDateTime, "Y-m-d\TH:i:s") + "Z" : null)}'
8989

9090

9191
'TYPO3.Neos:Document':

Documentation/Index.rst

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@ TYPO3 Flow Package for indexing Nodes from TYPO3 Neos to ElasticSearch.
99
Setup
1010
-----
1111

12-
To be able indexing nodes into ElasticSearch there must be an index at all. This has to be 'neos'.
12+
To be able indexing nodes into ElasticSearch there must be an index at all.
1313
This can be created on console like this when the ElasticSearch Server is running::
1414

15-
curl -XPUT 'http://localhost:9200/neos/'
15+
curl -XPUT 'http://localhost:9200/typo3cr/'
1616

1717
Other wise you get an error message like this::
1818

1919
{
20-
"error" : "IndexMissingException[[neos] missing]",
20+
"error" : "IndexMissingException[[typo3cr] missing]",
2121
"status" : 404
2222
}
2323

24-
To be sure that the 'neos' index was created use the following url in your browser::
24+
To be sure that the 'typo3cr' index was created use the following url in your browser::
2525

26-
http://localhost:9200/neos/_search?pretty
26+
http://localhost:9200/typo3cr/_search?pretty
2727

2828
The output should be like this::
2929

@@ -41,3 +41,7 @@ The output should be like this::
4141
"hits" : [ ]
4242
}
4343
}
44+
45+
It is recommended to use an index name that corresponds to the project you are indexing to avoid
46+
clashes by using the same index in different projects. The index name can be changed in the
47+
settings.

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,11 @@ search underneath the current site node (like in the example above).
172172
Furthermore, the following operators are supported:
173173

174174
* `nodeType("Your.Node:Type")`
175-
* `exactMatch(key, value)`; supports simple types: `exactMatch('tag', 'foo')`, or node references: `exactMatch('author', authorNode)`
175+
* `exactMatch('propertyName', value)`; supports simple types: `exactMatch('tag', 'foo')`, or node references: `exactMatch('author', authorNode)`
176+
* `greaterThan('propertyName', value)` -- range filter with property values greater than the given value
177+
* `greaterThanOrEqual('propertyName', value)` -- range filter with property values greater than or equal to the given value
178+
* `lessThan('propertyName', value)` -- range filter with property values less than the given value
179+
* `lessThanOrEqual('propertyName', value)` -- range filter with property values less than or equal to the given value
176180
* `sortAsc('propertyName')` and `sortDesc('propertyName')` -- can also be used multiple times, e.g. `sortAsc('tag').sortDesc(`date')` will first sort by tag ascending, and then by date descending.
177181
* `limit(5)` -- only return five results. If not specified, the default limit by ElasticSearch applies (which is at 10 by default)
178182
* `from(5)` -- return the results starting from the 6th one
@@ -285,7 +289,7 @@ TYPO3:
285289
type: date
286290
include_in_all: false
287291
format: 'date_time_no_millis'
288-
indexing: '${(node.hiddenBeforeDateTime ? node.hiddenBeforeDateTime.format("Y-m-d\TH:i:s") + "Z" : null)}'
292+
indexing: '${(node.hiddenBeforeDateTime ? Date.format(node.hiddenBeforeDateTime, "Y-m-d\TH:i:s") + "Z" : null)}'
289293
```
290294

291295
There are a few indexing helpers inside the `Indexing` namespace which are usable inside the
@@ -347,4 +351,4 @@ In order to understand what's going on, the following commands are helpful:
347351

348352
* use `./flow nodeindex:showMapping` to show the currently defined ElasticSearch Mapping
349353
* use the `.log()` statement inside queries to dump them to the ElasticSearch Log
350-
* the logfile `Data/Logs/ElasticSearch.log` contains loads of helpful information.
354+
* the logfile `Data/Logs/ElasticSearch.log` contains loads of helpful information.

Tests/Unit/Eel/ElasticSearchQueryBuilderTest.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ public function limitWorks() {
160160
$this->assertSame(2, $actual['size']);
161161
}
162162

163-
164163
/**
165164
* @test
166165
*/
@@ -175,6 +174,30 @@ public function sortDescWorks() {
175174
$this->assertSame($expected, $actual['sort']);
176175
}
177176

177+
public function rangeConstraintExamples() {
178+
return array(
179+
array('greaterThan', 'gt', 10),
180+
array('greaterThanOrEqual', 'gte', 20),
181+
array('lessThan', 'lt', 'now'),
182+
array('lessThanOrEqual', 'lte', 40)
183+
);
184+
}
185+
186+
/**
187+
* @test
188+
* @dataProvider rangeConstraintExamples
189+
*/
190+
public function rangeConstraintsWork($constraint, $operator, $value) {
191+
$this->queryBuilder->$constraint('fieldName', $value);
192+
$expected = array(
193+
'range' => array(
194+
'fieldName' => array($operator => $value)
195+
)
196+
);
197+
$actual = $this->queryBuilder->getRequest();
198+
$this->assertInArray($expected, $actual['query']['filtered']['filter']['bool']['must']);
199+
}
200+
178201
/**
179202
* Test helper
180203
*

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
{
22
"name": "flowpack/elasticsearch-contentrepositoryadaptor",
33
"type": "typo3-flow-package",
4-
"description": "This package provides functionality for the interaction of elasticsearch engine and TYPO3CR.",
4+
"description": "This package provides functionality for using Elasticsearch on top of TYPO3CR.Search",
55
"homepage": "http://flowpack.org/",
66
"license": ["LGPL-3.0+"],
77
"require": {
88
"flowpack/elasticsearch": "*",
99
"typo3/eel": "*",
10-
"typo3/typo3cr": "*",
1110
"typo3/typo3cr-search": "*"
1211
},
1312
"autoload": {

0 commit comments

Comments
 (0)