u'''Search forward starting at the current line and moving down
        through the the history as necessary. This is an incremental
        search.
778953
def forward_search_history(self, e):  # (C-s)
        '''
        log("fwd_search_history")
        self._init_incremental_search(self._history.forward_search_history, e)
        self.finalize()
758904
function isForwardByHistory () {
  // 如果访问的页面state和之前访问过的页面相同，则属于返回

  let index = HISTORY_STATE_STACK.indexOf(getHistoryStateKey())

  if (index !== HISTORY_STATE_STACK.length - 1 && index !== -1) {
    HISTORY_STATE_STACK.length = index + 1
    return false
  }

  return true
}
1310811
def search(self, term=None, category=None, pages=1, url=search_url,
				sort=None, order=None):
		""""""

		if not self.current_url:
			self.current_url = url

		if self.current_url == Search.base_url:
			# Searching home page so no formatting
			results = self._get_results(self.current_url)
			self._add_results(results)
		else:

			search = self._format_search(term, category)
			sorting = self._format_sort(sort, order)

			# Now get the results.
			for i in range(pages):
				results = self._get_results(search + "/" + str(self._current_page) +
											"/" + sorting)
				self._add_results(results)
				self._current_page += 1
			self._current_page -= 1
1001719
private int findSlotBefore(SearchKey searchKey) {
		/*
		 * int slot = 0; while (slot < contents.getNumRecords() &&
		 * getKey(contents, slot).compareTo(searchKey) < 0) slot++; return slot
		 * - 1;
		 */
		// Optimization: Use binary search rather than sequential search
		int startSlot = 0, endSlot = currentPage.getNumRecords() - 1;
		int middleSlot = (startSlot + endSlot) / 2;

		if (endSlot >= 0) {
			while (middleSlot != startSlot) {
				if (getKey(currentPage, middleSlot, keyType.length())
						.compareTo(searchKey) < 0)
					startSlot = middleSlot;
				else
					endSlot = middleSlot;

				middleSlot = (startSlot + endSlot) / 2;
			}

			if (getKey(currentPage, endSlot, keyType.length()).compareTo(searchKey) < 0)
				return endSlot;
			else if (getKey(currentPage, startSlot, keyType.length())
					.compareTo(searchKey) < 0)
				return startSlot;
			else
				return startSlot - 1;
		} else
			return -1;
	}
832119
def auto_down(self, count=1, go_to_start_of_line_if_history_changes=False):
        
        if self.complete_state:
            self.complete_next(count=count)
        elif self.document.cursor_position_row < self.document.line_count - 1:
            self.cursor_down(count=count)
        elif not self.selection_state:
            self.history_forward(count=count)

            # Go to the start of the line?
            if go_to_start_of_line_if_history_changes:
                self.cursor_position += self.document.get_start_of_line_position()
1124019
function next_step(response, search){

	ll('init start...');

	// Prevent future actions (the register would be sticky).
	search.unregister('search', 'next step');

	// Take a look at the two facets that we'll be iterating over.
	ll('Gathering functions for term data...');
	var reqs_to_do = 0;
	f1 = response.facet_field(global_facet1);
	f2 = response.facet_field(global_facet2);
	ll('f1: ' + f1);
	ll('f2: ' + f2);

	// Collect the initial node information for the two axes.
	// Also collect the initial index by id for both axes.
	var id_to_index = {};
	us.each([f1, f2], function(set){
	    us.each(set, function(set_pair, set_index){
		var sid = set_pair[0];
		nodes.push({id: sid, index: set_index});
		id_to_index[sid] = set_index;
	    });
	});
	ll('id_to_index #: ' + us.keys(id_to_index).length);

	// Now collect the batch URLs along one facet in reference to
	// the other (arbitrary)--we should be able to get what we
	// want by just looking at once facet and checking the other
	// as we vary it.
	var collected_functions = [];
	us.each(f1, function(f1_pair){
	    reqs_to_do++;
	    collected_functions.push(
		function(){
		    var f1_id = f1_pair[0];
		    
		    // Return the state.
		    // We have to reset the rows as well since rows is
		    // not sticky across a search action (think about
		    // it).
		    search.set('rows', 0); // we don't need any actual rows
		    search.set_facet_limit(flimit);
		    search.reset_query_filters();
		    
		    search.add_query_filter(global_facet1, f1_id);
		    return search.search();
		});
	});

	// Fetch the data and scrape out what we want.
	var reqs_done = 0;
	var accumulator_fun = function(resp){

	    // Update progress bar.
	    reqs_done++;
	    var per = Math.round((reqs_done / reqs_to_do) * 100);
	    //ll(reqs_done + ' of ' + reqs_to_do + ' = ' + per + '%');
	    // jQuery(pwidget).progressbar('value', per);
	    jQuery(pwidget_bs3_bar).css('width', per + '%');
	    jQuery(pwidget_bs3_bar).attr('aria-valuenow', per);

	    // Recover the facet that we're currently looking at: 1.
	    var f1_name = '???';
    	    var fq_set = resp.parameter('fq');
	    //ll('accumu: ' + dump(fq_set));
	    us.each(fq_set, function(fq_item){
		// Split up each line in the set.
		var two_part = bbop.first_split(':', fq_item);
    		var fkey = two_part[0];
    		var fval = bbop.dequote(two_part[1]);
    		//ll('Looking at info for: ' + fval);
		
		// Check to see if it matches. If it does, that's the
		// recovered value.
		if( fkey === global_facet1 ){
		    f1_name = fval;		     
		}
	    });
	    ll('got: ' + f1_name);

	    // Now grab out all of the second-facet information.
	    //ll('accumu: ' + resp.raw());
	    var incoming_facet = resp.facet_field(global_facet2);
	    var in_hash = bbop.hashify(incoming_facet);	
	    ll('in_hash: ' + bbop.dump(in_hash));
	    us.each(f2, function(f2_line, f2_index){

		// Figure out the value for this pair.
		var f2_name = f2_line[0];
		//var comb_val = f2_line[1];
		var comb_val = 0;
		var results_val = 0;
		if( typeof(in_hash[f2_name]) !== 'undefined' ){
		    results_val = in_hash[f2_name];
		}
		ll([f1_name, f2_name].join(', ') + ': ' + results_val);
		
		// Up the max.
		if( results_val > max_val ){
		    max_val = results_val;
		}
		
		// While we're here, let's also create a lookup
		// structure.
		if( typeof(val_hash[f1_name]) === 'undefined' ){
		    val_hash[f1_name] = {}; }
		if( typeof(val_hash[f2_name]) === 'undefined' ){
		    val_hash[f2_name] = {}; }
		if( typeof(val_hash[f1_name][f2_name]) === 'undefined' ){
		    val_hash[f1_name][f2_name] = results_val; }
		if( typeof(val_hash[f2_name][f1_name]) === 'undefined' ){
		    val_hash[f2_name][f1_name] = results_val; }
	    });
	};

	///
	/// Coloration functions using D3.
	/// We have the max_val now, so we can compute color.
	///

	// A value from our values domain in to a color in our range.
	// 0 always maps to a white-ish color.
	var c = d3.scale.linear().domain([0,max_val]).rangeRound([127,255]);
	function value_to_color_dark(val){
	    //var retval = '#efefef';
	    var retval = '#fafafa';
	    if( val !== 0 ){
		var cval = c(val);
		var cinv = 255 - cval;
		var chex = cinv.toString(16);
		if( cval ){
		    if( chex.length === 1 ){ chex = '0' + chex; }
		    retval = '#' + chex + chex + chex + '';
		}
	    }
	    return retval;
	}
	function value_to_color_step(val){
	    //var retval = '#efefef';
	    var retval = '#fafafa';
	    if( val !== 0 ){
		// 1-3 = pale green
		// 4-10 = yellow
		// 11-100 = orange
		// 101+ = red 
		if( val <= 3 ){
		    retval = '#79f853'; // green
		}else if( val <= 10 ){
		    //retval = '#f5ff2b'; // yellow
		    retval = '#e8f129'; // yellow
		}else if( val <= 100 ){
		    retval = '#fd953b'; // orange		
		}else{
		    retval = '#ff4e53';
		}
	    }
	    return retval;
	}	
	// Decide our coloration live at this point.
	//var value_to_color = value_to_color_dark; // default
	value_to_color = value_to_color_step; // default
	// var curr_color_selection =
	// 	jQuery("input:radio[name=color]:checked").val();
	
	// The final function is the data renderer.
	var final_fun = function(){
	    ll('Entering final_fun...');

	    // We are done!
	    jQuery(pwidget_bs3_container).hide();

	    //render(matrix, nodes, max_val);
	    render();
	};

	// The final function is the data renderer.
	var error_fun = function(err){
	    alert('Encountered error while running: ' + err.toString());
	};

	search.run_promise_functions(collected_functions,
				     accumulator_fun, final_fun, error_fun);
    }
293873
def reverse_search_history(self, e):  # (C-r)
        '''
        log("rev_search_history")
        self._init_incremental_search(self._history.reverse_search_history, e)
        self.finalize()
855902
def reverse_search_history(event):
    
    event.cli.current_search_state.direction = IncrementalSearchDirection.BACKWARD
    event.cli.push_focus(SEARCH_BUFFER)
359795
def search_next(self):
        

        pattern = self.get_selected_text() or self.__search_pattern
        if not pattern:
            return False

        return self.search(pattern, **{"case_sensitive": True,
                                       "whole_word": False,
                                       "regular_expressions": False,
                                       "backward_search": False,
                                       "wrap_around": True})
1266895
def previous_history(self, current): # (C-p)
         '''
        if self.history_cursor == len(self.history):
            self.history.append(current.copy()) #do not use add_history since we do not want to increment cursor
            
        if self.history_cursor > 0:
            self.history_cursor -= 1
            current.set_line(self.history[self.history_cursor].get_line_text())
            current.point = lineobj.EndOfLine
906061
function beginSearch(prefix, initialString) {
        function createDialog() {
            _curDialog = new QuickNavigateDialog();
            _curDialog.showDialog(prefix, initialString);
        }

        if (_curDialog) {
            if (_curDialog.isOpen) {
                // Just start a search using the existing dialog.
                _curDialog.setSearchFieldValue(prefix, initialString);
            } else {
                // The dialog is already closing. Wait till it's done closing,
                // then open a new dialog. (Calling close() again returns the
                // promise for the deferred that was already kicked off when it
                // started closing.)
                _curDialog.close().done(createDialog);
            }
        } else {
            createDialog();
        }
    }
828418
function() {
        var hist = $.mobile.navigate.history;

        if ( this._isCloseable ) {
            this._isCloseable = false;
            // If the hash listening is enabled and there is at least one preceding history
            // entry it's ok to go back. Initial pages with the dialog hash state are an example
            // where the stack check is necessary
            if ( $.mobile.hashListeningEnabled && hist.activeIndex > 0 ) {
                $.mobile.back();
            } else {
                $.mobile.pageContainer.pagecontainer( "back" );
            }
        }
    }
1102590
def page(self, i):
		""""""
		# Need to clear previous results.
		self.torrents = list()
		self._current_page = i
		self.search(term=self.term, category=self.category,
					sort=self.sort, order=self.order)
768061
function forwardSearch() {
      cameFrom = open1Set.pop();
      if (cameFrom.closed) {
        return;
      }

      cameFrom.closed = true;

      if (cameFrom.f1 < lMin && (cameFrom.g1 + f2 - heuristic(from, cameFrom.node)) < lMin) {
        graph.forEachLinkedNode(cameFrom.node.id, forwardVisitor);
      }

      if (open1Set.length > 0) {
        // this will be used in reverse search
        f1 = open1Set.peek().f1;
      } 
    }
983201
private void seekNext() {
    if (!needSeek) {
      return;
    }

    // First, iterate all
    if (this.currentIterator != null && this.currentIterator.hasNext()) {
      needSeek = false;
      return;
    }

    // Then, find the next available work unit
    nextWu = null;
    this.currentIterator = null;
    while (nextWu == null && workUnits.hasNext()) {
      nextWu = workUnits.next();
      if (nextWu instanceof MultiWorkUnit) {
        this.currentIterator = ((MultiWorkUnit) nextWu).getWorkUnits().iterator();
        if (!this.currentIterator.hasNext()) {
          nextWu = null;
        }
      }
    }

    needSeek = false;
  }
869608
private boolean performLineSearch() {
		// if true then it can't iterate any more
		if( lineSearch.iterate() ) {
			// see if the line search failed
			if( !lineSearch.isConverged() ) {
				if( firstStep ) {
					// if it failed on the very first step then it might have been too large
					// try halving the step size
					initialStep /= 2;
					if( initialStep != 0 ) {
						invokeLineInitialize(fx, maxStep);
						return false;
					} else {
						if( verbose != null && verboseLevel != 0 ) {
							verbose.println("Initial step reduced to zero");
						}
						return terminateSearch(false);
					}
				} else {
					return terminateSearch(false);
				}
			} else {
				firstStep = false;
			}

			// update variables
			double step = lineSearch.getStep();

			// save the new x
			System.arraycopy(function.getCurrentState(),0,x.data,0,N);
			// compute the change in the x
			for( int i = 0; i < N; i++ )
				s.data[i] = step * searchVector.data[i];
			updated = true;

			// convergence tests
			// function value at end of line search
			double fstp = lineSearch.getFunction();

			if( verbose != null ) {
				double actualStep = NormOps_DDRM.fastNormF(s);
				double ftest_val = Math.abs(fstp-fx)/Math.abs(fx);
				double gtest_val = Math.abs(derivAtZero);

				verbose.printf("%-4d  %9.3E  %10.3E  %9.3E  %9.3E  %9.3E  %6.3f\n",
						iterations, fstp, fstp - fx,actualStep,ftest_val,gtest_val, maxStep);
			}

			// see if the actual different and predicted differences are smaller than the
			// error tolerance
			if( Math.abs(fstp-fx) <= ftol*Math.abs(fx) || Math.abs(derivAtZero) < gtol ) {
				if( verbose != null ) {
					verbose.println("converged after line search.");
				}
				return terminateSearch(true);
			}

			if( fstp > fx ) {
				throw new RuntimeException("Bug! Worse results!");
			}

			// current function value is now the previous
			fx = fstp;

			// start the loop again
			mode = 0;
		}
		return false;
	}
930554
def find(self):
        """"""
        options = self.find_options.get_options()
        if options is None:
            return
        self.stop_and_reset_thread(ignore_results=True)
        self.search_thread = SearchThread(self)
        self.search_thread.sig_finished.connect(self.search_complete)
        self.search_thread.sig_current_file.connect(
            lambda x: self.status_bar.set_label_path(x, folder=False)
        )
        self.search_thread.sig_current_folder.connect(
            lambda x: self.status_bar.set_label_path(x, folder=True)
        )
        self.search_thread.sig_file_match.connect(
            self.result_browser.append_result
        )
        self.search_thread.sig_out_print.connect(
            lambda x: sys.stdout.write(str(x) + "\n")
        )
        self.status_bar.reset()
        self.result_browser.clear_title(
            self.find_options.search_text.currentText())
        self.search_thread.initialize(*options)
        self.search_thread.start()
        self.find_options.ok_button.setEnabled(False)
        self.find_options.stop_button.setEnabled(True)
        self.status_bar.show()