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
88ef7999
Commit
88ef7999
authored
Jun 11, 2018
by
thomascorthals
Committed by
Markus Kalkbrenner
Jun 11, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added support for NOW and TZ (#599)
* Added support for NOW and TZ
parent
f64f3127
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
94 additions
and
0 deletions
+94
-0
src/Core/Query/AbstractQuery.php
src/Core/Query/AbstractQuery.php
+50
-0
src/Core/Query/AbstractRequestBuilder.php
src/Core/Query/AbstractRequestBuilder.php
+2
-0
tests/Core/Query/QueryTest.php
tests/Core/Query/QueryTest.php
+14
-0
tests/Core/Query/RequestBuilderTest.php
tests/Core/Query/RequestBuilderTest.php
+28
-0
No files found.
src/Core/Query/AbstractQuery.php
View file @
88ef7999
...
...
@@ -198,4 +198,54 @@ abstract class AbstractQuery extends Configurable implements QueryInterface
return
$responseWriter
;
}
/**
* Set now option.
*
* Instructs Solr to use an arbitrary moment in time (past or future) to override NOW for date math expressions.
*
* Make sure to pass a string instead of an int if the code has to run on a 32-bit PHP installation.
*
* @param string $timestamp Milliseconds since epoch
*
* @return self Provides fluent interface
*/
public
function
setNow
(
$timestamp
)
{
return
$this
->
setOption
(
'now'
,
$timestamp
);
}
/**
* Get now option.
*
* @return string Milliseconds since epoch
*/
public
function
getNow
()
{
return
$this
->
getOption
(
'now'
);
}
/**
* Set timezone option.
*
* Forces all date based addition and rounding to be relative to the specified time zone instead of UTC.
*
* @param string $timezone Java TimeZone ID
*
* @return self Provides fluent interface
*/
public
function
setTimeZone
(
$timezone
)
{
return
$this
->
setOption
(
'timezone'
,
$timezone
);
}
/**
* Get timezone option.
*
* @return string Java TimeZone ID
*/
public
function
getTimeZone
()
{
return
$this
->
getOption
(
'timezone'
);
}
}
src/Core/Query/AbstractRequestBuilder.php
View file @
88ef7999
...
...
@@ -22,6 +22,8 @@ abstract class AbstractRequestBuilder implements RequestBuilderInterface
$request
->
setHandler
(
$query
->
getHandler
());
$request
->
addParam
(
'omitHeader'
,
$query
->
getOmitHeader
());
$request
->
addParam
(
'timeAllowed'
,
$query
->
getTimeAllowed
());
$request
->
addParam
(
'NOW'
,
$query
->
getNow
());
$request
->
addParam
(
'TZ'
,
$query
->
getTimeZone
());
$request
->
addParams
(
$query
->
getParams
());
$request
->
addParam
(
'wt'
,
$query
->
getResponseWriter
());
...
...
tests/Core/Query/QueryTest.php
View file @
88ef7999
...
...
@@ -70,6 +70,20 @@ class QueryTest extends TestCase
$query
->
setTimeAllowed
(
1200
);
$this
->
assertSame
(
1200
,
$query
->
getTimeAllowed
());
}
public
function
testSetAndGetNow
()
{
$query
=
new
TestQuery
();
$query
->
setNow
(
'1520997255000'
);
$this
->
assertSame
(
'1520997255000'
,
$query
->
getNow
());
}
public
function
testSetAndGetTimeZone
()
{
$query
=
new
TestQuery
();
$query
->
setTimeZone
(
'Europe/Brussels'
);
$this
->
assertSame
(
'Europe/Brussels'
,
$query
->
getTimeZone
());
}
}
class
TestQuery
extends
AbstractQuery
...
...
tests/Core/Query/RequestBuilderTest.php
View file @
88ef7999
...
...
@@ -60,6 +60,34 @@ class RequestBuilderTest extends TestCase
);
}
public
function
testBuildWithNow
()
{
$query
=
new
SelectQuery
();
$query
->
addParam
(
'p1'
,
'v1'
);
$query
->
addParam
(
'p2'
,
'v2'
);
$query
->
setNow
(
'1520997255000'
);
$request
=
$this
->
builder
->
build
(
$query
);
$this
->
assertSame
(
'select?omitHeader=true&NOW=1520997255000&p1=v1&p2=v2&wt=json&json.nl=flat'
,
urldecode
(
$request
->
getUri
())
);
}
public
function
testBuildWithTimeZone
()
{
$query
=
new
SelectQuery
();
$query
->
addParam
(
'p1'
,
'v1'
);
$query
->
addParam
(
'p2'
,
'v2'
);
$query
->
setTimeZone
(
'Europe/Brussels'
);
$request
=
$this
->
builder
->
build
(
$query
);
$this
->
assertSame
(
'select?omitHeader=true&TZ=Europe/Brussels&p1=v1&p2=v2&wt=json&json.nl=flat'
,
urldecode
(
$request
->
getUri
())
);
}
public
function
testRenderLocalParams
()
{
$myParams
=
[
'tag'
=>
'mytag'
,
'ex'
=>
[
'exclude1'
,
'exclude2'
]];
...
...
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