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
8cd24773
Commit
8cd24773
authored
Mar 29, 2014
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Query::filter() adjustments
parent
a884c80f
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
55 additions
and
13 deletions
+55
-13
Query.php
extensions/elasticsearch/Query.php
+3
-3
QueryBuilder.php
extensions/elasticsearch/QueryBuilder.php
+6
-6
Query.php
extensions/sphinx/Query.php
+11
-1
Query.php
framework/db/Query.php
+11
-1
QueryTrait.php
framework/db/QueryTrait.php
+2
-2
QueryTest.php
tests/unit/extensions/sphinx/QueryTest.php
+11
-0
QueryTest.php
tests/unit/framework/db/QueryTest.php
+11
-0
No files found.
extensions/elasticsearch/Query.php
View file @
8cd24773
...
...
@@ -92,7 +92,7 @@ class Query extends Component implements QueryInterface
* @var array|string The filter part of this search query. This is an array or json string that follows the format of
* the elasticsearch [Query DSL](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl.html).
*/
public
$filter
;
public
$filter
Part
;
public
$facets
=
[];
...
...
@@ -459,9 +459,9 @@ class Query extends Component implements QueryInterface
* @param string $filter
* @return static the query object itself
*/
public
function
applyFilter
(
$filter
)
public
function
filterPart
(
$filter
)
{
$this
->
filter
=
$filter
;
$this
->
filter
Part
=
$filter
;
return
$this
;
}
...
...
extensions/elasticsearch/QueryBuilder.php
View file @
8cd24773
...
...
@@ -62,17 +62,17 @@ class QueryBuilder extends \yii\base\Object
}
$whereFilter
=
$this
->
buildCondition
(
$query
->
where
);
if
(
is_string
(
$query
->
filter
))
{
if
(
is_string
(
$query
->
filter
Part
))
{
if
(
empty
(
$whereFilter
))
{
$parts
[
'filter'
]
=
$query
->
filter
;
$parts
[
'filter'
]
=
$query
->
filter
Part
;
}
else
{
$parts
[
'filter'
]
=
'{"and": ['
.
$query
->
filter
.
', '
.
Json
::
encode
(
$whereFilter
)
.
']}'
;
$parts
[
'filter'
]
=
'{"and": ['
.
$query
->
filter
Part
.
', '
.
Json
::
encode
(
$whereFilter
)
.
']}'
;
}
}
elseif
(
$query
->
filter
!==
null
)
{
}
elseif
(
$query
->
filter
Part
!==
null
)
{
if
(
empty
(
$whereFilter
))
{
$parts
[
'filter'
]
=
$query
->
filter
;
$parts
[
'filter'
]
=
$query
->
filter
Part
;
}
else
{
$parts
[
'filter'
]
=
[
'and'
=>
[
$query
->
filter
,
$whereFilter
]];
$parts
[
'filter'
]
=
[
'and'
=>
[
$query
->
filter
Part
,
$whereFilter
]];
}
}
elseif
(
!
empty
(
$whereFilter
))
{
$parts
[
'filter'
]
=
$whereFilter
;
...
...
extensions/sphinx/Query.php
View file @
8cd24773
...
...
@@ -819,6 +819,16 @@ class Query extends Component implements QueryInterface
$operator
=
strtoupper
(
$condition
[
0
]);
switch
(
$operator
)
{
case
'NOT'
:
case
'AND'
:
case
'OR'
:
$subCondition
=
$this
->
filterCondition
(
$condition
[
1
]);
if
(
$this
->
parameterNotEmpty
(
$subCondition
))
{
$condition
[
1
]
=
$subCondition
;
}
else
{
$condition
=
[];
}
break
;
case
'IN'
:
case
'NOT IN'
:
case
'LIKE'
:
...
...
@@ -837,7 +847,7 @@ class Query extends Component implements QueryInterface
break
;
}
}
else
{
$condition
=
$this
->
filter
ConditionHash
(
$condition
);
$condition
=
$this
->
filter
HashCondition
(
$condition
);
}
return
$condition
;
}
...
...
framework/db/Query.php
View file @
8cd24773
...
...
@@ -906,6 +906,16 @@ class Query extends Component implements QueryInterface
$operator
=
strtoupper
(
$condition
[
0
]);
switch
(
$operator
)
{
case
'NOT'
:
case
'AND'
:
case
'OR'
:
$subCondition
=
$this
->
filterCondition
(
$condition
[
1
]);
if
(
$this
->
parameterNotEmpty
(
$subCondition
))
{
$condition
[
1
]
=
$subCondition
;
}
else
{
$condition
=
[];
}
break
;
case
'IN'
:
case
'NOT IN'
:
case
'LIKE'
:
...
...
@@ -924,7 +934,7 @@ class Query extends Component implements QueryInterface
break
;
}
}
else
{
$condition
=
$this
->
filter
ConditionHash
(
$condition
);
$condition
=
$this
->
filter
HashCondition
(
$condition
);
}
return
$condition
;
}
...
...
framework/db/QueryTrait.php
View file @
8cd24773
...
...
@@ -109,7 +109,7 @@ trait QueryTrait
* @param array $condition original condition
* @return array condition with empty parameters removed
*/
protected
function
filter
ConditionHash
(
$condition
)
protected
function
filter
HashCondition
(
$condition
)
{
if
(
is_array
(
$condition
)
&&
!
isset
(
$condition
[
0
]))
{
// hash format: 'column1' => 'value1', 'column2' => 'value2', ...
...
...
@@ -126,7 +126,7 @@ trait QueryTrait
*/
protected
function
filterCondition
(
$condition
)
{
return
$this
->
filter
ConditionHash
(
$condition
);
return
$this
->
filter
HashCondition
(
$condition
);
}
/**
...
...
tests/unit/extensions/sphinx/QueryTest.php
View file @
8cd24773
...
...
@@ -117,6 +117,17 @@ class QueryTest extends SphinxTestCase
$this
->
assertEquals
(
$condition
,
$query
->
where
);
}
public
function
testFilterRecursively
()
{
$query
=
new
Query
();
$query
->
filter
([
'not'
,
[
'like'
,
'name'
,
''
]]);
$this
->
assertEquals
(
null
,
$query
->
where
);
$query
->
where
([
'id'
=>
1
]);
$query
->
filter
([
'and'
,
[
'like'
,
'name'
,
''
]]);
$this
->
assertEquals
([
'id'
=>
1
],
$query
->
where
);
}
public
function
testGroup
()
{
$query
=
new
Query
;
...
...
tests/unit/framework/db/QueryTest.php
View file @
8cd24773
...
...
@@ -106,6 +106,17 @@ class QueryTest extends DatabaseTestCase
$this
->
assertEquals
(
$condition
,
$query
->
where
);
}
public
function
testFilterRecursively
()
{
$query
=
new
Query
();
$query
->
filter
([
'not'
,
[
'like'
,
'name'
,
''
]]);
$this
->
assertEquals
(
null
,
$query
->
where
);
$query
->
where
([
'id'
=>
1
]);
$query
->
filter
([
'and'
,
[
'like'
,
'name'
,
''
]]);
$this
->
assertEquals
([
'id'
=>
1
],
$query
->
where
);
}
public
function
testJoin
()
{
}
...
...
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