Skip to content

Commit a690b02

Browse files
committed
Merge pull request #32 from Flowpack/dev-searchcommons
[TASK] merge branch dev-searchcommons into master
2 parents 34d768e + cee5367 commit a690b02

18 files changed

Lines changed: 246 additions & 1005 deletions

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use TYPO3\Flow\Annotations as Flow;
1515
use TYPO3\Flow\Cli\CommandController;
1616
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Mapping\NodeTypeMappingBuilder;
17+
use TYPO3\TYPO3CR\Search\Indexer\NodeIndexingManager;
1718

1819
/**
1920
* Provides CLI features for index handling
@@ -30,7 +31,7 @@ class NodeIndexCommandController extends CommandController {
3031

3132
/**
3233
* @Flow\Inject
33-
* @var \Flowpack\ElasticSearch\ContentRepositoryAdaptor\Indexer\NodeIndexingManager
34+
* @var NodeIndexingManager
3435
*/
3536
protected $nodeIndexingManager;
3637

@@ -59,6 +60,7 @@ class NodeIndexCommandController extends CommandController {
5960
protected $nodeTypeMappingBuilder;
6061

6162
/**
63+
* @Flow\Inject
6264
* @var \Flowpack\ElasticSearch\ContentRepositoryAdaptor\LoggerInterface
6365
*/
6466
protected $logger;

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

Lines changed: 0 additions & 141 deletions
This file was deleted.

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

Lines changed: 59 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313
* */
1414

1515
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception\QueryBuildingException;
16+
use TYPO3\Eel\ProtectedContextAwareInterface;
1617
use TYPO3\Flow\Annotations as Flow;
1718
use TYPO3\TYPO3CR\Domain\Model\NodeInterface;
19+
use TYPO3\TYPO3CR\Search\Search\QueryBuilderInterface;
1820

1921
/**
2022
* Query Builder for ElasticSearch Queries
2123
*/
22-
class ElasticSearchQueryBuilder implements \TYPO3\Eel\ProtectedContextAwareInterface {
24+
class ElasticSearchQueryBuilder implements QueryBuilderInterface, ProtectedContextAwareInterface {
2325

2426
/**
2527
* @Flow\Inject
@@ -77,6 +79,14 @@ class ElasticSearchQueryBuilder implements \TYPO3\Eel\ProtectedContextAwareInter
7779
// Reference: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-filtered-query.html
7880
'filtered' => array(
7981
'query' => array(
82+
'bool' => array(
83+
'must' => array(
84+
array(
85+
'match_all' => array()
86+
)
87+
)
88+
)
89+
8090
),
8191
'filter' => array(
8292
// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-bool-filter.html
@@ -108,22 +118,6 @@ class ElasticSearchQueryBuilder implements \TYPO3\Eel\ProtectedContextAwareInter
108118
'fields' => array('__path')
109119
);
110120

111-
/**
112-
* @param NodeInterface $contextNode
113-
*/
114-
public function __construct(NodeInterface $contextNode) {
115-
// on indexing, the __parentPath is tokenized to contain ALL parent path parts,
116-
// e.g. /foo, /foo/bar/, /foo/bar/baz; to speed up matching.. That's why we use a simple "term" filter here.
117-
// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-term-filter.html
118-
$this->queryFilter('term', array('__parentPath' => $contextNode->getPath()));
119-
120-
//
121-
// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-terms-filter.html
122-
$this->queryFilter('terms', array('__workspace' => array('live', $contextNode->getContext()->getWorkspace()->getName())));
123-
124-
$this->contextNode = $contextNode;
125-
}
126-
127121
/**
128122
* HIGH-LEVEL API
129123
*/
@@ -299,16 +293,6 @@ public function getRequest() {
299293
return $this->request;
300294
}
301295

302-
/**
303-
* All methods are considered safe
304-
*
305-
* @param string $methodName
306-
* @return boolean
307-
*/
308-
public function allowsCallOfMethod($methodName) {
309-
return TRUE;
310-
}
311-
312296
/**
313297
* Log the current request to the ElasticSearch log for debugging after it has been executed.
314298
*
@@ -401,4 +385,52 @@ public function count() {
401385
return $count;
402386
}
403387

388+
/**
389+
* Match the searchword against the fulltext index
390+
*
391+
* @param string $searchWord
392+
* @return QueryBuilderInterface
393+
*/
394+
public function fulltext($searchWord) {
395+
396+
$this->appendAtPath('query.filtered.query.bool.must', array(
397+
'query_string' => array(
398+
'query' => $searchWord
399+
)
400+
));
401+
return $this;
402+
}
403+
404+
/**
405+
* Sets the starting point for this query. Search result should only contain nodes that
406+
* match the context of the given node and have it as parent node in their rootline.
407+
*
408+
* @param NodeInterface $contextNode
409+
* @return QueryBuilderInterface
410+
*/
411+
public function query(NodeInterface $contextNode) {
412+
// on indexing, the __parentPath is tokenized to contain ALL parent path parts,
413+
// e.g. /foo, /foo/bar/, /foo/bar/baz; to speed up matching.. That's why we use a simple "term" filter here.
414+
// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-term-filter.html
415+
$this->queryFilter('term', array('__parentPath' => $contextNode->getPath()));
416+
417+
//
418+
// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-terms-filter.html
419+
$this->queryFilter('terms', array('__workspace' => array('live', $contextNode->getContext()->getWorkspace()->getName())));
420+
421+
$this->contextNode = $contextNode;
422+
423+
return $this;
424+
}
425+
426+
427+
/**
428+
* All methods are considered safe
429+
*
430+
* @param string $methodName
431+
* @return boolean
432+
*/
433+
public function allowsCallOfMethod($methodName) {
434+
return TRUE;
435+
}
404436
}

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

Lines changed: 0 additions & 94 deletions
This file was deleted.

0 commit comments

Comments
 (0)