Add DEFAULTSORT to search index field data
authordcausse <dcausse@wikimedia.org>
Mon, 29 Aug 2016 14:30:43 +0000 (16:30 +0200)
committerdcausse <dcausse@wikimedia.org>
Mon, 29 Aug 2016 14:51:57 +0000 (16:51 +0200)
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
includes/content/WikitextContentHandler.php
includes/search/SearchIndexField.php
tests/phpunit/includes/content/WikitextStructureTest.php

index e83c213..4cf2915 100644 (file)
@@ -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' );
+       }
 }
index 5c0a9c8..f3f2cb8 100644 (file)
@@ -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() ) {
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 6d83057..15ba50b 100644 (file)
@@ -104,6 +104,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 ==