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
5da3959c
Commit
5da3959c
authored
Jul 27, 2012
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes for issue #81
parent
bb517cea
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
161 additions
and
67 deletions
+161
-67
library/Solarium/QueryType/MoreLikeThis/Query.php
library/Solarium/QueryType/MoreLikeThis/Query.php
+22
-8
library/Solarium/QueryType/MoreLikeThis/RequestBuilder.php
library/Solarium/QueryType/MoreLikeThis/RequestBuilder.php
+2
-2
library/Solarium/QueryType/Select/Query/Component/Facet/Range.php
...Solarium/QueryType/Select/Query/Component/Facet/Range.php
+16
-12
library/Solarium/QueryType/Select/Query/Component/MoreLikeThis.php
...olarium/QueryType/Select/Query/Component/MoreLikeThis.php
+23
-7
library/Solarium/QueryType/Select/RequestBuilder/Component/FacetSet.php
...um/QueryType/Select/RequestBuilder/Component/FacetSet.php
+4
-10
library/Solarium/QueryType/Select/RequestBuilder/Component/MoreLikeThis.php
...ueryType/Select/RequestBuilder/Component/MoreLikeThis.php
+2
-2
library/Solarium/QueryType/Terms/Query.php
library/Solarium/QueryType/Terms/Query.php
+24
-8
library/Solarium/QueryType/Terms/RequestBuilder.php
library/Solarium/QueryType/Terms/RequestBuilder.php
+3
-7
library/Solarium/QueryType/Terms/ResponseParser.php
library/Solarium/QueryType/Terms/ResponseParser.php
+1
-3
tests/Solarium/Tests/QueryType/MoreLikeThis/QueryTest.php
tests/Solarium/Tests/QueryType/MoreLikeThis/QueryTest.php
+22
-0
tests/Solarium/Tests/QueryType/Select/Query/Component/Facet/RangeTest.php
...ests/QueryType/Select/Query/Component/Facet/RangeTest.php
+6
-6
tests/Solarium/Tests/QueryType/Select/Query/Component/MoreLikeThisTest.php
...sts/QueryType/Select/Query/Component/MoreLikeThisTest.php
+22
-0
tests/Solarium/Tests/QueryType/Terms/QueryTest.php
tests/Solarium/Tests/QueryType/Terms/QueryTest.php
+14
-2
No files found.
library/Solarium/QueryType/MoreLikeThis/Query.php
View file @
5da3959c
...
...
@@ -180,24 +180,31 @@ class Query extends SelectQuery
* The fields to use for similarity. NOTE: if possible, these should have a
* stored TermVector
*
* Separate multiple fields with commas.
* Separate multiple fields with commas
if you use string input
.
*
* @param string $fields
* @param string
|array
$fields
* @return self Provides fluent interface
*/
public
function
setMltFields
(
$fields
)
{
if
(
is_string
(
$fields
))
{
$fields
=
explode
(
','
,
$fields
);
$fields
=
array_map
(
'trim'
,
$fields
);
}
return
$this
->
setOption
(
'mltfields'
,
$fields
);
}
/**
* Get MLT fields option
*
* @return
string|null
* @return
array
*/
public
function
getMltFields
()
{
return
$this
->
getOption
(
'mltfields'
);
$value
=
$this
->
getOption
(
'mltfields'
);
if
(
$value
===
null
)
$value
=
array
();
return
$value
;
}
/**
...
...
@@ -371,24 +378,31 @@ class Query extends SelectQuery
* Query fields and their boosts using the same format as that used in
* DisMaxQParserPlugin. These fields must also be specified in fields.
*
* Separate multiple fields with commas.
* Separate multiple fields with commas
if you use string input
.
*
* @param string $queryFields
* @param string
|array
$queryFields
* @return self Provides fluent interface
*/
public
function
setQueryFields
(
$queryFields
)
{
if
(
is_string
(
$queryFields
))
{
$queryFields
=
explode
(
','
,
$queryFields
);
$queryFields
=
array_map
(
'trim'
,
$queryFields
);
}
return
$this
->
setOption
(
'queryfields'
,
$queryFields
);
}
/**
* Get queryfields option
*
* @return
string|null
* @return
array
*/
public
function
getQueryFields
()
{
return
$this
->
getOption
(
'queryfields'
);
$value
=
$this
->
getOption
(
'queryfields'
);
if
(
$value
===
null
)
$value
=
array
();
return
$value
;
}
}
library/Solarium/QueryType/MoreLikeThis/RequestBuilder.php
View file @
5da3959c
...
...
@@ -64,7 +64,7 @@ class RequestBuilder extends SelectRequestBuilder
$request
->
addParam
(
'mlt.interestingTerms'
,
$query
->
getInterestingTerms
());
$request
->
addParam
(
'mlt.match.include'
,
$query
->
getMatchInclude
());
$request
->
addParam
(
'mlt.match.offset'
,
$query
->
getStart
());
$request
->
addParam
(
'mlt.fl'
,
$query
->
getMltFields
(
));
$request
->
addParam
(
'mlt.fl'
,
implode
(
','
,
$query
->
getMltFields
()
));
$request
->
addParam
(
'mlt.mintf'
,
$query
->
getMinimumTermFrequency
());
$request
->
addParam
(
'mlt.mindf'
,
$query
->
getMinimumDocumentFrequency
());
$request
->
addParam
(
'mlt.minwl'
,
$query
->
getMinimumWordLength
());
...
...
@@ -72,7 +72,7 @@ class RequestBuilder extends SelectRequestBuilder
$request
->
addParam
(
'mlt.maxqt'
,
$query
->
getMaximumQueryTerms
());
$request
->
addParam
(
'mlt.maxntp'
,
$query
->
getMaximumNumberOfTokens
());
$request
->
addParam
(
'mlt.boost'
,
$query
->
getBoost
());
$request
->
addParam
(
'mlt.qf'
,
$query
->
getQueryFields
(
));
$request
->
addParam
(
'mlt.qf'
,
implode
(
','
,
$query
->
getQueryFields
()
));
// convert query to stream if necessary
if
(
true
===
$query
->
getQueryStream
())
{
...
...
library/Solarium/QueryType/Select/Query/Component/Facet/Range.php
View file @
5da3959c
...
...
@@ -254,8 +254,9 @@ class Range extends Facet
*/
public
function
setOther
(
$other
)
{
if
(
is_array
(
$other
))
{
$other
=
implode
(
','
,
$other
);
if
(
is_string
(
$other
))
{
$other
=
explode
(
','
,
$other
);
$other
=
array_map
(
'trim'
,
$other
);
}
return
$this
->
setOption
(
'other'
,
$other
);
...
...
@@ -264,13 +265,14 @@ class Range extends Facet
/**
* Get other counts
*
* In case of multiple values a comma separated string will be returned
*
* @return string
* @return array
*/
public
function
getOther
()
{
return
$this
->
getOption
(
'other'
);
$other
=
$this
->
getOption
(
'other'
);
if
(
$other
===
null
)
$other
=
array
();
return
$other
;
}
/**
...
...
@@ -284,8 +286,9 @@ class Range extends Facet
*/
public
function
setInclude
(
$include
)
{
if
(
is_array
(
$include
))
{
$include
=
implode
(
','
,
$include
);
if
(
is_string
(
$include
))
{
$include
=
explode
(
','
,
$include
);
$include
=
array_map
(
'trim'
,
$include
);
}
return
$this
->
setOption
(
'include'
,
$include
);
...
...
@@ -294,12 +297,13 @@ class Range extends Facet
/**
* Get include option
*
* In case of multiple values a comma separated string will be returned
*
* @return string
* @return array
*/
public
function
getInclude
()
{
return
$this
->
getOption
(
'include'
);
$include
=
$this
->
getOption
(
'include'
);
if
(
$include
===
null
)
$include
=
array
();
return
$include
;
}
}
library/Solarium/QueryType/Select/Query/Component/MoreLikeThis.php
View file @
5da3959c
...
...
@@ -85,24 +85,32 @@ class MoreLikeThis extends Component
* The fields to use for similarity. NOTE: if possible, these should have a
* stored TermVector
*
*
S
eparate multiple fields with commas.
*
When using string input you can s
eparate multiple fields with commas.
*
* @param string $fields
* @param string
|array
$fields
* @return self Provides fluent interface
*/
public
function
setFields
(
$fields
)
{
if
(
is_string
(
$fields
))
{
$fields
=
explode
(
','
,
$fields
);
$fields
=
array_map
(
'trim'
,
$fields
);
}
return
$this
->
setOption
(
'fields'
,
$fields
);
}
/**
* Get fields option
*
* @return
string|null
* @return
array
*/
public
function
getFields
()
{
return
$this
->
getOption
(
'fields'
);
$fields
=
$this
->
getOption
(
'fields'
);
if
(
$fields
==
null
)
$fields
=
array
();
return
$fields
;
}
/**
...
...
@@ -276,24 +284,32 @@ class MoreLikeThis extends Component
* Query fields and their boosts using the same format as that used in
* DisMaxQParserPlugin. These fields must also be specified in fields.
*
*
S
eparate multiple fields with commas.
*
When using string input you can s
eparate multiple fields with commas.
*
* @param string $queryFields
* @return self Provides fluent interface
*/
public
function
setQueryFields
(
$queryFields
)
{
if
(
is_string
(
$queryFields
))
{
$queryFields
=
explode
(
','
,
$queryFields
);
$queryFields
=
array_map
(
'trim'
,
$queryFields
);
}
return
$this
->
setOption
(
'queryfields'
,
$queryFields
);
}
/**
* Get queryfields option
*
* @return
string|null
* @return
array
*/
public
function
getQueryFields
()
{
return
$this
->
getOption
(
'queryfields'
);
$queryfields
=
$this
->
getOption
(
'queryfields'
);
if
(
$queryfields
==
null
)
$queryfields
=
array
();
return
$queryfields
;
}
/**
...
...
library/Solarium/QueryType/Select/RequestBuilder/Component/FacetSet.php
View file @
5da3959c
...
...
@@ -182,18 +182,12 @@ class FacetSet extends RequestBuilder
$request
->
addParam
(
"f.
$field
.facet.range.gap"
,
$facet
->
getGap
());
$request
->
addParam
(
"f.
$field
.facet.range.hardend"
,
$facet
->
getHardend
());
if
(
null
!==
$facet
->
getOther
())
{
$other
=
explode
(
','
,
$facet
->
getOther
());
foreach
(
$other
AS
$otherValue
)
{
$request
->
addParam
(
"f.
$field
.facet.range.other"
,
trim
(
$otherValue
));
}
foreach
(
$facet
->
getOther
()
as
$otherValue
)
{
$request
->
addParam
(
"f.
$field
.facet.range.other"
,
$otherValue
);
}
if
(
null
!==
$facet
->
getInclude
())
{
$include
=
explode
(
','
,
$facet
->
getInclude
());
foreach
(
$include
AS
$includeValue
)
{
$request
->
addParam
(
"f.
$field
.facet.range.include"
,
trim
(
$includeValue
));
}
foreach
(
$facet
->
getInclude
()
as
$includeValue
)
{
$request
->
addParam
(
"f.
$field
.facet.range.include"
,
$includeValue
);
}
}
}
library/Solarium/QueryType/Select/RequestBuilder/Component/MoreLikeThis.php
View file @
5da3959c
...
...
@@ -58,7 +58,7 @@ class MoreLikeThis
// enable morelikethis
$request
->
addParam
(
'mlt'
,
'true'
);
$request
->
addParam
(
'mlt.fl'
,
$component
->
getFields
(
));
$request
->
addParam
(
'mlt.fl'
,
implode
(
','
,
$component
->
getFields
()
));
$request
->
addParam
(
'mlt.mintf'
,
$component
->
getMinimumTermFrequency
());
$request
->
addParam
(
'mlt.mindf'
,
$component
->
getMinimumDocumentFrequency
());
$request
->
addParam
(
'mlt.minwl'
,
$component
->
getMinimumWordLength
());
...
...
@@ -66,7 +66,7 @@ class MoreLikeThis
$request
->
addParam
(
'mlt.maxqt'
,
$component
->
getMaximumQueryTerms
());
$request
->
addParam
(
'mlt.maxntp'
,
$component
->
getMaximumNumberOfTokens
());
$request
->
addParam
(
'mlt.boost'
,
$component
->
getBoost
());
$request
->
addParam
(
'mlt.qf'
,
$component
->
getQueryFields
(
));
$request
->
addParam
(
'mlt.qf'
,
implode
(
','
,
$component
->
getQueryFields
()
));
$request
->
addParam
(
'mlt.count'
,
$component
->
getCount
());
return
$request
;
...
...
library/Solarium/QueryType/Terms/Query.php
View file @
5da3959c
...
...
@@ -97,24 +97,32 @@ class Query extends BaseQuery
/**
* Set the field name(s) to get the terms from
*
* For multiple fields use a comma-separated string
* For multiple fields use a comma-separated string
or array
*
* @param string $value
* @param string
|array
$value
* @return self Provides fluent interface
*/
public
function
setFields
(
$value
)
{
if
(
is_string
(
$value
))
{
$value
=
explode
(
','
,
$value
);
$value
=
array_map
(
'trim'
,
$value
);
}
return
$this
->
setOption
(
'fields'
,
$value
);
}
/**
* Get the field name(s) to get the terms from
*
* @return
string
* @return
array
*/
public
function
getFields
()
{
return
$this
->
getOption
(
'fields'
);
$value
=
$this
->
getOption
(
'fields'
);
if
(
$value
===
null
)
$value
=
array
();
return
$value
;
}
/**
...
...
@@ -246,24 +254,32 @@ class Query extends BaseQuery
/**
* Set regex flags
*
* Use a comma-separated string for multiple entries
* Use a comma-separated string
or array
for multiple entries
*
* @param string $value
* @param string
|array
$value
* @return self Provides fluent interface
*/
public
function
setRegexFlags
(
$value
)
{
if
(
is_string
(
$value
))
{
$value
=
explode
(
','
,
$value
);
$value
=
array_map
(
'trim'
,
$value
);
}
return
$this
->
setOption
(
'regexflags'
,
$value
);
}
/**
* Get regex flags
*
* @return
string
* @return
array
*/
public
function
getRegexFlags
()
{
return
$this
->
getOption
(
'regexflags'
);
$value
=
$this
->
getOption
(
'regexflags'
);
if
(
$value
===
null
)
$value
=
array
();
return
$value
;
}
/**
...
...
library/Solarium/QueryType/Terms/RequestBuilder.php
View file @
5da3959c
...
...
@@ -73,16 +73,12 @@ class RequestBuilder extends BaseRequestBuilder
$request
->
addParam
(
'terms.raw'
,
$query
->
getRaw
());
$request
->
addParam
(
'terms.sort'
,
$query
->
getSort
());
$fields
=
explode
(
','
,
$query
->
getFields
());
foreach
(
$fields
as
$field
)
{
foreach
(
$query
->
getFields
()
as
$field
)
{
$request
->
addParam
(
'terms.fl'
,
trim
(
$field
));
}
if
(
$query
->
getRegexFlags
()
!==
null
)
{
$flags
=
explode
(
','
,
$query
->
getRegexFlags
());
foreach
(
$flags
as
$flag
)
{
$request
->
addParam
(
'terms.regex.flag'
,
trim
(
$flag
));
}
foreach
(
$query
->
getRegexFlags
()
as
$flag
)
{
$request
->
addParam
(
'terms.regex.flag'
,
trim
(
$flag
));
}
return
$request
;
...
...
library/Solarium/QueryType/Terms/ResponseParser.php
View file @
5da3959c
...
...
@@ -59,9 +59,7 @@ class ResponseParser extends ResponseParserAbstract implements ResponseParserInt
$data
=
$result
->
getData
();
$query
=
$result
->
getQuery
();
$field
=
$query
->
getFields
();
$fields
=
explode
(
','
,
$field
);
foreach
(
$fields
as
$field
)
{
foreach
(
$query
->
getFields
()
as
$field
)
{
$field
=
trim
(
$field
);
if
(
isset
(
$data
[
'terms'
][
$field
]))
{
$terms
=
$data
[
'terms'
][
$field
];
...
...
tests/Solarium/Tests/QueryType/MoreLikeThis/QueryTest.php
View file @
5da3959c
...
...
@@ -666,6 +666,17 @@ class QueryTest extends \PHPUnit_Framework_TestCase
$value
=
'name,description'
;
$this
->
query
->
setMltFields
(
$value
);
$this
->
assertEquals
(
array
(
'name'
,
'description'
),
$this
->
query
->
getMltFields
()
);
}
public
function
testSetAndGetMltFieldsWithArray
()
{
$value
=
array
(
'name'
,
'description'
);
$this
->
query
->
setMltFields
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
query
->
getMltFields
()
...
...
@@ -776,6 +787,17 @@ class QueryTest extends \PHPUnit_Framework_TestCase
$value
=
'content,name'
;
$this
->
query
->
setQueryFields
(
$value
);
$this
->
assertEquals
(
array
(
'content'
,
'name'
),
$this
->
query
->
getQueryFields
()
);
}
public
function
testSetAndGetQueryFieldsWithArray
()
{
$value
=
array
(
'content'
,
'name'
);
$this
->
query
->
setQueryFields
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
query
->
getQueryFields
()
...
...
tests/Solarium/Tests/QueryType/Select/Query/Component/Facet/RangeTest.php
View file @
5da3959c
...
...
@@ -70,8 +70,8 @@ class RangeTest extends \PHPUnit_Framework_TestCase
$this
->
assertEquals
(
$options
[
'end'
],
$this
->
facet
->
getEnd
());
$this
->
assertEquals
(
$options
[
'gap'
],
$this
->
facet
->
getGap
());
$this
->
assertEquals
(
$options
[
'hardend'
],
$this
->
facet
->
getHardend
());
$this
->
assertEquals
(
$options
[
'other'
]
,
$this
->
facet
->
getOther
());
$this
->
assertEquals
(
$options
[
'include'
]
,
$this
->
facet
->
getInclude
());
$this
->
assertEquals
(
array
(
$options
[
'other'
])
,
$this
->
facet
->
getOther
());
$this
->
assertEquals
(
array
(
$options
[
'include'
])
,
$this
->
facet
->
getInclude
());
}
public
function
testGetType
()
...
...
@@ -115,25 +115,25 @@ class RangeTest extends \PHPUnit_Framework_TestCase
public
function
testSetAndGetOther
()
{
$this
->
facet
->
setOther
(
'all'
);
$this
->
assertEquals
(
'all'
,
$this
->
facet
->
getOther
());
$this
->
assertEquals
(
array
(
'all'
)
,
$this
->
facet
->
getOther
());
}
public
function
testSetAndGetOtherArray
()
{
$this
->
facet
->
setOther
(
array
(
'before'
,
'after'
));
$this
->
assertEquals
(
'before,after'
,
$this
->
facet
->
getOther
());
$this
->
assertEquals
(
array
(
'before'
,
'after'
)
,
$this
->
facet
->
getOther
());
}
public
function
testSetAndGetInclude
()
{
$this
->
facet
->
setInclude
(
'all'
);
$this
->
assertEquals
(
'all'
,
$this
->
facet
->
getInclude
());
$this
->
assertEquals
(
array
(
'all'
)
,
$this
->
facet
->
getInclude
());
}
public
function
testSetAndGetIncludeArray
()
{
$this
->
facet
->
setInclude
(
array
(
'lower'
,
'upper'
));
$this
->
assertEquals
(
'lower,upper'
,
$this
->
facet
->
getInclude
());
$this
->
assertEquals
(
array
(
'lower'
,
'upper'
)
,
$this
->
facet
->
getInclude
());
}
}
tests/Solarium/Tests/QueryType/Select/Query/Component/MoreLikeThisTest.php
View file @
5da3959c
...
...
@@ -94,6 +94,17 @@ class MoreLikeThisTest extends \PHPUnit_Framework_TestCase
$value
=
'name,description'
;
$this
->
mlt
->
setFields
(
$value
);
$this
->
assertEquals
(
array
(
'name'
,
'description'
),
$this
->
mlt
->
getFields
()
);
}
public
function
testSetAndGetFieldsWithArray
()
{
$value
=
array
(
'name'
,
'description'
);
$this
->
mlt
->
setFields
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
mlt
->
getFields
()
...
...
@@ -182,6 +193,17 @@ class MoreLikeThisTest extends \PHPUnit_Framework_TestCase
$value
=
'content,name'
;
$this
->
mlt
->
setQueryFields
(
$value
);
$this
->
assertEquals
(
array
(
'content'
,
'name'
),
$this
->
mlt
->
getQueryFields
()
);
}
public
function
testSetAndGetQueryFieldsWithArray
()
{
$value
=
array
(
'content'
,
'name'
);
$this
->
mlt
->
setQueryFields
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
mlt
->
getQueryFields
()
...
...
tests/Solarium/Tests/QueryType/Terms/QueryTest.php
View file @
5da3959c
...
...
@@ -64,7 +64,13 @@ class QueryTest extends \PHPUnit_Framework_TestCase
public
function
testSetAndGetFields
()
{
$this
->
query
->
setFields
(
'fieldA,fieldB'
);
$this
->
assertEquals
(
'fieldA,fieldB'
,
$this
->
query
->
getFields
());
$this
->
assertEquals
(
array
(
'fieldA'
,
'fieldB'
),
$this
->
query
->
getFields
());
}
public
function
testSetAndGetFieldsWithArray
()
{
$this
->
query
->
setFields
(
array
(
'fieldA'
,
'fieldB'
));
$this
->
assertEquals
(
array
(
'fieldA'
,
'fieldB'
),
$this
->
query
->
getFields
());
}
public
function
testSetAndGetLowerbound
()
...
...
@@ -106,7 +112,13 @@ class QueryTest extends \PHPUnit_Framework_TestCase
public
function
testSetAndGetRegexFlags
()
{
$this
->
query
->
setRegexFlags
(
'case_insensitive,comments'
);
$this
->
assertEquals
(
'case_insensitive,comments'
,
$this
->
query
->
getRegexFlags
());
$this
->
assertEquals
(
array
(
'case_insensitive'
,
'comments'
),
$this
->
query
->
getRegexFlags
());
}
public
function
testSetAndGetRegexFlagsWithArray
()
{
$this
->
query
->
setRegexFlags
(
array
(
'case_insensitive'
,
'comments'
));
$this
->
assertEquals
(
array
(
'case_insensitive'
,
'comments'
),
$this
->
query
->
getRegexFlags
());
}
public
function
testSetAndGetLimit
()
...
...
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