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
a41cc287
Commit
a41cc287
authored
Apr 27, 2011
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- added highlighting component
- added select helper - added new unittests
parent
aca37f29
Changes
13
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
1411 additions
and
1 deletion
+1411
-1
library/Solarium/Client/Request/Select.php
library/Solarium/Client/Request/Select.php
+36
-0
library/Solarium/Client/Response/Select.php
library/Solarium/Client/Response/Select.php
+26
-0
library/Solarium/Query/Select.php
library/Solarium/Query/Select.php
+37
-0
library/Solarium/Query/Select/Component.php
library/Solarium/Query/Select/Component.php
+1
-0
library/Solarium/Query/Select/Component/Highlighting.php
library/Solarium/Query/Select/Component/Highlighting.php
+503
-0
library/Solarium/Query/Select/Component/MoreLikeThis.php
library/Solarium/Query/Select/Component/MoreLikeThis.php
+1
-1
library/Solarium/Query/Select/Helper.php
library/Solarium/Query/Select/Helper.php
+179
-0
library/Solarium/Result/Select.php
library/Solarium/Result/Select.php
+12
-0
library/Solarium/Result/Select/Highlighting.php
library/Solarium/Result/Select/Highlighting.php
+109
-0
library/Solarium/Result/Select/Highlighting/Result.php
library/Solarium/Result/Select/Highlighting/Result.php
+108
-0
tests/Solarium/Query/Select/Component/HighlightingTest.php
tests/Solarium/Query/Select/Component/HighlightingTest.php
+266
-0
tests/Solarium/Query/Select/HelperTest.php
tests/Solarium/Query/Select/HelperTest.php
+123
-0
tests/Solarium/Query/SelectTest.php
tests/Solarium/Query/SelectTest.php
+10
-0
No files found.
library/Solarium/Client/Request/Select.php
View file @
a41cc287
...
@@ -93,6 +93,9 @@ class Solarium_Client_Request_Select extends Solarium_Client_Request
...
@@ -93,6 +93,9 @@ class Solarium_Client_Request_Select extends Solarium_Client_Request
case
Solarium_Query_Select_Component
::
DISMAX
:
case
Solarium_Query_Select_Component
::
DISMAX
:
$this
->
addDisMax
(
$component
);
$this
->
addDisMax
(
$component
);
break
;
break
;
case
Solarium_Query_Select_Component
::
HIGHLIGHTING
:
$this
->
addHighlighting
(
$component
);
break
;
default
:
default
:
throw
new
Solarium_Exception
(
'Unknown component type'
);
throw
new
Solarium_Exception
(
'Unknown component type'
);
}
}
...
@@ -279,4 +282,37 @@ class Solarium_Client_Request_Select extends Solarium_Client_Request
...
@@ -279,4 +282,37 @@ class Solarium_Client_Request_Select extends Solarium_Client_Request
$this
->
addParam
(
'bf'
,
$component
->
getBoostFunctions
());
$this
->
addParam
(
'bf'
,
$component
->
getBoostFunctions
());
}
}
/**
* Add params for highlighting
*
* @param Solarium_Query_Select_Component_Highlighting $component
* @return void
*/
public
function
addHighlighting
(
$component
)
{
// enable highlighting
$this
->
_params
[
'hl'
]
=
'true'
;
$this
->
addParam
(
'hl.fl'
,
$component
->
getFields
());
$this
->
addParam
(
'hl.snippets'
,
$component
->
getSnippets
());
$this
->
addParam
(
'hl.fragsize'
,
$component
->
getFragSize
());
$this
->
addParam
(
'hl.mergeContiguous'
,
$component
->
getMergeContiguous
());
$this
->
addParam
(
'hl.requireFieldMatch'
,
$component
->
getRequireFieldMatch
());
$this
->
addParam
(
'hl.maxAnalyzedChars'
,
$component
->
getMaxAnalyzedChars
());
$this
->
addParam
(
'hl.alternateField'
,
$component
->
getAlternateField
());
$this
->
addParam
(
'hl.maxAlternateFieldLength'
,
$component
->
getMaxAlternateFieldLength
());
$this
->
addParam
(
'hl.formatter'
,
$component
->
getFormatter
());
$this
->
addParam
(
'hl.simple.pre'
,
$component
->
getSimplePrefix
());
$this
->
addParam
(
'hl.simple.post'
,
$component
->
getSimplePostfix
());
$this
->
addParam
(
'hl.fragmenter'
,
$component
->
getFragmenter
());
$this
->
addParam
(
'hl.fragListBuilder'
,
$component
->
getFragListBuilder
());
$this
->
addParam
(
'hl.fragmentsBuilder'
,
$component
->
getFragmentsBuilder
());
$this
->
addParam
(
'hl.useFastVectorHighlighter'
,
$component
->
getUseFastVectorHighlighter
());
$this
->
addParam
(
'hl.usePhraseHighlighter'
,
$component
->
getUsePhraseHighlighter
());
$this
->
addParam
(
'hl.highlightMultiTerm'
,
$component
->
getHighlightMultiTerm
());
$this
->
addParam
(
'hl.regex.slop'
,
$component
->
getRegexSlop
());
$this
->
addParam
(
'hl.regex.pattern'
,
$component
->
getRegexPattern
());
$this
->
addParam
(
'hl.regex.maxAnalyzedChars'
,
$component
->
getRegexMaxAnalyzedChars
());
}
}
}
\ No newline at end of file
library/Solarium/Client/Response/Select.php
View file @
a41cc287
...
@@ -95,6 +95,9 @@ class Solarium_Client_Response_Select extends Solarium_Client_Response
...
@@ -95,6 +95,9 @@ class Solarium_Client_Response_Select extends Solarium_Client_Response
case
Solarium_Query_Select_Component
::
DISMAX
:
case
Solarium_Query_Select_Component
::
DISMAX
:
// no result action needed
// no result action needed
break
;
break
;
case
Solarium_Query_Select_Component
::
HIGHLIGHTING
:
$this
->
_addHighlighting
(
$component
);
break
;
default
:
default
:
throw
new
Solarium_Exception
(
'Unknown component type'
);
throw
new
Solarium_Exception
(
'Unknown component type'
);
}
}
...
@@ -257,4 +260,27 @@ class Solarium_Client_Response_Select extends Solarium_Client_Response
...
@@ -257,4 +260,27 @@ class Solarium_Client_Response_Select extends Solarium_Client_Response
$this
->
_components
[
$component
->
getType
()]
=
$moreLikeThis
;
$this
->
_components
[
$component
->
getType
()]
=
$moreLikeThis
;
}
}
/**
* Add highlighting result
*
* @param Solarium_Query_Select_Component_Highlighting $component
* @return void
*/
protected
function
_addHighlighting
(
$component
)
{
$results
=
array
();
if
(
isset
(
$this
->
_data
[
'highlighting'
]))
{
$highlightResults
=
$this
->
_data
[
'highlighting'
];
foreach
(
$highlightResults
AS
$key
=>
$result
)
{
$results
[
$key
]
=
new
Solarium_Result_Select_Highlighting_Result
(
$result
);
}
}
$highlighting
=
new
Solarium_Result_Select_Highlighting
(
$results
);
$this
->
_components
[
$component
->
getType
()]
=
$highlighting
;
}
}
}
\ No newline at end of file
library/Solarium/Query/Select.php
View file @
a41cc287
...
@@ -97,6 +97,13 @@ class Solarium_Query_Select extends Solarium_Query
...
@@ -97,6 +97,13 @@ class Solarium_Query_Select extends Solarium_Query
*/
*/
protected
$_components
=
array
();
protected
$_components
=
array
();
/**
* Helper instance
*
* @var Solarium_Query_Select_Helper
*/
protected
$_helper
;
/**
/**
* Initialize options
* Initialize options
*
*
...
@@ -568,6 +575,9 @@ class Solarium_Query_Select extends Solarium_Query
...
@@ -568,6 +575,9 @@ class Solarium_Query_Select extends Solarium_Query
case
Solarium_Query_Select_Component
::
DISMAX
:
case
Solarium_Query_Select_Component
::
DISMAX
:
$className
=
'Solarium_Query_Select_Component_DisMax'
;
$className
=
'Solarium_Query_Select_Component_DisMax'
;
break
;
break
;
case
Solarium_Query_Select_Component
::
HIGHLIGHTING
:
$className
=
'Solarium_Query_Select_Component_Highlighting'
;
break
;
default
:
default
:
throw
new
Solarium_Exception
(
'Cannot autoload unknown component: '
.
$key
);
throw
new
Solarium_Exception
(
'Cannot autoload unknown component: '
.
$key
);
}
}
...
@@ -659,4 +669,31 @@ class Solarium_Query_Select extends Solarium_Query
...
@@ -659,4 +669,31 @@ class Solarium_Query_Select extends Solarium_Query
return
$this
->
getComponent
(
Solarium_Query_Select_Component
::
DISMAX
,
true
);
return
$this
->
getComponent
(
Solarium_Query_Select_Component
::
DISMAX
,
true
);
}
}
/**
* Get a highlighting component instance
*
* This is a convenience method that maps presets to getComponent
*
* @return Solarium_Query_Select_Component_Highlighting
*/
public
function
getHighlighting
()
{
return
$this
->
getComponent
(
Solarium_Query_Select_Component
::
HIGHLIGHTING
,
true
);
}
/**
* Get a helper instance
*
* Uses lazy loading: the helper is instantiated on first use
*
* @return Solarium_Query_Select_Helper
*/
public
function
getHelper
()
{
if
(
null
===
$this
->
_helper
)
{
$this
->
_helper
=
new
Solarium_Query_Select_Helper
;
}
return
$this
->
_helper
;
}
}
}
\ No newline at end of file
library/Solarium/Query/Select/Component.php
View file @
a41cc287
...
@@ -50,6 +50,7 @@ class Solarium_Query_Select_Component extends Solarium_Configurable
...
@@ -50,6 +50,7 @@ class Solarium_Query_Select_Component extends Solarium_Configurable
const
MORELIKETHIS
=
'morelikethis'
;
const
MORELIKETHIS
=
'morelikethis'
;
const
FACETSET
=
'facetset'
;
const
FACETSET
=
'facetset'
;
const
DISMAX
=
'dismax'
;
const
DISMAX
=
'dismax'
;
const
HIGHLIGHTING
=
'highlighting'
;
/**
/**
* Component type
* Component type
...
...
library/Solarium/Query/Select/Component/Highlighting.php
0 → 100644
View file @
a41cc287
This diff is collapsed.
Click to expand it.
library/Solarium/Query/Select/Component/MoreLikeThis.php
View file @
a41cc287
...
@@ -58,7 +58,7 @@ class Solarium_Query_Select_Component_MoreLikeThis extends Solarium_Query_Select
...
@@ -58,7 +58,7 @@ class Solarium_Query_Select_Component_MoreLikeThis extends Solarium_Query_Select
*
*
* The fields to use for similarity. NOTE: if possible, these should have a
* The fields to use for similarity. NOTE: if possible, these should have a
* stored TermVector
* stored TermVector
*
*
* Separate multiple fields with commas.
* Separate multiple fields with commas.
*
*
* @param string $fields
* @param string $fields
...
...
library/Solarium/Query/Select/Helper.php
0 → 100644
View file @
a41cc287
<?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.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @package Solarium
* @subpackage Query
*/
/**
* Select query helper
*
* Generates small snippets for use in queries, filterqueries and sorting
*
* @package Solarium
* @subpackage Query
*/
class
Solarium_Query_Select_Helper
{
/**
* Render a range query
*
* From and to can be any type of data. For instance int, string or point.
*
* Example: rangeQuery('store', '45,-94', '46,-93')
* Returns: store:[45,-94 TO 46,-93]
*
* @static
* @param string $field
* @param string $from
* @param string $to
* @param boolean $inclusive
* @return string
*/
public
function
rangeQuery
(
$field
,
$from
,
$to
,
$inclusive
=
true
)
{
if
(
$inclusive
)
{
return
$field
.
':['
.
$from
.
' TO '
.
$to
.
']'
;
}
else
{
return
$field
.
':{'
.
$from
.
' TO '
.
$to
.
'}'
;
}
}
/**
* Render a geofilt (distance) filter
*
* Find all entries within the distance of a certain point.
*
* @static
* @param $pointX
* @param $pointY
* @param $field
* @param $distance
* @return string
*/
public
function
geofilt
(
$pointX
,
$pointY
,
$field
,
$distance
)
{
return
$this
->
qparser
(
'geofilt'
,
array
(
'pt'
=>
$pointX
.
','
.
$pointY
,
'sfield'
=>
$field
,
'd'
=>
$distance
)
);
}
/**
* Render a bbox (boundingbox) filter
*
* Exact distance calculations can be somewhat expensive and it can often
* make sense to use a quick approximation instead. The bbox filter is
* guaranteed to encompass all of the points of interest, but it may also
* include other points that are slightly outside of the required distance.
*
* @static
* @param string $pointX
* @param string $pointY
* @param string $field
* @param string $distance
* @return string
*/
public
function
bbox
(
$pointX
,
$pointY
,
$field
,
$distance
)
{
return
$this
->
qparser
(
'bbox'
,
array
(
'pt'
=>
$pointX
.
','
.
$pointY
,
'sfield'
=>
$field
,
'd'
=>
$distance
)
);
}
/**
* Render a geodist function call
*
* geodist is a function query that yields the calculated distance.
* This gives the flexibility to do a number of interesting things,
* such as sorting by the distance (Solr can sort by any function query),
* or combining the distance with the relevancy score,
* such as boosting by the inverse of the distance.
*
* @static
* @param $pointX
* @param $pointY
* @param $field
* @return string
*/
public
function
geodist
(
$pointX
,
$pointY
,
$field
)
{
return
$this
->
functionCall
(
'geodist'
,
array
(
$pointX
,
$pointY
,
$field
)
);
}
/**
* Render a qparser plugin call
*
* @static
* @param string $name
* @param array $params
* @return string
*/
public
function
qparser
(
$name
,
$params
=
array
())
{
$output
=
'{!'
.
$name
;
foreach
(
$params
AS
$key
=>
$value
)
{
$output
.=
' '
.
$key
.
'='
.
$value
;
}
$output
.=
'}'
;
return
$output
;
}
/**
* Render a functionCall
*
* @static
* @param string $name
* @param array $params
* @return string
*/
public
function
functionCall
(
$name
,
$params
=
array
())
{
return
$name
.
'('
.
implode
(
$params
,
','
)
.
')'
;
}
}
\ No newline at end of file
library/Solarium/Result/Select.php
View file @
a41cc287
...
@@ -219,4 +219,16 @@ class Solarium_Result_Select extends Solarium_Result_Query
...
@@ -219,4 +219,16 @@ class Solarium_Result_Select extends Solarium_Result_Query
{
{
return
$this
->
getComponent
(
Solarium_Query_Select_Component
::
MORELIKETHIS
);
return
$this
->
getComponent
(
Solarium_Query_Select_Component
::
MORELIKETHIS
);
}
}
/**
* Get highlighting component result
*
* This is a convenience method that maps presets to getComponent
*
* @return Solarium_Result_Select_Component_Highlighting
*/
public
function
getHighlighting
()
{
return
$this
->
getComponent
(
Solarium_Query_Select_Component
::
HIGHLIGHTING
);
}
}
}
\ No newline at end of file
library/Solarium/Result/Select/Highlighting.php
0 → 100644
View file @
a41cc287
<?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.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @package Solarium
* @subpackage Result
*/
/**
* Select component highlighting result
*
* @package Solarium
* @subpackage Result
*/
class
Solarium_Result_Select_Highlighting
implements
IteratorAggregate
,
Countable
{
/**
* Result array
*
* @var array
*/
protected
$_results
;
/**
* Constructor
*
* @param array $results
* @return void
*/
public
function
__construct
(
$results
)
{
$this
->
_results
=
$results
;
}
/**
* Get a result by key
*
* @param mixed $key
* @return Solarium_Result_Select_Highlighting_Result|null
*/
public
function
getResult
(
$key
)
{
if
(
isset
(
$this
->
_results
[
$key
]))
{
return
$this
->
_results
[
$key
];
}
else
{
return
null
;
}
}
/**
* Get all results
*
* @return array
*/
public
function
getResults
()
{
return
$this
->
_results
;
}
/**
* IteratorAggregate implementation
*
* @return ArrayIterator
*/
public
function
getIterator
()
{
return
new
ArrayIterator
(
$this
->
_results
);
}
/**
* Countable implementation
*
* @return int
*/
public
function
count
()
{
return
count
(
$this
->
_results
);
}
}
\ No newline at end of file
library/Solarium/Result/Select/Highlighting/Result.php
0 → 100644
View file @
a41cc287
<?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.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @package Solarium
* @subpackage Result
*/
/**
* Select component highlighting result item
*
* @package Solarium
* @subpackage Result
*/
class
Solarium_Result_Select_Highlighting_Result
implements
IteratorAggregate
,
Countable
{
/**
* Fields array
*
* @var array
*/
protected
$_fields
;
/**
* Constructor
*
* @param array $fields
* @return void
*/
public
function
__construct
(
$fields
)
{
$this
->
_fields
=
$fields
;
}
/**
* Get highlights for all fields
*
* @return array
*/
public
function
getFields
()
{
return
$this
->
_fields
;
}
/**
* Get highlights for a single field
*
* @return array
*/
public
function
getField
(
$key
)
{
if
(
isset
(
$this
->
_fields
[
$key
]))
{
return
$this
->
_fields
[
$key
];
}
else
{
return
array
();
}
}
/**
* IteratorAggregate implementation
*
* @return ArrayIterator
*/
public
function
getIterator
()
{
return
new
ArrayIterator
(
$this
->
_fields
);
}
/**
* Countable implementation
*
* @return int
*/
public
function
count
()
{
return
count
(
$this
->
_fields
);
}
}
\ No newline at end of file
tests/Solarium/Query/Select/Component/HighlightingTest.php
0 → 100644
View file @
a41cc287
<?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_Query_Select_Component_HighlightingTest
extends
PHPUnit_Framework_TestCase
{
protected
$_hlt
;
public
function
setUp
()
{
$this
->
_hlt
=
new
Solarium_Query_Select_Component_Highlighting
;
}
public
function
testGetType
()
{
$this
->
assertEquals
(
Solarium_Query_Select_Component
::
HIGHLIGHTING
,
$this
->
_hlt
->
getType
());
}
public
function
testSetAndGetFields
()
{
$value
=
'name,description'
;
$this
->
_hlt
->
setFields
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_hlt
->
getFields
()
);
}
public
function
testSetAndGetSnippets
()
{
$value
=
2
;
$this
->
_hlt
->
setSnippets
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_hlt
->
getSnippets
()
);
}
public
function
testSetAndGetFragSize
()
{
$value
=
20
;
$this
->
_hlt
->
setFragsize
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_hlt
->
getFragSize
()
);
}
public
function
testSetAndGetMergeContiguous
()
{
$value
=
true
;
$this
->
_hlt
->
setMergeContiguous
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_hlt
->
getMergeContiguous
()
);
}
public
function
testSetAndGetRequireFieldMatch
()
{
$value
=
true
;
$this
->
_hlt
->
setRequireFieldMatch
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_hlt
->
getRequireFieldMatch
()
);
}
public
function
testSetAndGetMaxAnalyzedChars
()
{
$value
=
200
;
$this
->
_hlt
->
setMaxAnalyzedChars
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_hlt
->
getMaxAnalyzedChars
()
);
}
public
function
testSetAndGetAlternateField
()
{
$value
=
'description'
;
$this
->
_hlt
->
setAlternateField
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_hlt
->
getAlternateField
()
);
}
public
function
testSetAndGetMaxAlternateFieldLength
()
{
$value
=
150
;
$this
->
_hlt
->
setMaxAlternateFieldLength
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_hlt
->
getMaxAlternateFieldLength
()
);
}
public
function
testSetAndGetFormatter
()
{
$this
->
_hlt
->
setFormatter
();
$this
->
assertEquals
(
'simple'
,
$this
->
_hlt
->
getFormatter
()
);
}
public
function
testSetAndGetSimplePrefix
()
{
$value
=
'<em>'
;
$this
->
_hlt
->
setSimplePrefix
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_hlt
->
getSimplePrefix
()
);
}
public
function
testSetAndGetSimplePostfix
()
{
$value
=
'</em>'
;
$this
->
_hlt
->
setSimplePostfix
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_hlt
->
getSimplePostfix
()
);
}
public
function
testSetAndGetFragmenter
()
{
$value
=
Solarium_Query_Select_Component_Highlighting
::
FRAGMENTER_REGEX
;
$this
->
_hlt
->
setFragmenter
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_hlt
->
getFragmenter
()
);
}
public
function
testSetAndGetFragListBuilder
()
{
$value
=
'myBuilder'
;
$this
->
_hlt
->
setFragListBuilder
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_hlt
->
getFragListBuilder
()
);
}
public
function
testSetAndGetFragmentsBuilder
()
{
$value
=
'myBuilder'
;
$this
->
_hlt
->
setFragmentsBuilder
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_hlt
->
getFragmentsBuilder
()
);
}
public
function
testSetAndGetUseFastVectorHighlighter
()
{
$value
=
true
;
$this
->
_hlt
->
setUseFastVectorHighlighter
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_hlt
->
getUseFastVectorHighlighter
()
);
}
public
function
testSetAndGetUsePhraseHighlighter
()
{
$value
=
true
;
$this
->
_hlt
->
setUsePhraseHighlighter
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_hlt
->
getUsePhraseHighlighter
()
);
}
public
function
testSetAndGetHighlightMultiTerm
()
{
$value
=
true
;
$this
->
_hlt
->
setHighlightMultiTerm
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_hlt
->
getHighlightMultiTerm
()
);
}
public
function
testSetAndGetRegexSlop
()
{
$value
=
.
8
;
$this
->
_hlt
->
setRegexSlop
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_hlt
->
getRegexSlop
()
);
}
public
function
testSetAndGetRegexPattern
()
{
$value
=
'myPattern'
;
$this
->
_hlt
->
setRegexPattern
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_hlt
->
getRegexPattern
()
);
}
public
function
testSetAndGetRegexMaxAnalyzedChars
()
{
$value
=
500
;
$this
->
_hlt
->
setRegexMaxAnalyzedChars
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_hlt
->
getRegexMaxAnalyzedChars
()
);
}
}
tests/Solarium/Query/Select/HelperTest.php
0 → 100644
View file @
a41cc287
<?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_Query_Select_HelperTest
extends
PHPUnit_Framework_TestCase
{
protected
$_helper
;
public
function
setUp
()
{
$this
->
_helper
=
new
Solarium_Query_Select_Helper
;
}
public
function
testRangeQueryInclusive
()
{
$this
->
assertEquals
(
'field:[1 TO 2]'
,
$this
->
_helper
->
rangeQuery
(
'field'
,
1
,
2
)
);
$this
->
assertEquals
(
'store:[45,-94 TO 46,-93]'
,
$this
->
_helper
->
rangeQuery
(
'store'
,
'45,-94'
,
'46,-93'
)
);
}
public
function
testRangeQueryExclusive
()
{
$this
->
assertEquals
(
'field:{1 TO 2}'
,
$this
->
_helper
->
rangeQuery
(
'field'
,
1
,
2
,
false
)
);
$this
->
assertEquals
(
'store:{45,-94 TO 46,-93}'
,
$this
->
_helper
->
rangeQuery
(
'store'
,
'45,-94'
,
'46,-93'
,
false
)
);
}
public
function
testGeofilt
()
{
$this
->
assertEquals
(
'{!geofilt pt=45.15,-93.85 sfield=store d=5}'
,
$this
->
_helper
->
geofilt
(
45.15
,
-
93.85
,
'store'
,
5
)
);
}
public
function
testBbox
()
{
$this
->
assertEquals
(
'{!bbox pt=45.15,-93.85 sfield=store d=5}'
,
$this
->
_helper
->
bbox
(
45.15
,
-
93.85
,
'store'
,
5
)
);
}
public
function
testGeodist
()
{
$this
->
assertEquals
(
'geodist(45.15,-93.85,store)'
,
$this
->
_helper
->
geodist
(
45.15
,
-
93.85
,
'store'
)
);
}
public
function
testQparserNoParams
()
{
$this
->
assertEquals
(
'{!parser}'
,
$this
->
_helper
->
qparser
(
'parser'
)
);
}
public
function
testQparser
()
{
$this
->
assertEquals
(
'{!parser a=1 b=test}'
,
$this
->
_helper
->
qparser
(
'parser'
,
array
(
'a'
=>
1
,
'b'
=>
'test'
))
);
}
public
function
testFunctionCallNoParams
()
{
$this
->
assertEquals
(
'sum()'
,
$this
->
_helper
->
functionCall
(
'sum'
)
);
}
public
function
testFunctionCall
()
{
$this
->
assertEquals
(
'sum(1,2)'
,
$this
->
_helper
->
functionCall
(
'sum'
,
array
(
1
,
2
))
);
}
}
tests/Solarium/Query/SelectTest.php
View file @
a41cc287
...
@@ -478,4 +478,14 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase
...
@@ -478,4 +478,14 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase
get_class
(
$dismax
)
get_class
(
$dismax
)
);
);
}
}
public
function
testGetHelper
()
{
$helper
=
$this
->
_query
->
getHelper
();
$this
->
assertEquals
(
'Solarium_Query_Select_Helper'
,
get_class
(
$helper
)
);
}
}
}
\ 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