|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace Doctrine\ODM\CouchDB\View; |
|
5
|
|
|
|
|
6
|
|
|
use Doctrine\CouchDB\View\LuceneQuery; |
|
7
|
|
|
use Doctrine\ODM\CouchDB\DocumentManager; |
|
8
|
|
|
|
|
9
|
|
|
class ODMLuceneQuery extends LuceneQuery |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* @var DocumentManager |
|
13
|
|
|
*/ |
|
14
|
|
|
private $dm; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @var bool |
|
18
|
|
|
*/ |
|
19
|
|
|
private $onlyDocs = false; |
|
20
|
|
|
|
|
21
|
|
|
private $documentName; |
|
22
|
|
|
|
|
23
|
|
|
public function getDocumentName() |
|
24
|
|
|
{ |
|
25
|
|
|
return $this->documentName; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function setDocumentName($documentName) |
|
29
|
|
|
{ |
|
30
|
|
|
$this->documentName = $documentName; |
|
31
|
|
|
return $this; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function execute() |
|
35
|
|
|
{ |
|
36
|
|
|
$response = $this->doExecute(); |
|
37
|
|
|
if ($this->dm && $this->getParameter('include_docs') === true) { |
|
38
|
|
|
$uow = $this->dm->getUnitOfWork(); |
|
|
|
|
|
|
39
|
|
|
foreach ($response->body['rows'] AS $k => $v) { |
|
40
|
|
|
if (!isset($v['type']) && !$this->documentName) { |
|
41
|
|
|
throw new \InvalidArgumentException( |
|
42
|
|
|
"Cannot query " . $this->getHttpQuery() . " lucene and convert to document instances, ". |
|
43
|
|
|
"the type of document " . $v['id'] . " is not stored in Lucene. You can query without " . |
|
44
|
|
|
"include_docs and pass the ids to findMany() of the repository you know this document is " . |
|
45
|
|
|
"a type of."); |
|
46
|
|
|
} |
|
47
|
|
|
$v['type'] = isset($v['type']) ? $v['type'] : $this->documentName; |
|
48
|
|
|
|
|
49
|
|
|
$doc = $this->dm->find(str_replace(".", "\\", $v['type']), $v['id']); |
|
50
|
|
View Code Duplication |
if ($this->onlyDocs) { |
|
|
|
|
|
|
51
|
|
|
$response->body['rows'][$k] = $doc; |
|
52
|
|
|
} else { |
|
53
|
|
|
$response->body['rows'][$k]['doc'] = $doc; |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
return $this->createResult($response); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @param DocumentManager $dm |
|
64
|
|
|
*/ |
|
65
|
|
|
public function setDocumentManager(DocumentManager $dm) |
|
66
|
|
|
{ |
|
67
|
|
|
$this->dm = $dm; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @param bool $flag |
|
72
|
|
|
* @return LuceneQuery |
|
73
|
|
|
*/ |
|
74
|
|
|
public function onlyDocs($flag) |
|
75
|
|
|
{ |
|
76
|
|
|
$this->setIncludeDocs(true); |
|
77
|
|
|
$this->onlyDocs = $flag; |
|
78
|
|
|
return $this; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.