--- modules/views_fastsearch/views_fastsearch.module	Sat Sep 08 15:14:15 2007
+++ modules/views_fastsearch/views_fastsearch.module	Sat Oct 13 17:12:57 2007
@@ -117,4 +117,12 @@
 function views_fastsearch_views_arguments() {
+  $arguments = array(
+      'search_node_index' => array(
+        'name' => t("Search: Fast Index"),
+        'handler' => "views_handler_arg_search_index",
+        'help' => t('Filters by nodes that match the search keys'),
+    ),
+  );
+  
   if (_views_fastsearch_is_search_node_links()) {
-    return array(
+    $arguments = array($arguments[0],
       'search_node_linked_to' => array(
@@ -131,5 +139,9 @@
       ),
-    );
+        
+  );
+
   }
+  return $arguments;
 }
+      
 
@@ -138,2 +150,130 @@
  */
+
+
+
+function views_handler_arg_search_index($op, &$query, $argtype, $arg = '') {
+  switch ($op) {
+    case 'filter':
+     $word_count = 0;
+      if (!empty($arg)) {
+        // use the newer fast search if the Dup indexes have been repaired
+        $search_index_unique = variable_get('search_index_unique', 0);
+
+        // walk through each of the values
+        // building the AND, OR, and exclusion terms
+        foreach (explode(' ', $arg) as $value) {
+          // OR applies to the next value only
+          $upper_value = strtoupper($value);
+          if ($upper_value == 'OR') {
+            // the initial AND assumption was wrong,
+            // convert the leading term to an OR term
+            if (isset($values['AND']) && count($values['AND']) == 1) {
+              $values['OR'] = $values['AND'];
+              unset($values['AND']);
+            }
+            $sqlop = ' OR ';
+            continue;
+          }
+
+          // throw out too small words
+          if (drupal_strlen($value) < variable_get('minimum_word_size', 3)) {
+            continue;
+          }
+
+          // we've got something to search on!
+          $word_count ++;
+
+          if ($sqlop == ' OR ' && $word_count > 1) {
+            $values['OR'][] = $value;
+          }
+          else { // implied AND
+            // look for an end to a quoted phrase
+            if (isset($in_quote)) {
+              if (substr($value, -1) != $in_quote) {
+                $quote_value .= ' '. $value;
+              }
+              else {
+                if (!$search_index_unique) {
+                  $tnc = $query->add_table('search_dataset', TRUE);
+                  $tablename = $query->get_table_name('search_dataset', $tnc);
+                  $and_clause[] = "$tablename.data like '%%%s%%'";
+                }
+                $values['AND'][] = $quote_value .' '. drupal_substr($value, 0, -1);
+                unset($in_quote);
+              }
+              continue;
+            }
+
+            $first_char = drupal_substr($value, 0, 1);
+            switch ($first_char) {
+              case '-': // values starting with a - are exlusion terms
+                $values['EXCLUDE'][] = drupal_substr($value, 1);
+                break;
+              case '"': // begin quoted phrase
+              case '\'':
+                if (substr($value, -1) == $first_char) {
+                  $value = drupal_substr($value, 1, -2);
+                }
+                else {
+                  $in_quote = $first_char;
+                  $quote_value = drupal_substr($value, 1);
+                  break;
+                }
+                // FALLTHROUGH
+              default:
+                if (!$search_index_unique) {
+                  $tnc = $query->add_table('search_index', TRUE);
+                  $tablename = $query->get_table_name('search_index', $tnc);
+                  $extra['AND'][] = "$tablename.word='%s'";
+                  //if ($filter['options']) {
+                  //  $tablename = $query->get_table_name('search_index', $tnc);
+                  //  $query->add_where("$tablename.type='%s'", $filter['options']);
+                  //}
+                }
+                $values['AND'][] = $value;
+                break;
+            }
+          }
+          $sqlop = ' AND ';
+        }
+      }
+
+      // if there aren't any words
+      if ($word_count == 0) {
+        $query->add_where('1');
+        return;
+      }
+
+      // 'simplify' the search terms, which calls the preprocess
+      //
+      // also, the Drupal search engine doesn't index quote characters,
+      // so remove them
+      foreach ($values as $op => $value) {
+        foreach ($values[$op] as $index => $word) {
+          $values[$op][$index] = str_replace('"', '', search_simplify($word));
+        }
+      }
+
+      // NOTE: using global to pass values to theme_views_fastsearch_display
+      global $_vfs_search_keys;
+      $_vfs_search_keys = $values;
+
+      // modify the query
+      if ($search_index_unique) {
+        _views_fastsearch_query_unique($query, $values, $extra);
+      }
+      else {
+        _views_fastsearch_query($query, $values, $extra);
+      }
+
+      // Log the search keys:
+      $type = 'views_fastsearch arg';
+      //if ($filter['operator'] != '=') {
+      //  $type .= ' '. $filter['operator'];
+      
+      watchdog('search', t('%keys (%type).', array('%keys' => $arg, '%type' => $type)), WATCHDOG_NOTICE);
+  }
+}
+
+
 function views_handler_arg_node_linked_to($op, &$query, $argtype, $arg = '') {
