Expand use of guessSemantics to mean also lang and safety, a=chris

Chris Pollett [2019-06-26 16:Jun:th]
Expand use of guessSemantics to mean also lang and safety, a=chris
Filename
src/models/PhraseModel.php
diff --git a/src/models/PhraseModel.php b/src/models/PhraseModel.php
index ec3db4911..d21c2bf53 100755
--- a/src/models/PhraseModel.php
+++ b/src/models/PhraseModel.php
@@ -365,7 +365,8 @@ class PhraseModel extends ParallelModel
                             $dis_cnt++;
                         }
                         list($word_struct, $format_words) =
-                            $this->parseWordStructConjunctiveQuery($disjunct);
+                            $this->parseWordStructConjunctiveQuery($disjunct,
+                            $guess_semantics);
                         if ($word_struct != null) {
                             $word_structs[] = $word_struct;
                         }
@@ -514,9 +515,12 @@ class PhraseModel extends ParallelModel
      * @param string& $phrase string to extract struct from, if the phrase
      *  semantics is guessed or an if condition is processed the value of
      *  phrase will be altered. (Helps for feeding to network queries)
+     * @param boolean $guess_semantics whether to add lang: and safe:
+     *  meta word even if not present in orginal query based on guessed values.
      * @return array struct representing the conjunctive query
      */
-    public function parseWordStructConjunctiveQuery(&$phrase)
+    public function parseWordStructConjunctiveQuery(&$phrase,
+        $guess_semantics = true)
     {
         $query = $phrase;
         $indent= "  ";
@@ -529,7 +533,7 @@ class PhraseModel extends ParallelModel
         list($found_metas, $disallow_phrases,
             $phrase_string, $query_string, $index_name, $weight,
             $locale_tag) =
-            $this->extractMetaWordInfo($phrase);
+            $this->extractMetaWordInfo($phrase, $guess_semantics);
         /*
             we search using the stemmed/char-grammed words, but we format
             snippets in the results by bolding either
@@ -711,10 +715,12 @@ class PhraseModel extends ParallelModel
      * the query
      *
      * @param string $phrase the query string
+     * @param boolean $guess_semantics whether to add lang: and safe:
+     *  meta word even if not present in orginal query based on guessed values.
      * @return array containing items listed above in the description of this
      *     method
      */
-    public function extractMetaWordInfo($phrase)
+    public function extractMetaWordInfo($phrase, $guess_semantics = true)
     {
         $index_name = $this->index_name;
         $weight = 1;
@@ -758,14 +764,16 @@ class PhraseModel extends ParallelModel
                 && substr($matches[0], 0, 11) == 'media:image') {
                 $found_media_image = true;
             }
-            if ($meta_word == 'site:' && !empty($matches[0])) {
-                $found_site = true;
-            }
-            if ($meta_word == 'safe:' && !empty($matches[0])) {
-                $found_safe = true;
-            }
-            if ($meta_word == 'lang:' && !empty($matches[0])) {
-                $found_lang = true;
+            if ($guess_semantics && !empty($matches[0])) {
+                if ($meta_word == 'site:') {
+                    $found_site = true;
+                }
+                if ($meta_word == 'safe:') {
+                    $found_safe = true;
+                }
+                if ($meta_word == 'lang:') {
+                    $found_lang = true;
+                }
             }
             $phrase_string = preg_replace($pattern, "", $phrase_string);
         }
@@ -776,7 +784,7 @@ class PhraseModel extends ParallelModel
             $phrase_string = "";
         }
         $found_metas = array_unique($found_metas);
-        if (!$found_media_image && !$found_site &&
+        if ($guess_semantics && !$found_media_image && !$found_site &&
             (!empty($found_metas) || !empty($phrase_string))) {
             if (!$found_lang) {
                 $lang_parts = explode("-", $locale_tag);
@@ -872,7 +880,7 @@ class PhraseModel extends ParallelModel
                     $letter = "thÆ°";
                     break;
             }
-            $phrase = $letter." ".$phrase."|".$phrase;
+            $phrase = $letter . " " . $phrase . "|" . $phrase;
         }
         $tag = str_replace("-", "_", $tag);
         $tokenizer_name = C\NS_LOCALE . "$tag\\resources\\Tokenizer";
ViewGit