From 7c09f09432690c97441d5c70c3ea652ac74f0802 Mon Sep 17 00:00:00 2001 From: dcausse Date: Mon, 29 Aug 2016 16:30:43 +0200 Subject: [PATCH] Add DEFAULTSORT to search index field data Added FLAG_SOURCE_DATA to support additional data that is not supposed to be part of the default mapping. Should merged with I1484c2e62788bedb57a42869a5fb25cd8f64482f, otherwize rebuilding an index may add an extra field to CirrusSearch mapping. Bug: T134978 Change-Id: Ia41f8eeb9dd4f764543bdd4d71b7a50de8101101 --- includes/content/WikiTextStructure.php | 8 ++++++++ includes/content/WikitextContentHandler.php | 5 +++++ includes/search/SearchIndexField.php | 10 ++++++++++ .../includes/content/WikitextStructureTest.php | 13 +++++++++++++ 4 files changed, 36 insertions(+) diff --git a/includes/content/WikiTextStructure.php b/includes/content/WikiTextStructure.php index e83c213c0e..4cf2915ba7 100644 --- a/includes/content/WikiTextStructure.php +++ b/includes/content/WikiTextStructure.php @@ -277,4 +277,12 @@ class WikiTextStructure { $this->extractWikitextParts(); return $this->auxText; } + + /** + * Get the defaultsort property + * @return string|null + */ + public function getDefaultSort() { + return $this->parserOutput->getProperty( 'defaultsort' ); + } } diff --git a/includes/content/WikitextContentHandler.php b/includes/content/WikitextContentHandler.php index 5c0a9c81fe..f3f2cb8f55 100644 --- a/includes/content/WikitextContentHandler.php +++ b/includes/content/WikitextContentHandler.php @@ -142,6 +142,10 @@ class WikitextContentHandler extends TextContentHandler { $fields['file_text'] = $engine->makeSearchFieldMapping( 'file_text', SearchIndexField::INDEX_TYPE_TEXT ); + $fields['defaultsort'] = $engine->makeSearchFieldMapping( 'defaultsort', + SearchIndexField::INDEX_TYPE_TEXT ); + $fields['defaultsort']->setFlag( SearchIndexField::FLAG_SOURCE_DATA ); + return $fields; } @@ -174,6 +178,7 @@ class WikitextContentHandler extends TextContentHandler { $fields['opening_text'] = $structure->getOpeningText(); $fields['text'] = $structure->getMainText(); // overwrites one from ContentHandler $fields['auxiliary_text'] = $structure->getAuxiliaryText(); + $fields['defaultsort'] = $structure->getDefaultSort(); $title = $page->getTitle(); if ( NS_FILE == $title->getNamespace() ) { diff --git a/includes/search/SearchIndexField.php b/includes/search/SearchIndexField.php index 7499853801..cfed1e9c14 100644 --- a/includes/search/SearchIndexField.php +++ b/includes/search/SearchIndexField.php @@ -35,6 +35,16 @@ interface SearchIndexField { * Do not index this field, just store it. */ const FLAG_NO_INDEX = 8; + + /** + * Similar to FLAG_NO_INDEX but we inform the SearchEngine + * that this field should not be part of the search schema + * by default. + * SearchEngine implementations could then override its settings + * or simply use this data for other purposes. + */ + const FLAG_SOURCE_DATA = 16; + /** * Get mapping for specific search engine * @param SearchEngine $engine diff --git a/tests/phpunit/includes/content/WikitextStructureTest.php b/tests/phpunit/includes/content/WikitextStructureTest.php index 6d83057b7e..15ba50b9eb 100644 --- a/tests/phpunit/includes/content/WikitextStructureTest.php +++ b/tests/phpunit/includes/content/WikitextStructureTest.php @@ -104,6 +104,19 @@ END; $this->assertContains( "Wikitext in Heading and also html", $headings ); } + public function testDefaultSort() { + $text = <<getStructure( $text ); + $this->assertEquals( "Michel, Louise", $struct->getDefaultSort() ); + } + public function testHeadingsFirst() { $text = <<