Fixes a bug in search paging which was introduced when crawl mixes updates, also fixes a bug in where keywords could be lost in crawl mixes, a=chris

Chris Pollett [2011-05-13 00:May:th]
Fixes a bug in search paging which was introduced when crawl mixes updates, also fixes a bug in where keywords could be lost in crawl mixes, a=chris
Filename
lib/index_bundle_iterators/group_iterator.php
models/phrase_model.php
scripts/mix.js
diff --git a/lib/index_bundle_iterators/group_iterator.php b/lib/index_bundle_iterators/group_iterator.php
index 4749994da..bacbbdae8 100644
--- a/lib/index_bundle_iterators/group_iterator.php
+++ b/lib/index_bundle_iterators/group_iterator.php
@@ -103,7 +103,7 @@ class GroupIterator extends IndexBundleIterator
      * the minimum number of pages to group from a block;
      * this trumps $this->index_bundle_iterator->results_per_block
      */
-    const MIN_FIND_RESULTS_PER_BLOCK = 400;
+    const MIN_FIND_RESULTS_PER_BLOCK = 200;

     /**
      * Creates a group iterator with the given parameters.
diff --git a/models/phrase_model.php b/models/phrase_model.php
index 0e51a0a65..40efe8e5b 100755
--- a/models/phrase_model.php
+++ b/models/phrase_model.php
@@ -192,6 +192,7 @@ class PhraseModel extends Model
         $presentation_parts = preg_split('/#(\d)+#/',
             $input_phrase, -1, PREG_SPLIT_DELIM_CAPTURE);
         $count = 0;
+
         $presentation_parts = array_chunk($presentation_parts, 2);

         $num_parts = count($presentation_parts);
@@ -215,9 +216,16 @@ class PhraseModel extends Model
         }

         $results_high = $low + $results_per_page;
+        $num_last_parts = count($query_parts[$last_part]);
+        if($query_parts[$last_part][$num_last_parts - 1][0] +
+            $query_parts[$last_part][$num_last_parts - 1][1] < $low) {
+            $query_parts[$last_part][$num_last_parts - 1][1] = $results_high;
+        }
+
         $num_phrases = count($query_parts);

         foreach($query_parts as $phrase => $pre_result_bounds) {
+
             $phrase_high = $pre_result_bounds[0][1];
             $result_bounds = array();
             $start_flag = false;
@@ -227,6 +235,7 @@ class PhraseModel extends Model
                 if($bound[0] > $results_high) break;
                 //rest of presentation after what we'll return so break
                 $phrase_high =  $bound[0] + $bound[1];
+
                 if($phrase_high < $low) continue;
                 // this part of presentation is before what we'll return so skip
                 $result_bounds[] = $bound;
@@ -247,6 +256,7 @@ class PhraseModel extends Model
             foreach($disjunct_phrases as $disjunct) {
                 list($word_struct, $format_words) =
                     $this->parseWordStructConjunctiveQuery($disjunct);
+
                 if($word_struct != NULL) {
                     $word_structs[] = $word_struct;
                 }
@@ -298,6 +308,8 @@ class PhraseModel extends Model
             $format_words = NULL;
         }

+        $results["PAGES"] = array_values($results["PAGES"]);
+
         $output = $this->formatPageResults($results, $format_words);

         return $output;
diff --git a/scripts/mix.js b/scripts/mix.js
index cd04e35ed..8f9162260 100644
--- a/scripts/mix.js
+++ b/scripts/mix.js
@@ -198,11 +198,27 @@ function drawCrawl(i, j, ts, name, weight, keywords)
         "][COMPONENTS]["+j+"][CRAWL_TIMESTAMP]\"' value=\""+ts+"\" />"+
         "<input title=\""+tl['editmix_add_query']+"\" "+
         "name=\"mix[GROUPS]["+i+"][COMPONENTS]["+j+"][KEYWORDS]\" "+
-        "value=\""+ keywords+"\" class=\"widefield\"/></td><td><a href=\""+
+        "value=\""+ keywords+"\" onchange=\"updateKeywords("+i+","+j+
+        ", this.value)\""+
+        "class=\"widefield\"/></td><td><a href=\""+
         "javascript:removeCrawl("+i+", "+j+");\">"+
         tl['editmix_element_delete']+"</a></td>";
 }

+/*
+ * Used to update the keywords of a crawl in the groups array whenever it is
+ * changed in the form.
+ *
+ * @param int i group to update keywords in
+ * @param int j crawl within group to update
+ * @param String keywords the new keywords
+ */
+function updateKeywords(i, j, keywords)
+{
+    groups[i]['components'][j][3] = keywords;
+
+}
+
 /*
  * Deletes the jth crawl from the ith group in the current crawl mix
  *
ViewGit