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
daec42c3
Commit
daec42c3
authored
Jul 22, 2011
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added edismax support, including unittests and examples
parent
ef470657
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
95 additions
and
4 deletions
+95
-4
examples/2.5.5-edismax.php
examples/2.5.5-edismax.php
+44
-0
examples/2.5.6-grouping-by-field.php
examples/2.5.6-grouping-by-field.php
+0
-0
examples/2.5.7-grouping-by-query.php
examples/2.5.7-grouping-by-query.php
+0
-0
examples/index.html
examples/index.html
+3
-2
library/Solarium/Client/RequestBuilder/Select/Component/DisMax.php
...olarium/Client/RequestBuilder/Select/Component/DisMax.php
+1
-1
library/Solarium/Query/Select/Component/DisMax.php
library/Solarium/Query/Select/Component/DisMax.php
+32
-0
tests/Solarium/Client/RequestBuilder/Select/Component/DisMaxTest.php
...ium/Client/RequestBuilder/Select/Component/DisMaxTest.php
+2
-1
tests/Solarium/Query/Select/Component/DisMaxTest.php
tests/Solarium/Query/Select/Component/DisMaxTest.php
+13
-0
No files found.
examples/2.5.5-edismax.php
0 → 100644
View file @
daec42c3
<?php
require
(
'init.php'
);
htmlHeader
();
// create a client instance
$client
=
new
Solarium_Client
(
$config
);
// get a select query instance
$query
=
$client
->
createSelect
();
// get the dismax component and set a boost query
$dismax
=
$query
->
getDisMax
();
// override the default setting of 'dismax' to enable 'edismax'
$dismax
->
setQueryParser
(
'edismax'
);
// this query is now a dismax query
$query
->
setQuery
(
'memory -printer'
);
// this executes the query and returns the result
$resultset
=
$client
->
select
(
$query
);
// display the total number of documents found by solr
echo
'NumFound: '
.
$resultset
->
getNumFound
();
// show documents using the resultset iterator
foreach
(
$resultset
as
$document
)
{
echo
'<hr/><table>'
;
// the documents are also iterable, to get all fields
foreach
(
$document
AS
$field
=>
$value
)
{
// this converts multivalue fields to a comma-separated string
if
(
is_array
(
$value
))
$value
=
implode
(
', '
,
$value
);
echo
'<tr><th>'
.
$field
.
'</th><td>'
.
$value
.
'</td></tr>'
;
}
echo
'</table>'
;
}
htmlFooter
();
\ No newline at end of file
examples/2.5.
5
-grouping-by-field.php
→
examples/2.5.
6
-grouping-by-field.php
View file @
daec42c3
File moved
examples/2.5.
6
-grouping-by-query.php
→
examples/2.5.
7
-grouping-by-query.php
View file @
daec42c3
File moved
examples/index.html
View file @
daec42c3
...
...
@@ -43,8 +43,9 @@
<li><a
href=
"2.5.2-morelikethis.php"
>
2.5.2 MoreLikeThis
</a></li>
<li><a
href=
"2.5.3-highlighting.php"
>
2.5.3 Highlighting
</a></li>
<li><a
href=
"2.5.4-dismax.php"
>
2.5.4 Dismax
</a></li>
<li><a
href=
"2.5.5-grouping-by-field.php"
>
2.5.5 Grouping by field
</a></li>
<li><a
href=
"2.5.6-grouping-by-query.php"
>
2.5.6 Grouping by query
</a></li>
<li><a
href=
"2.5.5-edismax.php"
>
2.5.5 Edismax
</a></li>
<li><a
href=
"2.5.6-grouping-by-field.php"
>
2.5.5 Grouping by field
</a></li>
<li><a
href=
"2.5.7-grouping-by-query.php"
>
2.5.6 Grouping by query
</a></li>
</ul>
<li><a
href=
"2.6-helper-functions.php"
>
2.6 Helper functions
</a></li>
<li><a
href=
"2.7-query-reuse.php"
>
2.7 Query re-use
</a></li>
...
...
library/Solarium/Client/RequestBuilder/Select/Component/DisMax.php
View file @
daec42c3
...
...
@@ -55,7 +55,7 @@ class Solarium_Client_RequestBuilder_Select_Component_DisMax
public
function
build
(
$component
,
$request
)
{
// enable dismax
$request
->
addParam
(
'defType'
,
'dismax'
);
$request
->
addParam
(
'defType'
,
$component
->
getQueryParser
()
);
$request
->
addParam
(
'q.alt'
,
$component
->
getQueryAlternative
());
$request
->
addParam
(
'qf'
,
$component
->
getQueryFields
());
...
...
library/Solarium/Query/Select/Component/DisMax.php
View file @
daec42c3
...
...
@@ -54,6 +54,15 @@ class Solarium_Query_Select_Component_DisMax extends Solarium_Query_Select_Compo
*/
protected
$_type
=
Solarium_Query_Select
::
COMPONENT_DISMAX
;
/**
* Default options
*
* @var array
*/
protected
$_options
=
array
(
'queryparser'
=>
'dismax'
,
);
/**
* Set QueryAlternative option
*
...
...
@@ -276,4 +285,27 @@ class Solarium_Query_Select_Component_DisMax extends Solarium_Query_Select_Compo
return
$this
->
getOption
(
'boostfunctions'
);
}
/**
* Set QueryParser option
*
* Can be used to enable edismax
*
* @param string $parser
* @return Solarium_Query_Select_Component_DisMax Provides fluent interface
*/
public
function
setQueryParser
(
$parser
)
{
return
$this
->
_setOption
(
'queryparser'
,
$parser
);
}
/**
* Get QueryParser option
*
* @return string
*/
public
function
getQueryParser
()
{
return
$this
->
getOption
(
'queryparser'
);
}
}
\ No newline at end of file
tests/Solarium/Client/RequestBuilder/Select/Component/DisMaxTest.php
View file @
daec42c3
...
...
@@ -38,6 +38,7 @@ class Solarium_Client_RequestBuilder_Select_Component_DisMaxTest extends PHPUnit
$request
=
new
Solarium_Client_Request
();
$component
=
new
Solarium_Query_Select_Component_DisMax
();
$component
->
setQueryParser
(
'dummyparser'
);
$component
->
setQueryAlternative
(
'test'
);
$component
->
setQueryFields
(
'content,name'
);
$component
->
setMinimumMatch
(
'75%'
);
...
...
@@ -52,7 +53,7 @@ class Solarium_Client_RequestBuilder_Select_Component_DisMaxTest extends PHPUnit
$this
->
assertEquals
(
array
(
'defType'
=>
'd
ismax
'
,
'defType'
=>
'd
ummyparser
'
,
'q.alt'
=>
'test'
,
'qf'
=>
'content,name'
,
'mm'
=>
'75%'
,
...
...
tests/Solarium/Query/Select/Component/DisMaxTest.php
View file @
daec42c3
...
...
@@ -45,6 +45,7 @@ class Solarium_Query_Select_Component_DisMaxTest extends PHPUnit_Framework_TestC
public
function
testConfigMode
()
{
$options
=
array
(
'queryparser'
=>
'edismax'
,
'queryalternative'
=>
'*:*'
,
'queryfields'
=>
'title^2.0 description'
,
'minimummatch'
=>
'2.0'
,
...
...
@@ -58,6 +59,7 @@ class Solarium_Query_Select_Component_DisMaxTest extends PHPUnit_Framework_TestC
$this
->
_disMax
->
setOptions
(
$options
);
$this
->
assertEquals
(
$options
[
'queryparser'
],
$this
->
_disMax
->
getQueryParser
());
$this
->
assertEquals
(
$options
[
'queryalternative'
],
$this
->
_disMax
->
getQueryAlternative
());
$this
->
assertEquals
(
$options
[
'queryfields'
],
$this
->
_disMax
->
getQueryFields
());
$this
->
assertEquals
(
$options
[
'minimummatch'
],
$this
->
_disMax
->
getMinimumMatch
());
...
...
@@ -77,6 +79,17 @@ class Solarium_Query_Select_Component_DisMaxTest extends PHPUnit_Framework_TestC
);
}
public
function
testSetAndGetQueryParser
()
{
$value
=
'dummyparser'
;
$this
->
_disMax
->
setQueryParser
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_disMax
->
getQueryParser
()
);
}
public
function
testSetAndGetQueryAlternative
()
{
$value
=
'*:*'
;
...
...
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