1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kaliop\EzFindSearchEngineBundle\Command; |
4
|
|
|
|
5
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
6
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
7
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
8
|
|
|
use eZ\Publish\API\Repository\Values\Content\Content; |
9
|
|
|
use eZ\Publish\API\Repository\Values\Content\Query\Criterion; |
10
|
|
|
use eZ\Publish\API\Repository\Values\Content\Query\SortClause; |
11
|
|
|
use Kaliop\EzFindSearchEngineBundle\API\Repository\Values\Content\Query as KQuery; |
12
|
|
|
use Kaliop\EzFindSearchEngineBundle\API\Repository\Values\Content\Query\SortClause as KSortClause; |
13
|
|
|
use Kaliop\EzFindSearchEngineBundle\API\Repository\Values\Content\Query\Criterion as KCriterion; |
14
|
|
|
|
15
|
|
|
class TestCommand extends ContainerAwareCommand |
16
|
|
|
{ |
17
|
|
|
protected function configure() |
18
|
|
|
{ |
19
|
|
|
$this->setName('kaliop:eseb:test') |
20
|
|
|
; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
24
|
|
|
{ |
25
|
|
|
|
26
|
|
|
// HACK to make sure ezfind modules and fetch functions are active. |
27
|
|
|
// The problem still remains though: the rest of the legacy kernel will not be loaded correctly... |
28
|
|
|
$legacyKernelClosure = $this->getContainer()->get('ezpublish_legacy.kernel'); |
29
|
|
|
$legacyKernel = $legacyKernelClosure(); |
30
|
|
|
$legacyKernel->runCallback( |
31
|
|
|
function () { |
32
|
|
|
$moduleRepositories = \eZModule::activeModuleRepositories(true); |
33
|
|
|
$moduleRepositories[] = 'extension/ezfind/modules'; |
34
|
|
|
//var_dump($moduleRepositories); |
35
|
|
|
\eZModule::setGlobalPathList( $moduleRepositories ); |
36
|
|
|
}, |
37
|
|
|
false |
38
|
|
|
); |
39
|
|
|
|
40
|
|
|
$searchService = $this->getContainer()->get('ezfind_search_engine.api.service.search'); |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
$query = new KQuery(); |
44
|
|
|
$query->query = new Criterion\LogicalOr([ |
45
|
|
|
new Criterion\LogicalAnd([ |
46
|
|
|
new Criterion\ContentTypeIdentifier('fs_article'), |
47
|
|
|
new Criterion\Subtree('/1/2/'), |
48
|
|
|
new Criterion\ParentLocationId(128), |
49
|
|
|
new Criterion\FullText('spuerscript'), |
50
|
|
|
new Criterion\Field('fs_article/strapline', Criterion\Operator::CONTAINS, 'ome'), |
51
|
|
|
new Criterion\Field('fs_article/strapline', Criterion\Operator::LIKE, 's_m%'), |
52
|
|
|
new Criterion\Field('fs_article/integer', Criterion\Operator::GT, 12), |
53
|
|
|
new Criterion\Field('fs_article/integer', Criterion\Operator::IN, array(23, 32)), |
54
|
|
|
]), |
55
|
|
|
new Criterion\ContentTypeIdentifier('folder'), |
56
|
|
|
new Criterion\LogicalAnd([ |
57
|
|
|
new Criterion\SectionId(1), |
58
|
|
|
new Criterion\ContentId(5), |
59
|
|
|
new Criterion\LocationId(5), |
60
|
|
|
new Criterion\LocationPriority(Criterion\Operator::GT, 0), |
|
|
|
|
61
|
|
|
new Criterion\RemoteId('abcdefg:ka and bb:cc'), |
62
|
|
|
new Criterion\DateMetadata(Criterion\DateMetadata::CREATED, Criterion\Operator::GT, 500000000), |
63
|
|
|
new KCriterion\SolrRaw('NOT(meta_path_string_ms:bbbb^4 OR meta_path_string_ms:bbba^4 AND (meta_path_string_ms:hello OR meta_path_string_ms:world))'), |
64
|
|
|
new Criterion\LogicalNot(new Criterion\RemoteId('abcdefg')), |
65
|
|
|
new Criterion\UserMetadata(Criterion\UserMetadata::OWNER, Criterion\Operator::EQ, 14), |
66
|
|
|
]) |
67
|
|
|
]); |
68
|
|
|
|
69
|
|
|
$query->limit = 10; |
70
|
|
|
//$query->offset = $searchOffset; |
71
|
|
|
|
72
|
|
|
$query->sortClauses = [ |
73
|
|
|
//new KSortClause\Score(KQuery::SORT_DESC) |
74
|
|
|
//new SortClause\ContentId(KQuery::SORT_ASC) |
75
|
|
|
new SortClause\LocationPathString(KQuery::SORT_DESC) |
|
|
|
|
76
|
|
|
]; |
77
|
|
|
|
78
|
|
|
//$query->returnType = KQuery::RETURN_EZFIND_DATA; |
79
|
|
|
|
80
|
|
|
$results = $searchService->findContent($query); |
81
|
|
|
|
82
|
|
|
echo "count: "; var_dump(count($results->searchHits)); |
|
|
|
|
83
|
|
|
echo "totalCount: "; var_dump($results->totalCount); |
84
|
|
|
echo "time (ms): "; var_dump($results->time); |
85
|
|
|
echo "maxScore: "; var_dump($results->maxScore); |
86
|
|
|
echo "q: "; var_dump($results->searchExtras->attribute('responseHeader')['params']['q']); |
87
|
|
|
echo "fq: "; var_dump($results->searchExtras->attribute('responseHeader')['params']['fq']); |
88
|
|
|
echo "sort: "; var_dump($results->searchExtras->attribute('responseHeader')['params']['sort']); |
89
|
|
|
|
90
|
|
|
foreach($results->searchHits as $i => $searchHit) { |
91
|
|
|
/** @var Content $content */ |
92
|
|
|
$content = $searchHit->valueObject; |
93
|
|
|
$score = $searchHit->score; |
|
|
|
|
94
|
|
|
//echo "hit $i: obj ".$content->id.', score '.$score."\n"; |
95
|
|
|
var_dump($content); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
//var_dump($results->searchExtras); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.