Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
solarium
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
solarium
Commits
281d770a
Commit
281d770a
authored
May 18, 2011
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- added getStatus and getQueryTime to Solarium_Result_Select
- improved unittests
parent
cc34a078
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
215 additions
and
4 deletions
+215
-4
library/Solarium/Client/Adapter/Http.php
library/Solarium/Client/Adapter/Http.php
+3
-0
library/Solarium/Client/ResponseParser/Update.php
library/Solarium/Client/ResponseParser/Update.php
+1
-1
library/Solarium/Result/Select.php
library/Solarium/Result/Select.php
+46
-0
tests/Solarium/Client/ResponseParser/Select/Component/HighlightingTest.php
...ient/ResponseParser/Select/Component/HighlightingTest.php
+63
-0
tests/Solarium/Client/ResponseParser/Select/Component/MoreLikeThisTest.php
...ient/ResponseParser/Select/Component/MoreLikeThisTest.php
+74
-0
tests/Solarium/Client/ResponseParser/UpdateTest.php
tests/Solarium/Client/ResponseParser/UpdateTest.php
+8
-0
tests/Solarium/Result/SelectTest.php
tests/Solarium/Result/SelectTest.php
+20
-3
No files found.
library/Solarium/Client/Adapter/Http.php
View file @
281d770a
...
@@ -133,11 +133,14 @@ class Solarium_Client_Adapter_Http extends Solarium_Client_Adapter
...
@@ -133,11 +133,14 @@ class Solarium_Client_Adapter_Http extends Solarium_Client_Adapter
protected
function
_getData
(
$uri
,
$context
)
protected
function
_getData
(
$uri
,
$context
)
{
{
$data
=
@
file_get_contents
(
$uri
,
false
,
$context
);
$data
=
@
file_get_contents
(
$uri
,
false
,
$context
);
// @codeCoverageIgnoreStart
if
(
isset
(
$http_response_header
))
{
if
(
isset
(
$http_response_header
))
{
$headers
=
$http_response_header
;
$headers
=
$http_response_header
;
}
else
{
}
else
{
$headers
=
array
();
$headers
=
array
();
}
}
// @codeCoverageIgnoreEnd
return
array
(
$data
,
$headers
);
return
array
(
$data
,
$headers
);
}
}
...
...
library/Solarium/Client/ResponseParser/Update.php
View file @
281d770a
...
@@ -47,7 +47,7 @@ class Solarium_Client_ResponseParser_Update extends Solarium_Client_ResponsePars
...
@@ -47,7 +47,7 @@ class Solarium_Client_ResponseParser_Update extends Solarium_Client_ResponsePars
/**
/**
* Parse response data
* Parse response data
*
*
* @param Solarium_Result_
Select
$result
* @param Solarium_Result_
Update
$result
* @return array
* @return array
*/
*/
public
function
parse
(
$result
)
public
function
parse
(
$result
)
...
...
library/Solarium/Result/Select.php
View file @
281d770a
...
@@ -83,6 +83,52 @@ class Solarium_Result_Select extends Solarium_Result_QueryType
...
@@ -83,6 +83,52 @@ class Solarium_Result_Select extends Solarium_Result_QueryType
*/
*/
protected
$_components
;
protected
$_components
;
/**
* Status code returned by Solr
*
* @var int
*/
protected
$_status
;
/**
* Solr index queryTime
*
* This doesn't include things like the HTTP responsetime. Purely the Solr
* query execution time.
*
* @var int
*/
protected
$_queryTime
;
/**
* Get Solr status code
*
* This is not the HTTP status code! The normal value for success is 0.
*
* @return int
*/
public
function
getStatus
()
{
$this
->
_parseResponse
();
return
$this
->
_status
;
}
/**
* Get Solr query time
*
* This doesn't include things like the HTTP responsetime. Purely the Solr
* query execution time.
*
* @return int
*/
public
function
getQueryTime
()
{
$this
->
_parseResponse
();
return
$this
->
_queryTime
;
}
/**
/**
* get Solr numFound
* get Solr numFound
*
*
...
...
tests/Solarium/Client/ResponseParser/Select/Component/HighlightingTest.php
0 → 100644
View file @
281d770a
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
class
Solarium_Client_ResponseParser_Select_Component_HighlightingTest
extends
PHPUnit_Framework_TestCase
{
protected
$_parser
;
public
function
setUp
()
{
$this
->
_parser
=
new
Solarium_Client_ResponseParser_Select_Component_Highlighting
;
}
public
function
testParse
()
{
$highlights
=
array
(
'key1'
=>
'dummy1'
,
'key2'
=>
'dummy2'
);
$data
=
array
(
'highlighting'
=>
$highlights
);
$expected
=
array
(
'key1'
=>
new
Solarium_Result_Select_Highlighting_Result
(
'dummy1'
),
'key2'
=>
new
Solarium_Result_Select_Highlighting_Result
(
'dummy2'
),
);
$result
=
$this
->
_parser
->
parse
(
null
,
null
,
$data
);
$this
->
assertEquals
(
$expected
,
$result
->
getResults
());
}
public
function
testParseNoData
()
{
$result
=
$this
->
_parser
->
parse
(
null
,
null
,
array
());
$this
->
assertEquals
(
array
(),
$result
->
getResults
());
}
}
tests/Solarium/Client/ResponseParser/Select/Component/MoreLikeThisTest.php
0 → 100644
View file @
281d770a
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
class
Solarium_Client_ResponseParser_Select_Component_MoreLikeThisTest
extends
PHPUnit_Framework_TestCase
{
protected
$_parser
;
public
function
setUp
()
{
$this
->
_parser
=
new
Solarium_Client_ResponseParser_Select_Component_MoreLikeThis
();
}
public
function
testParse
()
{
$query
=
new
Solarium_Query_Select
();
$data
=
array
(
'moreLikeThis'
=>
array
(
'id1'
=>
array
(
'numFound'
=>
12
,
'maxScore'
=>
1.75
,
'docs'
=>
array
(
array
(
'field1'
=>
'value1'
)
)
)
)
);
$docs
=
array
(
new
Solarium_Document_ReadOnly
(
array
(
'field1'
=>
'value1'
)));
$expected
=
array
(
'id1'
=>
new
Solarium_Result_Select_MoreLikeThis_Result
(
12
,
1.75
,
$docs
)
);
$result
=
$this
->
_parser
->
parse
(
$query
,
null
,
$data
);
$this
->
assertEquals
(
$expected
,
$result
->
getResults
());
}
public
function
testParseNoData
()
{
$result
=
$this
->
_parser
->
parse
(
null
,
null
,
array
());
$this
->
assertEquals
(
array
(),
$result
->
getResults
());
}
}
tests/Solarium/Client/ResponseParser/UpdateTest.php
View file @
281d770a
...
@@ -34,7 +34,15 @@ class Solarium_Client_ResponseParser_UpdateTest extends PHPUnit_Framework_TestCa
...
@@ -34,7 +34,15 @@ class Solarium_Client_ResponseParser_UpdateTest extends PHPUnit_Framework_TestCa
public
function
testParse
()
public
function
testParse
()
{
{
$data
=
'{"responseHeader" : {"status":1,"QTime":15}}'
;
$response
=
new
Solarium_Client_Response
(
$data
,
array
(
'HTTP 1.1 200 OK'
));
$result
=
new
Solarium_Result_Update
(
null
,
null
,
$response
);
$parser
=
new
Solarium_Client_ResponseParser_Update
;
$parsed
=
$parser
->
parse
(
$result
);
$this
->
assertEquals
(
1
,
$parsed
[
'status'
]);
$this
->
assertEquals
(
15
,
$parsed
[
'queryTime'
]);
}
}
}
}
tests/Solarium/Result/SelectTest.php
View file @
281d770a
...
@@ -58,7 +58,7 @@ class Solarium_Result_SelectTest extends PHPUnit_Framework_TestCase
...
@@ -58,7 +58,7 @@ class Solarium_Result_SelectTest extends PHPUnit_Framework_TestCase
Solarium_Query_Select
::
COMPONENT_HIGHLIGHTING
=>
$this
->
_highlighting
Solarium_Query_Select
::
COMPONENT_HIGHLIGHTING
=>
$this
->
_highlighting
);
);
$this
->
_result
=
new
Solarium_Result_SelectDummy
(
$this
->
_numFound
,
$this
->
_docs
,
$this
->
_components
);
$this
->
_result
=
new
Solarium_Result_SelectDummy
(
1
,
12
,
$this
->
_numFound
,
$this
->
_docs
,
$this
->
_components
);
}
}
public
function
testGetNumFound
()
public
function
testGetNumFound
()
...
@@ -128,6 +128,22 @@ class Solarium_Result_SelectTest extends PHPUnit_Framework_TestCase
...
@@ -128,6 +128,22 @@ class Solarium_Result_SelectTest extends PHPUnit_Framework_TestCase
$this
->
assertEquals
(
$this
->
_docs
,
$docs
);
$this
->
assertEquals
(
$this
->
_docs
,
$docs
);
}
}
public
function
testGetStatus
()
{
$this
->
assertEquals
(
1
,
$this
->
_result
->
getStatus
()
);
}
public
function
testGetQueryTime
()
{
$this
->
assertEquals
(
12
,
$this
->
_result
->
getQueryTime
()
);
}
}
}
...
@@ -135,12 +151,13 @@ class Solarium_Result_SelectDummy extends Solarium_Result_Select
...
@@ -135,12 +151,13 @@ class Solarium_Result_SelectDummy extends Solarium_Result_Select
{
{
protected
$_parsed
=
true
;
protected
$_parsed
=
true
;
public
function
__construct
(
$numfound
,
$docs
,
$components
)
public
function
__construct
(
$
status
,
$queryTime
,
$
numfound
,
$docs
,
$components
)
{
{
$this
->
_numfound
=
$numfound
;
$this
->
_numfound
=
$numfound
;
$this
->
_documents
=
$docs
;
$this
->
_documents
=
$docs
;
$this
->
_components
=
$components
;
$this
->
_components
=
$components
;
$this
->
_queryTime
=
$queryTime
;
$this
->
_status
=
$status
;
}
}
}
}
\ 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