Merge "Add DEFAULTSORT to search index field data"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 1 Sep 2016 14:51:41 +0000 (14:51 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 1 Sep 2016 14:51:41 +0000 (14:51 +0000)
includes/content/WikiTextStructure.php
includes/content/WikitextContentHandler.php
includes/search/SearchIndexField.php
tests/phpunit/includes/content/WikitextStructureTest.php

index 9768d36..55c4ad5 100644 (file)
@@ -233,4 +233,12 @@ class WikiTextStructure {
                $this->extractWikitextParts();
                return $this->auxText;
        }
+
+       /**
+        * Get the defaultsort property
+        * @return string|null
+        */
+       public function getDefaultSort() {
+               return $this->parserOutput->getProperty( 'defaultsort' );
+       }
 }
index 1c46d28..b9fe004 100644 (file)
@@ -128,6 +128,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;
        }
 
@@ -160,6 +164,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() ) {
index 7499853..cfed1e9 100644 (file)
@@ -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
index 4301fb8..49907c8 100644 (file)
@@ -49,6 +49,19 @@ END;
                $this->assertContains( "Wikitext in Heading and also html", $headings );
        }
 
+       public function testDefaultSort() {
+               $text = <<<END
+Louise Michel
+== Heading one ==
+Some text
+==== See also ====
+* Also things to see!
+{{DEFAULTSORT:Michel, Louise}}
+END;
+               $struct = $this->getStructure( $text );
+               $this->assertEquals( "Michel, Louise", $struct->getDefaultSort() );
+       }
+
        public function testHeadingsFirst() {
                $text = <<<END
 == Heading one ==