Skip to content
Snippets Groups Projects
Commit 629f335b authored by Demian Katz's avatar Demian Katz
Browse files

Use different default mm for edismax vs. dismax.

- Resolves problem with edismax OR searches failing; thanks to Greg Pendlebury for input.
- See VUFIND-935 for more history.
parent 2e8789cc
No related merge requests found
...@@ -88,6 +88,8 @@ class SearchHandler ...@@ -88,6 +88,8 @@ class SearchHandler
if (empty($this->specs['DismaxHandler'])) { if (empty($this->specs['DismaxHandler'])) {
$this->specs['DismaxHandler'] = $defaultDismaxHandler; $this->specs['DismaxHandler'] = $defaultDismaxHandler;
} }
// Set default mm handler if necessary:
$this->setDefaultMustMatch();
} }
/// Public API /// Public API
...@@ -248,6 +250,44 @@ class SearchHandler ...@@ -248,6 +250,44 @@ class SearchHandler
/// Internal API /// Internal API
/**
* Support method for constructor: if no mm is provided, set a reasonable
* default based on the selected Dismax handler.
*
* @return void
*/
protected function setDefaultMustMatch()
{
// Initialize parameter array if absent:
if (!isset($this->specs['DismaxParams'])) {
$this->specs['DismaxParams'] = [];
}
// Add mm if applicable:
if ($this->hasDismax()) {
// Our default mm depends on whether we're using dismax or edismax;
// for dismax, we want 100% matches, because we always want to
// simulate "AND" behavior by default (any "OR" searches will get
// rerouted to Lucene queries). For edismax, boolean operators are
// accounted for, and with an mm of 100%, OR searches will always
// fail. We can use 0% here, because the default q.op of AND will
// make AND searches work correctly even without a high mm value.
$default = $this->hasExtendedDismax() ? '0%' : '100%';
// Now if the configuration has no explicit mm value, let's push in
// our default:
$foundSetting = false;
foreach ($this->specs['DismaxParams'] as $current) {
if ($current[0] == 'mm') {
$foundSetting = true;
break;
}
}
if (!$foundSetting) {
$this->specs['DismaxParams'][] = ['mm', $default];
}
}
}
/** /**
* Return a Dismax subquery for specified search string. * Return a Dismax subquery for specified search string.
* *
......
...@@ -302,7 +302,7 @@ class QueryBuilderTest extends \VuFindTest\Unit\TestCase ...@@ -302,7 +302,7 @@ class QueryBuilderTest extends \VuFindTest\Unit\TestCase
$response = $qb->build($q); $response = $qb->build($q);
$processedQ = $response->get('q'); $processedQ = $response->get('q');
$this->assertEquals('((_query_:"{!dismax qf=\"field_a\" }value1") OR (_query_:"{!dismax qf=\"field_b\" }value2"))', $processedQ[0]); $this->assertEquals('((_query_:"{!dismax qf=\"field_a\" mm=\\\'100%\\\'}value1") OR (_query_:"{!dismax qf=\"field_b\" mm=\\\'100%\\\'}value2"))', $processedQ[0]);
} }
/** /**
...@@ -333,7 +333,7 @@ class QueryBuilderTest extends \VuFindTest\Unit\TestCase ...@@ -333,7 +333,7 @@ class QueryBuilderTest extends \VuFindTest\Unit\TestCase
$response = $qb->build($q); $response = $qb->build($q);
$processedQ = $response->get('q'); $processedQ = $response->get('q');
$this->assertEquals('((field_a:(value*)^100 OR field_c:(value*)^200) OR (_query_:"{!dismax qf=\"field_b\" }value2"))', $processedQ[0]); $this->assertEquals('((field_a:(value*)^100 OR field_c:(value*)^200) OR (_query_:"{!dismax qf=\"field_b\" mm=\\\'100%\\\'}value2"))', $processedQ[0]);
} }
/** /**
......
...@@ -51,7 +51,7 @@ class SearchHandlerTest extends PHPUnit_Framework_TestCase ...@@ -51,7 +51,7 @@ class SearchHandlerTest extends PHPUnit_Framework_TestCase
{ {
$spec = ['DismaxParams' => [['foo', 'bar']], 'DismaxFields' => ['field1', 'field2']]; $spec = ['DismaxParams' => [['foo', 'bar']], 'DismaxFields' => ['field1', 'field2']];
$hndl = new SearchHandler($spec); $hndl = new SearchHandler($spec);
$this->assertEquals('(_query_:"{!dismax qf=\"field1 field2\" foo=\\\'bar\\\'}foobar")', $hndl->createSimpleQueryString('foobar')); $this->assertEquals('(_query_:"{!dismax qf=\"field1 field2\" foo=\\\'bar\\\' mm=\\\'100%\\\'}foobar")', $hndl->createSimpleQueryString('foobar'));
} }
/** /**
...@@ -72,7 +72,7 @@ class SearchHandlerTest extends PHPUnit_Framework_TestCase ...@@ -72,7 +72,7 @@ class SearchHandlerTest extends PHPUnit_Framework_TestCase
*/ */
public function testToArray() public function testToArray()
{ {
$spec = ['DismaxParams' => [['foo', 'bar']], 'DismaxFields' => ['field1', 'field2']]; $spec = ['DismaxParams' => [['foo', 'bar'], ['mm', '100%']], 'DismaxFields' => ['field1', 'field2']];
$hndl = new SearchHandler($spec); $hndl = new SearchHandler($spec);
$defaults = ['CustomMunge' => [], 'DismaxHandler' => 'dismax', 'QueryFields' => [], 'FilterQuery' => []]; $defaults = ['CustomMunge' => [], 'DismaxHandler' => 'dismax', 'QueryFields' => [], 'FilterQuery' => []];
$this->assertEquals($spec + $defaults, $hndl->toArray()); $this->assertEquals($spec + $defaults, $hndl->toArray());
...@@ -87,7 +87,7 @@ class SearchHandlerTest extends PHPUnit_Framework_TestCase ...@@ -87,7 +87,7 @@ class SearchHandlerTest extends PHPUnit_Framework_TestCase
{ {
$spec = ['DismaxParams' => [['foo', 'bar']], 'DismaxFields' => ['field1', 'field2']]; $spec = ['DismaxParams' => [['foo', 'bar']], 'DismaxFields' => ['field1', 'field2']];
$hndl = new SearchHandler($spec, 'edismax'); $hndl = new SearchHandler($spec, 'edismax');
$this->assertEquals('(_query_:"{!edismax qf=\"field1 field2\" foo=\\\'bar\\\'}foobar")', $hndl->createSimpleQueryString('foobar')); $this->assertEquals('(_query_:"{!edismax qf=\"field1 field2\" foo=\\\'bar\\\' mm=\\\'0%\\\'}foobar")', $hndl->createSimpleQueryString('foobar'));
} }
/** /**
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment