From ddb0b2520a59011b444584ef988f337117906bcf Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Mon, 6 Jul 2015 17:12:52 +1200 Subject: [PATCH] API Additional support for custom copy_fields API Additional textSpellHtml type for html-safe spelling database generation --- code/solr/SolrIndex.php | 40 ++++++++++++++++++++++++++++++---- conf/solr/4/templates/types.ss | 11 ++++++++++ docs/en/Solr.md | 2 +- 3 files changed, 48 insertions(+), 5 deletions(-) diff --git a/code/solr/SolrIndex.php b/code/solr/SolrIndex.php index bea3b1d..0a72114 100644 --- a/code/solr/SolrIndex.php +++ b/code/solr/SolrIndex.php @@ -46,6 +46,14 @@ abstract class SolrIndex extends SearchIndex { * @config */ private static $default_field = '_text'; + + /** + * List of copy fields all fulltext fields should be copied into. + * This will fallback to default_field if not specified + * + * @var array + */ + private static $copy_fields = array(); /** * @return String Absolute path to the folder containing @@ -104,6 +112,22 @@ abstract class SolrIndex extends SearchIndex { return $this->config()->default_field; } + /** + * Get list of fields each text field should be copied into. + * This will fallback to the default field if omitted. + * + * @return array + */ + protected function getCopyDestinations() { + $copyFields = $this->config()->copy_fields; + if($copyFields) { + return $copyFields; + } + // Fallback to default field + $df = $this->getDefaultField(); + return array($df); + } + public function getFieldDefinitions() { $xml = array(); $stored = $this->getStoredDefault(); @@ -365,14 +389,22 @@ abstract class SolrIndex extends SearchIndex { ); } - function getCopyFieldDefinitions() { + /** + * Generate XML for copy field definitions + * + * @return string + */ + public function getCopyFieldDefinitions() { $xml = array(); - $df = $this->getDefaultField(); - foreach ($this->fulltextFields as $name => $field) { - $xml[] = ""; + // Default copy fields + foreach($this->getCopyDestinations() as $copyTo) { + foreach ($this->fulltextFields as $name => $field) { + $xml[] = ""; + } } + // Explicit copy fields foreach ($this->copyFields as $source => $fields) { foreach($fields as $fieldAttrs) { $xml[] = $this->toXmlTag('copyField', $fieldAttrs); diff --git a/conf/solr/4/templates/types.ss b/conf/solr/4/templates/types.ss index 135c8ac..c4081b8 100644 --- a/conf/solr/4/templates/types.ss +++ b/conf/solr/4/templates/types.ss @@ -203,6 +203,17 @@ + + + + + + + + + + + diff --git a/docs/en/Solr.md b/docs/en/Solr.md index eeef086..de66329 100644 --- a/docs/en/Solr.md +++ b/docs/en/Solr.md @@ -183,7 +183,7 @@ This can be fixed by aggregating spell checking data in a separate $xml = parent::getFieldDefinitions(); $xml .= "\n\n\t\t"; - $xml .= "\n\t\t"; + $xml .= "\n\t\t"; return $xml; }