mirror of
https://github.com/silverstripe/silverstripe-fulltextsearch
synced 2024-10-22 12:05:29 +00:00
Merge pull request #61 from tractorcow/pulls/master/storedfields
BUG Add missing addStoredFields method
This commit is contained in:
commit
ff62c2b930
@ -81,7 +81,7 @@ abstract class SolrIndex extends SearchIndex {
|
|||||||
|
|
||||||
function getFieldDefinitions() {
|
function getFieldDefinitions() {
|
||||||
$xml = array();
|
$xml = array();
|
||||||
$stored = Director::isDev() ? "stored='true'" : "stored='false'";
|
$stored = $this->getStoredDefault();
|
||||||
|
|
||||||
$xml[] = "";
|
$xml[] = "";
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ abstract class SolrIndex extends SearchIndex {
|
|||||||
|
|
||||||
// Add the fulltext collation field
|
// Add the fulltext collation field
|
||||||
|
|
||||||
$xml[] = "<field name='_text' type='htmltext' indexed='true' $stored multiValued='true' />" ;
|
$xml[] = "<field name='_text' type='htmltext' indexed='true' stored='$stored' multiValued='true' />" ;
|
||||||
|
|
||||||
// Add the user-specified fields
|
// Add the user-specified fields
|
||||||
|
|
||||||
@ -143,6 +143,28 @@ abstract class SolrIndex extends SearchIndex {
|
|||||||
return str_replace(' ', '+', $this->getNiceSuggestion($collation));
|
return str_replace(' ', '+', $this->getNiceSuggestion($collation));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a field that should be stored
|
||||||
|
*
|
||||||
|
* @param string $field The field to add
|
||||||
|
* @param string $forceType The type to force this field as (required in some cases, when not
|
||||||
|
* detectable from metadata)
|
||||||
|
* @param array $extraOptions Dependent on search implementation
|
||||||
|
*/
|
||||||
|
public function addStoredField($field, $forceType = null, $extraOptions = array()) {
|
||||||
|
$options = array_merge($extraOptions, array('stored' => 'true'));
|
||||||
|
$this->addFulltextField($field, $forceType, $options);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the default 'stored' value for fields in this index
|
||||||
|
*
|
||||||
|
* @return string A default value for the 'stored' field option, either 'true' or 'false'
|
||||||
|
*/
|
||||||
|
protected function getStoredDefault() {
|
||||||
|
return Director::isDev() ? 'true' : 'false';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param String $name
|
* @param String $name
|
||||||
* @param Array $spec
|
* @param Array $spec
|
||||||
@ -166,7 +188,7 @@ abstract class SolrIndex extends SearchIndex {
|
|||||||
'name' => $name,
|
'name' => $name,
|
||||||
'type' => $type,
|
'type' => $type,
|
||||||
'indexed' => 'true',
|
'indexed' => 'true',
|
||||||
'stored' => Director::isDev() ? 'true' : 'false',
|
'stored' => $this->getStoredDefault(),
|
||||||
'multiValued' => $multiValued
|
'multiValued' => $multiValued
|
||||||
),
|
),
|
||||||
isset($spec['extra_options']) ? $spec['extra_options'] : array()
|
isset($spec['extra_options']) ? $spec['extra_options'] : array()
|
||||||
|
@ -132,6 +132,39 @@ class SolrIndexTest extends SapphireTest {
|
|||||||
$this->assertEquals('destField', $copyField[0]['dest']);
|
$this->assertEquals('destField', $copyField[0]['dest']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests the setting of the 'stored' flag
|
||||||
|
*/
|
||||||
|
public function testStoredFields() {
|
||||||
|
// Test two fields
|
||||||
|
$index = new SolrIndexTest_FakeIndex2();
|
||||||
|
$index->addStoredField('Field1');
|
||||||
|
$index->addFulltextField('Field2');
|
||||||
|
$schema = $index->getFieldDefinitions();
|
||||||
|
$this->assertContains(
|
||||||
|
"<field name='SearchUpdaterTest_Container_Field1' type='text' indexed='true' stored='true'",
|
||||||
|
$schema
|
||||||
|
);
|
||||||
|
$this->assertContains(
|
||||||
|
"<field name='SearchUpdaterTest_Container_Field2' type='text' indexed='true' stored='false'",
|
||||||
|
$schema
|
||||||
|
);
|
||||||
|
|
||||||
|
// Test with addAllFulltextFields
|
||||||
|
$index2 = new SolrIndexTest_FakeIndex2();
|
||||||
|
$index2->addAllFulltextFields();
|
||||||
|
$index2->addStoredField('Field2');
|
||||||
|
$schema2 = $index2->getFieldDefinitions();
|
||||||
|
$this->assertContains(
|
||||||
|
"<field name='SearchUpdaterTest_Container_Field1' type='text' indexed='true' stored='false'",
|
||||||
|
$schema2
|
||||||
|
);
|
||||||
|
$this->assertContains(
|
||||||
|
"<field name='SearchUpdaterTest_Container_Field2' type='text' indexed='true' stored='true'",
|
||||||
|
$schema2
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
protected function getServiceMock() {
|
protected function getServiceMock() {
|
||||||
return Phockito::mock('Solr3Service');
|
return Phockito::mock('Solr3Service');
|
||||||
}
|
}
|
||||||
@ -165,3 +198,20 @@ class SolrIndexTest_FakeIndex extends SolrIndex {
|
|||||||
$this->addFilterField('ManyManyObjects.Field1');
|
$this->addFilterField('ManyManyObjects.Field1');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class SolrIndexTest_FakeIndex2 extends SolrIndex {
|
||||||
|
|
||||||
|
protected function getStoredDefault() {
|
||||||
|
// Override isDev defaulting to stored
|
||||||
|
return 'false';
|
||||||
|
}
|
||||||
|
|
||||||
|
function init() {
|
||||||
|
$this->addClass('SearchUpdaterTest_Container');
|
||||||
|
$this->addFilterField('MyDate', 'Date');
|
||||||
|
$this->addFilterField('HasOneObject.Field1');
|
||||||
|
$this->addFilterField('HasManyObjects.Field1');
|
||||||
|
$this->addFilterField('ManyManyObjects.Field1');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user