TestCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 20

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 20
dl 0
loc 86
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 5 1
B execute() 0 77 2
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),
0 ignored issues
show
Deprecated Code introduced by
The class eZ\Publish\API\Repositor...terion\LocationPriority has been deprecated with message: Since 5.3, use Location search instead

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.

Loading history...
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)
0 ignored issues
show
Deprecated Code introduced by
The class eZ\Publish\API\Repositor...ause\LocationPathString has been deprecated with message: Since 5.3, use Location search instead

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.

Loading history...
76
        ];
77
78
        //$query->returnType = KQuery::RETURN_EZFIND_DATA;
79
80
        $results = $searchService->findContent($query);
81
82
        echo "count: "; var_dump(count($results->searchHits));
0 ignored issues
show
Security Debugging Code introduced by
var_dump(count($results->searchHits)); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
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;
0 ignored issues
show
Unused Code introduced by
$score is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
94
            //echo "hit $i: obj ".$content->id.', score '.$score."\n";
95
            var_dump($content);
96
        }
97
98
        //var_dump($results->searchExtras);
99
    }
100
}
101