Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
679da533
Commit
679da533
authored
Nov 23, 2013
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
polished Query API
parent
c6347d6d
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
9 additions
and
39 deletions
+9
-39
Query.php
framework/yii/db/Query.php
+1
-1
ActiveQuery.php
framework/yii/elasticsearch/ActiveQuery.php
+5
-28
ActiveRecord.php
framework/yii/elasticsearch/ActiveRecord.php
+0
-1
Command.php
framework/yii/elasticsearch/Command.php
+0
-6
Query.php
framework/yii/elasticsearch/Query.php
+0
-0
QueryBuilder.php
framework/yii/elasticsearch/QueryBuilder.php
+3
-3
No files found.
framework/yii/db/Query.php
View file @
679da533
...
@@ -42,7 +42,7 @@ class Query extends Component implements QueryInterface
...
@@ -42,7 +42,7 @@ class Query extends Component implements QueryInterface
/**
/**
* @var array the columns being selected. For example, `['id', 'name']`.
* @var array the columns being selected. For example, `['id', 'name']`.
* This is used to construct the SELECT clause in a SQL statement. If not set, i
f
means selecting all columns.
* This is used to construct the SELECT clause in a SQL statement. If not set, i
t
means selecting all columns.
* @see select()
* @see select()
*/
*/
public
$select
;
public
$select
;
...
...
framework/yii/elasticsearch/ActiveQuery.php
View file @
679da533
...
@@ -85,7 +85,7 @@ class ActiveQuery extends Query implements ActiveQueryInterface
...
@@ -85,7 +85,7 @@ class ActiveQuery extends Query implements ActiveQueryInterface
{
{
$command
=
$this
->
createCommand
(
$db
);
$command
=
$this
->
createCommand
(
$db
);
$result
=
$command
->
queryAll
();
$result
=
$command
->
queryAll
();
if
(
$result
[
'total'
]
==
0
)
{
if
(
empty
(
$result
[
'hits'
])
)
{
return
[];
return
[];
}
}
$models
=
$this
->
createModels
(
$result
[
'hits'
]);
$models
=
$this
->
createModels
(
$result
[
'hits'
]);
...
@@ -111,19 +111,16 @@ class ActiveQuery extends Query implements ActiveQueryInterface
...
@@ -111,19 +111,16 @@ class ActiveQuery extends Query implements ActiveQueryInterface
*/
*/
public
function
one
(
$db
=
null
)
public
function
one
(
$db
=
null
)
{
{
$command
=
$this
->
createCommand
(
$db
);
if
((
$result
=
parent
::
one
(
$db
))
===
false
)
{
$result
=
$command
->
queryOne
();
if
(
$result
[
'total'
]
==
0
||
empty
(
$result
[
'hits'
]))
{
return
null
;
return
null
;
}
}
if
(
$this
->
asArray
)
{
if
(
$this
->
asArray
)
{
$first
=
reset
(
$result
[
'hits'
]);
$model
=
$result
[
'_source'
];
$model
=
$first
[
'_source'
];
$model
[
'primaryKey'
]
=
$result
[
'_id'
];
$model
[
'primaryKey'
]
=
$first
[
'_id'
];
}
else
{
}
else
{
/** @var ActiveRecord $class */
/** @var ActiveRecord $class */
$class
=
$this
->
modelClass
;
$class
=
$this
->
modelClass
;
$model
=
$class
::
create
(
reset
(
$result
[
'hits'
])
);
$model
=
$class
::
create
(
$result
);
}
}
if
(
!
empty
(
$this
->
with
))
{
if
(
!
empty
(
$this
->
with
))
{
$models
=
[
$model
];
$models
=
[
$model
];
...
@@ -132,24 +129,4 @@ class ActiveQuery extends Query implements ActiveQueryInterface
...
@@ -132,24 +129,4 @@ class ActiveQuery extends Query implements ActiveQueryInterface
}
}
return
$model
;
return
$model
;
}
}
/**
* Returns the query result as a scalar value.
* The value returned will be the specified attribute in the first record of the query results.
* @param string $attribute name of the attribute to select
* @param Connection $db the database connection used to execute the query.
* If this parameter is not given, the `db` application component will be used.
* @return string the value of the specified attribute in the first record of the query result.
* Null is returned if the query result is empty.
*/
public
function
scalar
(
$attribute
,
$db
=
null
)
{
$record
=
$this
->
one
(
$db
);
if
(
$record
!==
null
)
{
return
$record
->
$attribute
;
}
else
{
return
null
;
}
}
}
}
framework/yii/elasticsearch/ActiveRecord.php
View file @
679da533
...
@@ -64,7 +64,6 @@ class ActiveRecord extends \yii\db\ActiveRecord
...
@@ -64,7 +64,6 @@ class ActiveRecord extends \yii\db\ActiveRecord
* @param mixed $primaryKey the primaryKey value
* @param mixed $primaryKey the primaryKey value
* @param array $options options given in this parameter are passed to elasticsearch
* @param array $options options given in this parameter are passed to elasticsearch
* as request URI parameters.
* as request URI parameters.
*
* Please refer to the [elasticsearch documentation](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-get.html)
* Please refer to the [elasticsearch documentation](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-get.html)
* for more details on these options.
* for more details on these options.
* @return static|null The record instance or null if it was not found.
* @return static|null The record instance or null if it was not found.
...
...
framework/yii/elasticsearch/Command.php
View file @
679da533
...
@@ -59,12 +59,6 @@ class Command extends Component
...
@@ -59,12 +59,6 @@ class Command extends Component
return
Json
::
decode
(
$response
->
getBody
(
true
))[
'hits'
];
return
Json
::
decode
(
$response
->
getBody
(
true
))[
'hits'
];
}
}
public
function
queryOne
(
$options
=
[])
{
$options
[
'size'
]
=
1
;
return
$this
->
queryAll
(
$options
);
}
public
function
queryCount
(
$options
=
[])
public
function
queryCount
(
$options
=
[])
{
{
$options
[
'search_type'
]
=
'count'
;
$options
[
'search_type'
]
=
'count'
;
...
...
framework/yii/elasticsearch/Query.php
View file @
679da533
This diff is collapsed.
Click to expand it.
framework/yii/elasticsearch/QueryBuilder.php
View file @
679da533
...
@@ -45,7 +45,7 @@ class QueryBuilder extends \yii\base\Object
...
@@ -45,7 +45,7 @@ class QueryBuilder extends \yii\base\Object
public
function
build
(
$query
)
public
function
build
(
$query
)
{
{
$searchQuery
=
array
();
$searchQuery
=
array
();
$this
->
build
Select
(
$searchQuery
,
$query
->
select
);
$this
->
build
Fields
(
$searchQuery
,
$query
->
fields
);
// $this->buildFrom($searchQuery, $query->from);
// $this->buildFrom($searchQuery, $query->from);
$this
->
buildCondition
(
$searchQuery
,
$query
->
where
);
$this
->
buildCondition
(
$searchQuery
,
$query
->
where
);
$this
->
buildOrderBy
(
$searchQuery
,
$query
->
orderBy
);
$this
->
buildOrderBy
(
$searchQuery
,
$query
->
orderBy
);
...
@@ -113,9 +113,9 @@ class QueryBuilder extends \yii\base\Object
...
@@ -113,9 +113,9 @@ class QueryBuilder extends \yii\base\Object
* @param string $selectOption
* @param string $selectOption
* @return string the SELECT clause built from [[query]].
* @return string the SELECT clause built from [[query]].
*/
*/
public
function
build
Select
(
&
$query
,
$columns
)
public
function
build
Fields
(
&
$query
,
$columns
)
{
{
if
(
empty
(
$columns
)
)
{
if
(
$columns
===
null
)
{
return
;
return
;
}
}
foreach
(
$columns
as
$i
=>
$column
)
{
foreach
(
$columns
as
$i
=>
$column
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment