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
5b0d6f88
Commit
5b0d6f88
authored
Aug 27, 2014
by
Klimov Paul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
`yii\sphinx\ActiveQuery` fixed to be resuable with 'match' condition.
parent
10edf5c9
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
13 deletions
+27
-13
CHANGELOG.md
extensions/sphinx/CHANGELOG.md
+1
-0
QueryBuilder.php
extensions/sphinx/QueryBuilder.php
+20
-13
ActiveRecordTest.php
tests/unit/extensions/sphinx/ActiveRecordTest.php
+6
-0
No files found.
extensions/sphinx/CHANGELOG.md
View file @
5b0d6f88
...
@@ -7,6 +7,7 @@ Yii Framework 2 sphinx extension Change Log
...
@@ -7,6 +7,7 @@ Yii Framework 2 sphinx extension Change Log
-
Bug #3668: Escaping of the special characters at 'MATCH' statement added (klimov-paul)
-
Bug #3668: Escaping of the special characters at 'MATCH' statement added (klimov-paul)
-
Bug #4018: AR relation eager loading does not work with db models (klimov-paul)
-
Bug #4018: AR relation eager loading does not work with db models (klimov-paul)
-
Bug #4375: Distributed indexes support provided (klimov-paul)
-
Bug #4375: Distributed indexes support provided (klimov-paul)
-
Bug #4830:
`ActiveQuery`
instance reusage ability granted (klimov-paul)
-
Enh #3520: Added
`unlinkAll()`
-method to active record to remove all records of a model relation (NmDimas, samdark, cebe)
-
Enh #3520: Added
`unlinkAll()`
-method to active record to remove all records of a model relation (NmDimas, samdark, cebe)
-
Enh #4048: Added
`init`
event to
`ActiveQuery`
classes (qiangxue)
-
Enh #4048: Added
`init`
event to
`ActiveQuery`
classes (qiangxue)
-
Enh #4086: changedAttributes of afterSave Event now contain old values (dizews)
-
Enh #4086: changedAttributes of afterSave Event now contain old values (dizews)
...
...
extensions/sphinx/QueryBuilder.php
View file @
5b0d6f88
...
@@ -63,17 +63,6 @@ class QueryBuilder extends Object
...
@@ -63,17 +63,6 @@ class QueryBuilder extends Object
{
{
$params
=
empty
(
$params
)
?
$query
->
params
:
array_merge
(
$params
,
$query
->
params
);
$params
=
empty
(
$params
)
?
$query
->
params
:
array_merge
(
$params
,
$query
->
params
);
if
(
$query
->
match
!==
null
)
{
if
(
$query
->
match
instanceof
Expression
)
{
$query
->
andWhere
(
'MATCH('
.
$query
->
match
->
expression
.
')'
);
$params
=
array_merge
(
$params
,
$query
->
match
->
params
);
}
else
{
$phName
=
self
::
PARAM_PREFIX
.
count
(
$params
);
$params
[
$phName
]
=
$this
->
db
->
escapeMatchValue
(
$query
->
match
);
$query
->
andWhere
(
'MATCH('
.
$phName
.
')'
);
}
}
$from
=
$query
->
from
;
$from
=
$query
->
from
;
if
(
$from
===
null
&&
$query
instanceof
ActiveQuery
)
{
if
(
$from
===
null
&&
$query
instanceof
ActiveQuery
)
{
/* @var $modelClass ActiveRecord */
/* @var $modelClass ActiveRecord */
...
@@ -84,7 +73,7 @@ class QueryBuilder extends Object
...
@@ -84,7 +73,7 @@ class QueryBuilder extends Object
$clauses
=
[
$clauses
=
[
$this
->
buildSelect
(
$query
->
select
,
$params
,
$query
->
distinct
,
$query
->
selectOption
),
$this
->
buildSelect
(
$query
->
select
,
$params
,
$query
->
distinct
,
$query
->
selectOption
),
$this
->
buildFrom
(
$from
,
$params
),
$this
->
buildFrom
(
$from
,
$params
),
$this
->
buildWhere
(
$query
->
from
,
$query
->
where
,
$params
),
$this
->
buildWhere
(
$query
->
from
,
$query
->
where
,
$params
,
$query
->
match
),
$this
->
buildGroupBy
(
$query
->
groupBy
),
$this
->
buildGroupBy
(
$query
->
groupBy
),
$this
->
buildWithin
(
$query
->
within
),
$this
->
buildWithin
(
$query
->
within
),
$this
->
buildOrderBy
(
$query
->
orderBy
),
$this
->
buildOrderBy
(
$query
->
orderBy
),
...
@@ -487,10 +476,28 @@ class QueryBuilder extends Object
...
@@ -487,10 +476,28 @@ class QueryBuilder extends Object
* @param string[] $indexes list of index names, which affected by query
* @param string[] $indexes list of index names, which affected by query
* @param string|array $condition
* @param string|array $condition
* @param array $params the binding parameters to be populated
* @param array $params the binding parameters to be populated
* @param string|Expression|null $match
* @return string the WHERE clause built from [[query]].
* @return string the WHERE clause built from [[query]].
*/
*/
public
function
buildWhere
(
$indexes
,
$condition
,
&
$params
)
public
function
buildWhere
(
$indexes
,
$condition
,
&
$params
,
$match
=
null
)
{
{
if
(
$match
!==
null
)
{
if
(
$match
instanceof
Expression
)
{
$matchWhere
=
'MATCH('
.
$match
->
expression
.
')'
;
$params
=
array_merge
(
$params
,
$match
->
params
);
}
else
{
$phName
=
self
::
PARAM_PREFIX
.
count
(
$params
);
$params
[
$phName
]
=
$this
->
db
->
escapeMatchValue
(
$match
);
$matchWhere
=
'MATCH('
.
$phName
.
')'
;
}
if
(
$condition
===
null
)
{
$condition
=
$matchWhere
;
}
else
{
$condition
=
[
'and'
,
$matchWhere
,
$condition
];
}
}
if
(
empty
(
$condition
))
{
if
(
empty
(
$condition
))
{
return
''
;
return
''
;
}
}
...
...
tests/unit/extensions/sphinx/ActiveRecordTest.php
View file @
5b0d6f88
...
@@ -236,6 +236,8 @@ class ActiveRecordTest extends SphinxTestCase
...
@@ -236,6 +236,8 @@ class ActiveRecordTest extends SphinxTestCase
}
}
/**
/**
* @see https://github.com/yiisoft/yii2/issues/4830
*
* @depends testFind
* @depends testFind
*/
*/
public
function
testFindQueryReuse
()
public
function
testFindQueryReuse
()
...
@@ -243,5 +245,9 @@ class ActiveRecordTest extends SphinxTestCase
...
@@ -243,5 +245,9 @@ class ActiveRecordTest extends SphinxTestCase
$result
=
ArticleIndex
::
find
()
->
andWhere
([
'author_id'
=>
1
]);
$result
=
ArticleIndex
::
find
()
->
andWhere
([
'author_id'
=>
1
]);
$this
->
assertTrue
(
$result
->
one
()
instanceof
ArticleIndex
);
$this
->
assertTrue
(
$result
->
one
()
instanceof
ArticleIndex
);
$this
->
assertTrue
(
$result
->
one
()
instanceof
ArticleIndex
);
$this
->
assertTrue
(
$result
->
one
()
instanceof
ArticleIndex
);
$result
=
ArticleIndex
::
find
()
->
match
(
'dogs'
);
$this
->
assertTrue
(
$result
->
one
()
instanceof
ArticleIndex
);
$this
->
assertTrue
(
$result
->
one
()
instanceof
ArticleIndex
);
}
}
}
}
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