_binary From 3728be40f7a09199703311d0562ba5d6397e1afd Mon Sep 17 00:00:00 2001
From: Gargi Sheguri <gargiegs@gmail.com>
Date: Mon, 13 Nov 2023 17:22:58 -0500
Subject: [PATCH] Fixes for disjunct logic: descriptions

---
 .../index_bundle_iterators/GroupIterator.php  |  2 +-
 src/models/PhraseModel.php                    | 24 +++++++++++--------
 2 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/src/library/index_bundle_iterators/GroupIterator.php b/src/library/index_bundle_iterators/GroupIterator.php
index 5b8fd5f83..98c9eb6e6 100644
--- a/src/library/index_bundle_iterators/GroupIterator.php
+++ b/src/library/index_bundle_iterators/GroupIterator.php
@@ -208,7 +208,7 @@ class GroupIterator extends IndexBundleIterator
                     $pages = -1;
                 }
             } else if (!empty($new_pages)) {
-                $pages += $new_pages;
+                $pages = array_merge($pages, $new_pages);
                 $count = count($pages);
             }
             if (isset($this->index_bundle_iterator->hard_query)) {
diff --git a/src/models/PhraseModel.php b/src/models/PhraseModel.php
index 46d3a6262..d7cb06de4 100755
--- a/src/models/PhraseModel.php
+++ b/src/models/PhraseModel.php
@@ -401,9 +401,11 @@ class PhraseModel extends ParallelModel
                                 .="$in2<b>Disjunct $dis_cnt:" . "</b><br>";
                             $dis_cnt++;
                         }
-                        list($word_struct, $format_words) =
+                        list($word_struct, $found_format_words) =
                             $this->parseWordStructConjunctiveQuery(
                                 $disjunct, $use_conjunctive);
+                        $format_words = array_merge($format_words,
+                            $found_format_words);
                         if ($word_struct != null) {
                             $word_structs[] = $word_struct;
                         }
@@ -612,17 +614,19 @@ class PhraseModel extends ParallelModel
             $split_terms[] = $s;
             $s = '';
         }
-        $meta_words = [];
+        $special_words = [];
         // Extracts any meta tags specified in the search phrase
         $meta_pattern = '/(' . implode('|', array_map('preg_quote',
                 PhraseParser::$meta_words_list)) . ')/';
+        $disallowed_pattern = '/^\-/';
         foreach ($split_phrase as $word) {
-            if (preg_match($meta_pattern, $word)) {
-                $meta_words[] = $word;
+            if (preg_match($meta_pattern, $word) ||
+                preg_match($disallowed_pattern, $word)) {
+                $special_words[] = $word;
             }
         }
         foreach ($split_terms as $term) {
-            if (!in_array($term, $meta_words)) {
+            if (!in_array($term, $special_words)) {
                 $search_terms[] = $term;
             }
         }
@@ -642,8 +646,8 @@ class PhraseModel extends ParallelModel
             }
         }
         for ($i = 0; $i < count($search_terms); $i++) {
-            foreach ($meta_words as $meta_word) {
-                $search_terms[$i] .= " " . $meta_word;
+            foreach ($special_words as $add_word) {
+                $search_terms[$i] .= " " . $add_word;
             }
         }
         $repeat_check = [];
@@ -659,8 +663,8 @@ class PhraseModel extends ParallelModel
                 $search_terms[$i] = $query_part;
             }
         }
-        if (count($search_terms) == 0 && count($meta_words) > 0) {
-            $search_terms = [implode(' ', $meta_words)];
+        if (count($search_terms) == 0 && count($special_words) > 0) {
+            $search_terms = [implode(' ', $special_words)];
         }
         /*
         The resultant array holds multiple strings, each signifying
@@ -1401,7 +1405,7 @@ class PhraseModel extends ParallelModel
                 if (!is_array($next_docs)) {
                     break;
                 }
-                $pages += $next_docs;
+                $pages = array_merge($pages, $next_docs);
                 $num_retrieved = count($pages);
             }
         }
-- 
2.42.0

