Add SearchIndexField::getEngineHints()
authorDavid Causse <dcausse@wikimedia.org>
Tue, 20 Jun 2017 13:43:28 +0000 (15:43 +0200)
committerDavid Causse <dcausse@wikimedia.org>
Thu, 22 Jun 2017 14:03:01 +0000 (16:03 +0200)
Allows search engine clients that implement custom definitions
to pass engine hints used at index time.
Hints are a way to fine tune the behavior of the search engine
when handling a particular field.
As of now this is introduced for CirrusSearch to let SearchIndexField
implementations to control how the noop script is configured.
The noop hint with CirrusSearch allows to (for example):
- ignore an update if a numeric value does not change for more than X%
- control the merge strategy of complex fields

Bug: T166589
Change-Id: Ia560e41d33013c30ac47e5a60543f8cb133e61fb

includes/search/NullIndexField.php
includes/search/SearchIndexField.php
includes/search/SearchIndexFieldDefinition.php

index 933e0ad..852e1d5 100644 (file)
@@ -42,4 +42,11 @@ class NullIndexField implements SearchIndexField {
        public function merge( SearchIndexField $that ) {
                return $that;
        }
+
+       /**
+        * {@inheritDoc}
+        */
+       public function getEngineHints( SearchEngine $engine ) {
+               return [];
+       }
 }
index 6b5316f..a348d6d 100644 (file)
@@ -72,4 +72,21 @@ interface SearchIndexField {
         * @return SearchIndexField|false New definition or false if not mergeable.
         */
        public function merge( SearchIndexField $that );
+
+       /**
+        * A list of search engine hints for this field.
+        * Hints are usually specific to a search engine implementation
+        * and allow to fine control how the search engine will handle this
+        * particular field.
+        *
+        * For example some search engine permits some optimizations
+        * at index time by ignoring an update if the updated value
+        * does not change by more than X% on a numeric value.
+        *
+        * @param SearchEngine $engine
+        * @return array an array of hints generally indexed by hint name. The type of
+        * values is search engine specific
+        * @since 1.30
+        */
+       public function getEngineHints( SearchEngine $engine );
 }
index 04344fd..e3e01e8 100644 (file)
@@ -140,4 +140,11 @@ abstract class SearchIndexFieldDefinition implements SearchIndexField {
        public function setMergeCallback( $callback ) {
                $this->mergeCallback = $callback;
        }
+
+       /**
+        * {@inheritDoc}
+        */
+       public function getEngineHints( SearchEngine $engine ) {
+               return [];
+       }
 }