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
e83202a2
Commit
e83202a2
authored
May 15, 2012
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' of github.com:basdenooijer/solarium into develop
parents
2dd0f0e4
ec513c82
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
718 additions
and
11 deletions
+718
-11
library/Solarium/Client/RequestBuilder/Select/Component/EDisMax.php
...larium/Client/RequestBuilder/Select/Component/EDisMax.php
+79
-0
library/Solarium/Client/ResponseParser/Select/Component/Spellcheck.php
...ium/Client/ResponseParser/Select/Component/Spellcheck.php
+3
-3
library/Solarium/Query/Select.php
library/Solarium/Query/Select.php
+22
-0
library/Solarium/Query/Select/Component/EDisMax.php
library/Solarium/Query/Select/Component/EDisMax.php
+222
-0
library/Solarium/Result/Select/Spellcheck.php
library/Solarium/Result/Select/Spellcheck.php
+29
-8
tests/Solarium/Client/RequestBuilder/Select/Component/EDisMaxTest.php
...um/Client/RequestBuilder/Select/Component/EDisMaxTest.php
+84
-0
tests/Solarium/Client/RequestBuilder/SelectTest.php
tests/Solarium/Client/RequestBuilder/SelectTest.php
+11
-0
tests/Solarium/Query/Select/Component/EDisMaxTest.php
tests/Solarium/Query/Select/Component/EDisMaxTest.php
+268
-0
No files found.
library/Solarium/Client/RequestBuilder/Select/Component/EDisMax.php
0 → 100644
View file @
e83202a2
<?php
/**
* Copyright 2012 Marc Morera. 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.
*
* @copyright Copyright 2012 Marc Morera <yuhu@mmoreram.com>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Client
*/
/**
* Add select component edismax to the request
*
* @package Solarium
* @subpackage Client
*/
class
Solarium_Client_RequestBuilder_Select_Component_EDisMax
{
/**
* Add request settings for EDismax
*
* @param Solarium_Query_Select_Component_EDismax $component
* @param Solarium_Client_Request $request
* @return Solarium_Client_Request
*/
public
function
buildComponent
(
$component
,
$request
)
{
// enable edismax
$request
->
addParam
(
'defType'
,
$component
->
getQueryParser
());
$request
->
addParam
(
'q.alt'
,
$component
->
getQueryAlternative
());
$request
->
addParam
(
'qf'
,
$component
->
getQueryFields
());
$request
->
addParam
(
'mm'
,
$component
->
getMinimumMatch
());
$request
->
addParam
(
'pf'
,
$component
->
getPhraseFields
());
$request
->
addParam
(
'ps'
,
$component
->
getPhraseSlop
());
$request
->
addParam
(
'pf2'
,
$component
->
getPhraseBigramFields
());
$request
->
addParam
(
'ps2'
,
$component
->
getPhraseBigramSlop
());
$request
->
addParam
(
'pf3'
,
$component
->
getPhraseTrigramFields
());
$request
->
addParam
(
'ps3'
,
$component
->
getPhraseTrigramSlop
());
$request
->
addParam
(
'qs'
,
$component
->
getQueryPhraseSlop
());
$request
->
addParam
(
'tie'
,
$component
->
getTie
());
$request
->
addParam
(
'bq'
,
$component
->
getBoostQuery
());
$request
->
addParam
(
'bf'
,
$component
->
getBoostFunctions
());
$request
->
addParam
(
'boost'
,
$component
->
getBoostFunctionsMult
());
$request
->
addParam
(
'uf'
,
$component
->
getUserFields
());
return
$request
;
}
}
\ No newline at end of file
library/Solarium/Client/ResponseParser/Select/Component/Spellcheck.php
View file @
e83202a2
...
...
@@ -66,7 +66,7 @@ class Solarium_Client_ResponseParser_Select_Component_Spellcheck
$suggestions
=
array
();
$correctlySpelled
=
null
;
$collation
=
null
;
$collation
s
=
array
()
;
$index
=
0
;
while
(
isset
(
$spellcheckResults
[
$index
])
&&
isset
(
$spellcheckResults
[
$index
+
1
]))
{
...
...
@@ -78,7 +78,7 @@ class Solarium_Client_ResponseParser_Select_Component_Spellcheck
$correctlySpelled
=
$value
;
break
;
case
'collation'
:
$collation
=
$this
->
_parseCollation
(
$value
);
$collation
s
[]
=
$this
->
_parseCollation
(
$value
);
break
;
default
:
$suggestions
[]
=
$this
->
_parseSuggestion
(
$key
,
$value
);
...
...
@@ -87,7 +87,7 @@ class Solarium_Client_ResponseParser_Select_Component_Spellcheck
$index
+=
2
;
}
return
new
Solarium_Result_Select_Spellcheck
(
$suggestions
,
$collation
,
$correctlySpelled
);
return
new
Solarium_Result_Select_Spellcheck
(
$suggestions
,
$collation
s
,
$correctlySpelled
);
}
else
{
return
null
;
}
...
...
library/Solarium/Query/Select.php
View file @
e83202a2
...
...
@@ -79,6 +79,11 @@ class Solarium_Query_Select extends Solarium_Query
*/
const
COMPONENT_DISMAX
=
'dismax'
;
/**
* Query component dismax
*/
const
COMPONENT_EDISMAX
=
'edismax'
;
/**
* Query component morelikethis
*/
...
...
@@ -155,6 +160,11 @@ class Solarium_Query_Select extends Solarium_Query
'requestbuilder'
=>
'Solarium_Client_RequestBuilder_Select_Component_DisMax'
,
'responseparser'
=>
null
,
),
self
::
COMPONENT_EDISMAX
=>
array
(
'component'
=>
'Solarium_Query_Select_Component_EDisMax'
,
'requestbuilder'
=>
'Solarium_Client_RequestBuilder_Select_Component_EDisMax'
,
'responseparser'
=>
null
,
),
self
::
COMPONENT_MORELIKETHIS
=>
array
(
'component'
=>
'Solarium_Query_Select_Component_MoreLikeThis'
,
'requestbuilder'
=>
'Solarium_Client_RequestBuilder_Select_Component_MoreLikeThis'
,
...
...
@@ -900,6 +910,18 @@ class Solarium_Query_Select extends Solarium_Query
return
$this
->
getComponent
(
Solarium_Query_Select
::
COMPONENT_DISMAX
,
true
);
}
/**
* Get a EDisMax component instance
*
* This is a convenience method that maps presets to getComponent
*
* @return Solarium_Query_Select_Component_EDisMax
*/
public
function
getEDisMax
()
{
return
$this
->
getComponent
(
Solarium_Query_Select
::
COMPONENT_EDISMAX
,
true
);
}
/**
* Get a highlighting component instance
*
...
...
library/Solarium/Query/Select/Component/EDisMax.php
0 → 100644
View file @
e83202a2
<?php
/**
* Copyright 2012 Marc Morera. 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.
*
* @copyright Copyright 2012 Marc Morera <yuhu@mmoreram.com>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Query
*/
/**
* EDisMax component
*
* @link http://wiki.apache.org/solr/ExtendedDisMax
*
* @package Solarium
* @subpackage Query
*/
class
Solarium_Query_Select_Component_EDisMax
extends
Solarium_Query_Select_Component_DisMax
{
/**
* Component type
*
* @var string
*/
protected
$_type
=
Solarium_Query_Select
::
COMPONENT_EDISMAX
;
/**
* Default options
*
* @var array
*/
protected
$_options
=
array
(
'queryparser'
=>
'edismax'
,
);
/**
* Set BoostFunctionsMult option
*
* Functions (with optional boosts) that will be included in the
* user's query to influence the score by multiplying its value.
*
* Format is: "funcA(arg1,arg2)^1.2 funcB(arg3,arg4)^2.2"
*
* @param string $boostFunctionsMult
* @return Solarium_Query_Select_Component_EDisMax Provides fluent interface
*/
public
function
setBoostFunctionsMult
(
$boostFunctionsMult
)
{
return
$this
->
_setOption
(
'boostfunctionsmult'
,
$boostFunctionsMult
);
}
/**
* Get BoostFunctionsMult option
*
* @return string|null
*/
public
function
getBoostFunctionsMult
()
{
return
$this
->
getOption
(
'boostfunctionsmult'
);
}
/**
* Set PhraseFields option
*
* As with 'pf' but chops the input into bi-grams,
* e.g. "the brown fox jumped" is queried as "the brown" "brown fox" "fox jumped"
*
* Format is: "fieldA^1.0 fieldB^2.2 fieldC^3.5"
*
* @param string $phraseBigramFields
* @return Solarium_Query_Select_Component_EDisMax Provides fluent interface
*/
public
function
setPhraseBigramFields
(
$phraseBigramFields
)
{
return
$this
->
_setOption
(
'phrasebigramfields'
,
$phraseBigramFields
);
}
/**
* Get PhraseBigramFields option
*
* @return string|null
*/
public
function
getPhraseBigramFields
()
{
return
$this
->
getOption
(
'phrasebigramfields'
);
}
/**
* Set PhraseBigramSlop option
*
* As with 'ps' but sets default slop factor for 'pf2'.
* If not specified, 'ps' will be used.
*
* @param string $phraseBigramSlop
* @return Solarium_Query_Select_Component_EDisMax Provides fluent interface
*/
public
function
setPhraseBigramSlop
(
$phraseBigramSlop
)
{
return
$this
->
_setOption
(
'phrasebigramslop'
,
$phraseBigramSlop
);
}
/**
* Get PhraseBigramSlop option
*
* @return string|null
*/
public
function
getPhraseBigramSlop
()
{
return
$this
->
getOption
(
'phrasebigramslop'
);
}
/**
* Set PhraseFields option
*
* As with 'pf' but chops the input into tri-grams,
* e.g. "the brown fox jumped" is queried as "the brown fox" "brown fox jumped"
*
* Format is: "fieldA^1.0 fieldB^2.2 fieldC^3.5"
*
* @param string $phraseTrigramFields
* @return Solarium_Query_Select_Component_EDisMax Provides fluent interface
*/
public
function
setPhraseTrigramFields
(
$phraseTrigramFields
)
{
return
$this
->
_setOption
(
'phrasetrigramfields'
,
$phraseTrigramFields
);
}
/**
* Get PhraseTrigramFields option
*
* @return string|null
*/
public
function
getPhraseTrigramFields
()
{
return
$this
->
getOption
(
'phrasetrigramfields'
);
}
/**
* Set PhraseTrigramSlop option
*
* As with 'ps' but sets default slop factor for 'pf3'.
* If not specified, 'ps' will be used.
*
* @param string $phraseTrigramSlop
* @return Solarium_Query_Select_Component_EDisMax Provides fluent interface
*/
public
function
setPhraseTrigramSlop
(
$phraseTrigramSlop
)
{
return
$this
->
_setOption
(
'phrasetrigramslop'
,
$phraseTrigramSlop
);
}
/**
* Get PhraseTrigramSlop option
*
* @return string|null
*/
public
function
getPhraseTrigramSlop
()
{
return
$this
->
getOption
(
'phrasetrigramslop'
);
}
/**
* Set UserFields option
*
* Specifies which schema fields the end user shall be allowed to query for explicitly.
* This parameter supports wildcards.
*
* The default is to allow all fields, equivalent to &uf=*.
* To allow only title field, use &uf=title, to allow title and all fields ending with _s, use &uf=title *_s.
* To allow all fields except title, use &uf=* -title. To disallow all fielded searches, use &uf=-*.
* The uf parameter was introduced in Solr3.6
*
* @param string $userFields
* @return Solarium_Query_Select_Component_EDisMax Provides fluent interface
*/
public
function
setUserFields
(
$userFields
)
{
return
$this
->
_setOption
(
'userfields'
,
$userFields
);
}
/**
* Get UserFields option
*
* @return string|null
*/
public
function
getUserFields
()
{
return
$this
->
getOption
(
'userfields'
);
}
}
\ No newline at end of file
library/Solarium/Result/Select/Spellcheck.php
View file @
e83202a2
...
...
@@ -53,11 +53,11 @@ class Solarium_Result_Select_Spellcheck implements IteratorAggregate, Countable
protected
$_suggestions
;
/**
* Collation object
* Collation object
array
*
* @var
Solarium_Result_Select_Spellcheck_Collation
* @var
array
*/
protected
$_collation
;
protected
$_collation
s
;
/**
* Correctly spelled?
...
...
@@ -74,21 +74,42 @@ class Solarium_Result_Select_Spellcheck implements IteratorAggregate, Countable
* @param boolean $correctlySpelled
* @return void
*/
public
function
__construct
(
$suggestions
,
$collation
,
$correctlySpelled
)
public
function
__construct
(
$suggestions
,
$collation
s
,
$correctlySpelled
)
{
$this
->
_suggestions
=
$suggestions
;
$this
->
_collation
=
$collation
;
$this
->
_collation
s
=
$collations
;
$this
->
_correctlySpelled
=
$correctlySpelled
;
}
/**
* Get the collation result
*
* @param int $key
* @return Solarium_Result_Select_Spellcheck_Collation
*/
public
function
getCollation
()
public
function
getCollation
(
$key
=
null
)
{
$nrOfCollations
=
count
(
$this
->
_collations
);
if
(
$nrOfCollations
==
0
)
{
return
null
;
}
else
{
if
(
$key
===
null
)
{
$key
=
$nrOfCollations
-
1
;
// for backwards compatibility
}
return
$this
->
_collations
[
$key
];
}
}
/**
* Get all collations
*
* @return array
*/
public
function
getCollations
()
{
return
$this
->
_collation
;
return
$this
->
_collation
s
;
}
/**
...
...
tests/Solarium/Client/RequestBuilder/Select/Component/EDisMaxTest.php
0 → 100644
View file @
e83202a2
<?php
/**
* Copyright 2012 Marc Morera. 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_RequestBuilder_Select_Component_EDisMaxTest
extends
PHPUnit_Framework_TestCase
{
public
function
testBuildComponent
()
{
$builder
=
new
Solarium_Client_RequestBuilder_Select_Component_EDisMax
;
$request
=
new
Solarium_Client_Request
();
$component
=
new
Solarium_Query_Select_Component_EDisMax
();
$component
->
setQueryParser
(
'dummyparser'
);
$component
->
setQueryAlternative
(
'test'
);
$component
->
setQueryFields
(
'content,name'
);
$component
->
setMinimumMatch
(
'75%'
);
$component
->
setPhraseFields
(
'content,description'
);
$component
->
setPhraseSlop
(
1
);
$component
->
setPhraseBigramFields
(
'content,description,category'
);
$component
->
setPhraseBigramSlop
(
4
);
$component
->
setPhraseTrigramFields
(
'content2,date,subcategory'
);
$component
->
setPhraseTrigramSlop
(
3
);
$component
->
setQueryPhraseSlop
(
2
);
$component
->
setTie
(
0.5
);
$component
->
setBoostQuery
(
'cat:1'
);
$component
->
setBoostFunctions
(
'functionX(price)'
);
$component
->
setBoostFunctionsMult
(
'functionX(date)'
);
$component
->
setUserFields
(
'title *_s'
);
$request
=
$builder
->
buildComponent
(
$component
,
$request
);
$this
->
assertEquals
(
array
(
'defType'
=>
'dummyparser'
,
'q.alt'
=>
'test'
,
'qf'
=>
'content,name'
,
'mm'
=>
'75%'
,
'pf'
=>
'content,description'
,
'ps'
=>
1
,
'pf2'
=>
'content,description,category'
,
'ps2'
=>
4
,
'pf3'
=>
'content2,date,subcategory'
,
'ps3'
=>
3
,
'qs'
=>
2
,
'tie'
=>
0.5
,
'bq'
=>
'cat:1'
,
'bf'
=>
'functionX(price)'
,
'boost'
=>
'functionX(date)'
,
'uf'
=>
'title *_s'
,
),
$request
->
getParams
()
);
}
}
\ No newline at end of file
tests/Solarium/Client/RequestBuilder/SelectTest.php
View file @
e83202a2
...
...
@@ -151,6 +151,17 @@ class Solarium_Client_RequestBuilder_SelectTest extends PHPUnit_Framework_TestCa
);
}
public
function
testWithEdismaxComponent
()
{
$this
->
_query
->
getEDisMax
();
$request
=
$this
->
_builder
->
build
(
$this
->
_query
);
$this
->
assertEquals
(
'edismax'
,
$request
->
getParam
(
'defType'
)
);
}
}
class
TestDummyComponent
extends
Solarium_Query_Select_Component
{
...
...
tests/Solarium/Query/Select/Component/EDisMaxTest.php
0 → 100644
View file @
e83202a2
<?php
/**
* Copyright 2012 Marc Morera. 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_Query_Select_Component_EDisMaxTest
extends
PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Query_Select_Component_EDisMax
*/
protected
$_eDisMax
;
public
function
setUp
()
{
$this
->
_eDisMax
=
new
Solarium_Query_Select_Component_EDisMax
;
}
public
function
testConfigMode
()
{
$options
=
array
(
'queryparser'
=>
'edismax'
,
'queryalternative'
=>
'*:*'
,
'queryfields'
=>
'title^2.0 description'
,
'minimummatch'
=>
'2.0'
,
'phrasefields'
=>
'title^2.0 description^3.5'
,
'phraseslop'
=>
2
,
'phrasebigramfields'
=>
'description^1.3 date^4.3 field_text2^1.3'
,
'phrasebigramslop'
=>
3
,
'phrasetrigramfields'
=>
'datetime^4 field1^5 myotherfield^9'
,
'phrasetrigramslop'
=>
5
,
'queryphraseslop'
=>
4
,
'tie'
=>
2.1
,
'boostquery'
=>
'cat:1^3'
,
'boostfunctions'
=>
'funcA(arg1,arg2)^1.2 funcB(arg3,arg4)^2.2'
,
'boostfunctionsmult'
=>
'funcC(arg5,arg6)^4.3 funcD(arg7,arg8)^3.4'
,
'userfields'
=>
'date *_ul'
,
);
$this
->
_eDisMax
->
setOptions
(
$options
);
$this
->
assertEquals
(
$options
[
'queryparser'
],
$this
->
_eDisMax
->
getQueryParser
());
$this
->
assertEquals
(
$options
[
'queryalternative'
],
$this
->
_eDisMax
->
getQueryAlternative
());
$this
->
assertEquals
(
$options
[
'queryfields'
],
$this
->
_eDisMax
->
getQueryFields
());
$this
->
assertEquals
(
$options
[
'minimummatch'
],
$this
->
_eDisMax
->
getMinimumMatch
());
$this
->
assertEquals
(
$options
[
'phrasefields'
],
$this
->
_eDisMax
->
getPhraseFields
());
$this
->
assertEquals
(
$options
[
'phraseslop'
],
$this
->
_eDisMax
->
getPhraseSlop
());
$this
->
assertEquals
(
$options
[
'phrasebigramfields'
],
$this
->
_eDisMax
->
getPhraseBigramFields
());
$this
->
assertEquals
(
$options
[
'phrasebigramslop'
],
$this
->
_eDisMax
->
getPhraseBigramSlop
());
$this
->
assertEquals
(
$options
[
'phrasetrigramfields'
],
$this
->
_eDisMax
->
getPhraseTrigramFields
());
$this
->
assertEquals
(
$options
[
'phrasetrigramslop'
],
$this
->
_eDisMax
->
getPhraseTrigramSlop
());
$this
->
assertEquals
(
$options
[
'queryphraseslop'
],
$this
->
_eDisMax
->
getQueryPhraseSlop
());
$this
->
assertEquals
(
$options
[
'tie'
],
$this
->
_eDisMax
->
getTie
());
$this
->
assertEquals
(
$options
[
'boostquery'
],
$this
->
_eDisMax
->
getBoostQuery
());
$this
->
assertEquals
(
$options
[
'boostfunctionsmult'
],
$this
->
_eDisMax
->
getBoostFunctionsMult
());
$this
->
assertEquals
(
$options
[
'userfields'
],
$this
->
_eDisMax
->
getUserFields
());
}
public
function
testGetType
()
{
$this
->
assertEquals
(
Solarium_Query_Select
::
COMPONENT_EDISMAX
,
$this
->
_eDisMax
->
getType
()
);
}
public
function
testSetAndGetQueryParser
()
{
$value
=
'dummyparser'
;
$this
->
_eDisMax
->
setQueryParser
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_eDisMax
->
getQueryParser
()
);
}
public
function
testSetAndGetQueryAlternative
()
{
$value
=
'*:*'
;
$this
->
_eDisMax
->
setQueryAlternative
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_eDisMax
->
getQueryAlternative
()
);
}
public
function
testSetAndGetQueryFields
()
{
$value
=
'title^2.0 description'
;
$this
->
_eDisMax
->
setQueryFields
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_eDisMax
->
getQueryFields
()
);
}
public
function
testSetAndGetMinimumMatch
()
{
$value
=
'2.0'
;
$this
->
_eDisMax
->
setMinimumMatch
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_eDisMax
->
getMinimumMatch
()
);
}
public
function
testSetAndGetPhraseFields
()
{
$value
=
'title^2.0 description^3.5'
;
$this
->
_eDisMax
->
setPhraseFields
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_eDisMax
->
getPhraseFields
()
);
}
public
function
testSetAndGetPhraseSlop
()
{
$value
=
'2'
;
$this
->
_eDisMax
->
setPhraseSlop
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_eDisMax
->
getPhraseSlop
()
);
}
public
function
testSetAndGetPhraseBigramFields
()
{
$value
=
'description^1.3 date^4.3 field_text2^1.3'
;
$this
->
_eDisMax
->
setPhraseBigramFields
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_eDisMax
->
getPhraseBigramFields
()
);
}
public
function
testSetAndGetPhraseBigramSlop
()
{
$value
=
3
;
$this
->
_eDisMax
->
setPhraseBigramSlop
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_eDisMax
->
getPhraseBigramSlop
()
);
}
public
function
testSetAndGetPhraseTrigramFields
()
{
$value
=
'datetime^4 field1^5 myotherfield^9'
;
$this
->
_eDisMax
->
setPhraseTrigramFields
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_eDisMax
->
getPhraseTrigramFields
()
);
}
public
function
testSetAndGetPhraseTrigramSlop
()
{
$value
=
5
;
$this
->
_eDisMax
->
setPhraseTrigramSlop
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_eDisMax
->
getPhraseTrigramSlop
()
);
}
public
function
testSetAndGetQueryPhraseSlop
()
{
$value
=
'3'
;
$this
->
_eDisMax
->
setQueryPhraseSlop
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_eDisMax
->
getQueryPhraseSlop
()
);
}
public
function
testSetAndGetTie
()
{
$value
=
2.1
;
$this
->
_eDisMax
->
setTie
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_eDisMax
->
getTie
()
);
}
public
function
testSetAndGetBoostQuery
()
{
$value
=
'cat:1^3'
;
$this
->
_eDisMax
->
setBoostQuery
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_eDisMax
->
getBoostQuery
()
);
}
public
function
testSetAndGetBoostFunctions
()
{
$value
=
'funcA(arg1,arg2)^1.2 funcB(arg3,arg4)^2.2'
;
$this
->
_eDisMax
->
setBoostFunctions
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_eDisMax
->
getBoostFunctions
()
);
}
public
function
testSetAndGetBoostFunctionsMult
()
{
$value
=
'funcC(arg5,arg6)^4.3 funcD(arg7,arg8)^3.4'
;
$this
->
_eDisMax
->
setBoostFunctionsMult
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_eDisMax
->
getBoostFunctionsMult
()
);
}
public
function
testSetAndGetUserFields
()
{
$value
=
'date *_ul'
;
$this
->
_eDisMax
->
setUserFields
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_eDisMax
->
getUserFields
()
);
}
}
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