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
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Rotua Panjaitan
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
Hide 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
/**
* @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()
*/
public
$select
;
...
...
framework/yii/elasticsearch/ActiveQuery.php
View file @
679da533
...
...
@@ -85,7 +85,7 @@ class ActiveQuery extends Query implements ActiveQueryInterface
{
$command
=
$this
->
createCommand
(
$db
);
$result
=
$command
->
queryAll
();
if
(
$result
[
'total'
]
==
0
)
{
if
(
empty
(
$result
[
'hits'
])
)
{
return
[];
}
$models
=
$this
->
createModels
(
$result
[
'hits'
]);
...
...
@@ -111,19 +111,16 @@ class ActiveQuery extends Query implements ActiveQueryInterface
*/
public
function
one
(
$db
=
null
)
{
$command
=
$this
->
createCommand
(
$db
);
$result
=
$command
->
queryOne
();
if
(
$result
[
'total'
]
==
0
||
empty
(
$result
[
'hits'
]))
{
if
((
$result
=
parent
::
one
(
$db
))
===
false
)
{
return
null
;
}
if
(
$this
->
asArray
)
{
$first
=
reset
(
$result
[
'hits'
]);
$model
=
$first
[
'_source'
];
$model
[
'primaryKey'
]
=
$first
[
'_id'
];
$model
=
$result
[
'_source'
];
$model
[
'primaryKey'
]
=
$result
[
'_id'
];
}
else
{
/** @var ActiveRecord $class */
$class
=
$this
->
modelClass
;
$model
=
$class
::
create
(
reset
(
$result
[
'hits'
])
);
$model
=
$class
::
create
(
$result
);
}
if
(
!
empty
(
$this
->
with
))
{
$models
=
[
$model
];
...
...
@@ -132,24 +129,4 @@ class ActiveQuery extends Query implements ActiveQueryInterface
}
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
* @param mixed $primaryKey the primaryKey value
* @param array $options options given in this parameter are passed to elasticsearch
* as request URI parameters.
*
* Please refer to the [elasticsearch documentation](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-get.html)
* for more details on these options.
* @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
return
Json
::
decode
(
$response
->
getBody
(
true
))[
'hits'
];
}
public
function
queryOne
(
$options
=
[])
{
$options
[
'size'
]
=
1
;
return
$this
->
queryAll
(
$options
);
}
public
function
queryCount
(
$options
=
[])
{
$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
public
function
build
(
$query
)
{
$searchQuery
=
array
();
$this
->
build
Select
(
$searchQuery
,
$query
->
select
);
$this
->
build
Fields
(
$searchQuery
,
$query
->
fields
);
// $this->buildFrom($searchQuery, $query->from);
$this
->
buildCondition
(
$searchQuery
,
$query
->
where
);
$this
->
buildOrderBy
(
$searchQuery
,
$query
->
orderBy
);
...
...
@@ -113,9 +113,9 @@ class QueryBuilder extends \yii\base\Object
* @param string $selectOption
* @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
;
}
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