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
cc156ba8
Commit
cc156ba8
authored
Nov 13, 2013
by
Paul Klimov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Methods "callSnippet" and "callKeywords" added to "yii\sphinx\Command"
parent
07ad008d
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
79 additions
and
0 deletions
+79
-0
Command.php
extensions/sphinx/Command.php
+15
-0
Connection.php
extensions/sphinx/Connection.php
+3
-0
QueryBuilder.php
extensions/sphinx/QueryBuilder.php
+32
-0
CommandTest.php
tests/unit/extensions/sphinx/CommandTest.php
+29
-0
No files found.
extensions/sphinx/Command.php
View file @
cc156ba8
...
...
@@ -495,4 +495,18 @@ class Command extends Component
$sql
=
$this
->
db
->
getQueryBuilder
()
->
truncateIndex
(
$index
);
return
$this
->
setSql
(
$sql
);
}
public
function
callSnippets
(
$index
,
$source
,
$query
,
array
$options
=
[])
{
$params
=
[];
$sql
=
$this
->
db
->
getQueryBuilder
()
->
callSnippets
(
$index
,
$source
,
$query
,
$options
,
$params
);
return
$this
->
setSql
(
$sql
)
->
bindValues
(
$params
);
}
public
function
callKeywords
(
$index
,
$text
,
$fetchStatistic
=
false
)
{
$params
=
[];
$sql
=
$this
->
db
->
getQueryBuilder
()
->
callKeywords
(
$index
,
$text
,
$fetchStatistic
,
$params
);
return
$this
->
setSql
(
$sql
)
->
bindValues
(
$params
);
}
}
\ No newline at end of file
extensions/sphinx/Connection.php
View file @
cc156ba8
...
...
@@ -11,7 +11,10 @@ namespace yii\sphinx;
* Class Connection
*
* @property Schema $schema The schema information for this Sphinx connection. This property is read-only.
* @property QueryBuilder $queryBuilder The query builder for this Sphinx connection. This property is
* read-only.
* @method Schema getSchema() The schema information for this Sphinx connection
* @method QueryBuilder getQueryBuilder() he query builder for this Sphinx connection
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
...
...
extensions/sphinx/QueryBuilder.php
View file @
cc156ba8
...
...
@@ -278,6 +278,38 @@ class QueryBuilder extends Object
return
'TRUNCATE RTINDEX '
.
$this
->
db
->
quoteIndexName
(
$index
);
}
public
function
callSnippets
(
$index
,
$source
,
$query
,
$options
,
&
$params
)
{
if
(
is_array
(
$source
))
{
$dataSqlParts
=
[];
foreach
(
$source
as
$sourceRow
)
{
$phName
=
self
::
PARAM_PREFIX
.
count
(
$params
);
$params
[
$phName
]
=
$sourceRow
;
$dataSqlParts
[]
=
$phName
;
}
$dataSql
=
'('
.
implode
(
','
,
$dataSqlParts
)
.
')'
;
}
else
{
$phName
=
self
::
PARAM_PREFIX
.
count
(
$params
);
$params
[
$phName
]
=
$source
;
$dataSql
=
$phName
;
}
$indexParamName
=
self
::
PARAM_PREFIX
.
count
(
$params
);
$params
[
$indexParamName
]
=
$index
;
$queryParamName
=
self
::
PARAM_PREFIX
.
count
(
$params
);
$params
[
$queryParamName
]
=
$query
;
$optionSql
=
''
;
// @todo
return
'CALL SNIPPETS('
.
$dataSql
.
', '
.
$indexParamName
.
', '
.
$queryParamName
.
$optionSql
.
')'
;
}
public
function
callKeywords
(
$index
,
$text
,
$fetchStatistic
,
&
$params
)
{
$indexParamName
=
self
::
PARAM_PREFIX
.
count
(
$params
);
$params
[
$indexParamName
]
=
$index
;
$textParamName
=
self
::
PARAM_PREFIX
.
count
(
$params
);
$params
[
$textParamName
]
=
$text
;
return
'CALL KEYWORDS('
.
$textParamName
.
', '
.
$indexParamName
.
(
$fetchStatistic
?
', 1'
:
''
)
.
')'
;
}
/**
* @param array $columns
* @param boolean $distinct
...
...
tests/unit/extensions/sphinx/CommandTest.php
View file @
cc156ba8
...
...
@@ -252,4 +252,32 @@ class CommandTest extends SphinxTestCase
$rows
=
$db
->
createCommand
(
'SELECT * FROM yii2_test_rt_index'
)
->
queryAll
();
$this
->
assertEquals
(
0
,
count
(
$rows
),
'Unable to delete record!'
);
}
public
function
testCallSnippets
()
{
$db
=
$this
->
getConnection
();
$query
=
'pencil'
;
$data
=
[
'Some data sentence about '
.
$query
];
$rows
=
$db
->
createCommand
()
->
callSnippets
(
'yii2_test_item_index'
,
$data
,
$query
)
->
queryColumn
();
$this
->
assertNotEmpty
(
$rows
,
'Unable to call snippets!'
);
$this
->
assertContains
(
'<b>'
.
$query
.
'</b>'
,
$rows
[
0
],
'Query not present in the snippet!'
);
}
public
function
testCallKeywords
()
{
$db
=
$this
->
getConnection
();
$text
=
'table pencil'
;
$rows
=
$db
->
createCommand
()
->
callKeywords
(
'yii2_test_item_index'
,
$text
)
->
queryAll
();
$this
->
assertNotEmpty
(
$rows
,
'Unable to call keywords!'
);
$this
->
assertArrayHasKey
(
'tokenized'
,
$rows
[
0
],
'No tokenized keyword!'
);
$this
->
assertArrayHasKey
(
'normalized'
,
$rows
[
0
],
'No normalized keyword!'
);
$text
=
'table pencil'
;
$rows
=
$db
->
createCommand
()
->
callKeywords
(
'yii2_test_item_index'
,
$text
,
true
)
->
queryAll
();
$this
->
assertNotEmpty
(
$rows
,
'Unable to call keywords with statistic!'
);
$this
->
assertArrayHasKey
(
'docs'
,
$rows
[
0
],
'No docs!'
);
$this
->
assertArrayHasKey
(
'hits'
,
$rows
[
0
],
'No hits!'
);
}
}
\ No newline at end of file
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