/* EXAMPLE SEARCH FUNCTIONS END /* PHRASE SCRAPE FUNCTIONS START
350618
function getTags($) {
  const tags = [];

  const tagElements = $('.concept_light-tag');
  for (let i = 0; i < tagElements.length; i += 1) {
    const tagText = tagElements.eq(i).text();
    tags.push(tagText);
  }

  return tags;
}
266773
function begins(query, node) {
  var value = node[query.name]

  return (
    typeof value === 'string' &&
    value.slice(0, query.value.length) === query.value
  )
}
7672
function getSearchRange( isDefault ) {
				var searchRange,
					sel = editor.getSelection(),
					editable = editor.editable();

				if ( sel && !isDefault ) {
					searchRange = sel.getRanges()[ 0 ].clone();
					searchRange.collapse( true );
				} else {
					searchRange = editor.createRange();
					searchRange.setStartAt( editable, CKEDITOR.POSITION_AFTER_START );
				}
				searchRange.setEndAt( editable, CKEDITOR.POSITION_BEFORE_END );
				return searchRange;
			}
295865
function search(query, cols, max) {
    var url;
    var token = cache.get('token');
    var cases;
    var fields;
    var dfrd = Q.defer();

    function extractCases(xml) {
      var r = _parse(xml, dfrd);
      if (!r ||
        !r.response ||
        !r.response.cases ||
        !r.response.cases.length ||
        !r.response.cases[0].case) {
        return dfrd.reject(MODULE_ERRORS.bugNotFound);
      }
      cases = r.response.cases[0].case.map(function(kase) {
        var bug = new Case({
          id: kase.$.ixBug,
          operations: kase.$.operations.split(','),
          title: kase.sTitle[0].trim(),
          status: kase.sStatus[0].trim(),
          url: format('%s://%s/default.asp?%s', PROTOCOL, conf.host,
            kase.$.ixBug),
          fixFor: kase.sFixFor[0].trim()
        });
        if (kase.sPersonAssignedTo) {
          bug.assignedTo = kase.sPersonAssignedTo[0].trim();
          bug.assignedToEmail = kase.sEmailAssignedTo[0].trim();
        }
        if (kase.tags && kase.tags[0].tag) {
          bug.tags = kase.tags[0].tag.join(', ');
        }
        // find anything leftover in the case, disregarding the fields we
        // already
        _(kase)
          .keys()
          .difference(_.keys(bug).concat('sTitle', 'sStatus', '$',
            'sFixFor', 'sPersonAssignedTo',
            'sEmailAssignedTo'))
          .each(function(key) {
            var value = kase[key];
            bug[key] = _.isArray(value) && value.length === 1 ?
              // dereference
              bug[key] = value[0].trim() :
              value;
          });
        bug._raw = kase;
        return bug;
      });
      if (cases.length > 1) {
        return cases;
      }
      return cases[0];
    }

    fields = (cols || DEFAULT_COLS).join(',');
    max = max || DEFAULT_MAX;
    query = encodeURIComponent(query);
    if (!token) {
      dfrd.reject(MODULE_ERRORS.undefinedToken);
    } else {
      url = format(URLs.search, PROTOCOL, conf.host, query, fields, max,
        token);
      request(url, function(err, res, body) {
        var newCases;
        if (err) {
          dfrd.reject(err);
        } else {
          newCases = extractCases(body);
          if (!newCases) {
            console.error(body);
            dfrd.reject(MODULE_ERRORS.unknown);
          } else {
            dfrd.resolve(newCases);
          }
        }
      });
    }
    return dfrd.promise;
  }
365649
function run(input, keywords, endindex) {

	var METHODNAME = /\w|\$/;
	var CLASSNAME = /\w|\$|\./;

	var output = '',
		character = '',
		prototype = null,
		charindex = 0,
		curlcount = 0,
		prencount = 0,
		stringmode = false,
		commentmode = false,
		supercall = false,
		methodname = false,
		superargs = false,
		buffer = '',
		wordindex = -1,
		subwords = [
			'.extend', 
			'.mixin'
		];

	/**
	 * Check if we hit a `MyClass.extend` or `MyClass.mixin` pattern.
	 */
	function checkextensions() {
		subwords.every(checkextension);
	}

	/**
	 * Did the code just itend to extend or mixin something? 
	 * If so, we switch to super keyword replacement modus.
	 * @param {string} subword
	 * @returns {boolean} True if no match (so check another match)
	 */
	function checkextension(subword) {
		var checknext = true;
		if(findbehind(subword) && endshere(subword)) {
			wordindex = startindex(subword);
			prototype = getprototypeat(wordindex);
			curlcount = 0;
			prencount = 0;
			checknext = false;
		}
		return checknext;
	}

	/**
	 * Did the code just intend a supercall?
	 */
	function checksupercall() {
		keywords.every(function(keyword) {
			if (findbehind(keyword)) {
				supercall = true;
				methodname = true;
				buffer = buffer.substr(0, startindex(keyword));
				buffer += prototype;
				return false;
			}
			return true;
		});
	}

	/**
	 * TODO: zero-index singularity?
	 * @param {number} index
	 * @returns {string} 
	 */
	function getprototypeat(index) {
		var prev = buffer.substr(0, index);
		var indx = prev.length;
		while(--indx && prev[indx].match(CLASSNAME)) {}
		return prev.substring(indx + 1) + '.prototype.';
	}

	/**
	 * @param {string} string
	 * @returns {booleans}
	 */
	function findbehind(string) {
		var nowlength, hindsight;
		if (bufferlength() >= string.length) {
			nowlength = startindex(string);
			hindsight = buffer.substr(nowlength, string.length);
			if (hindsight === string) {
				return true;
			}
		}
		return false;
	}

	/**
	 * Magic word is not a substring of a longer word?
	 * @param {string} subword
	 * @returns {booleans}
	 */
	function endshere(subword) {
		var nextindex = charindex + 1;
		return input.length === nextindex ||
			!input[nextindex].match(METHODNAME);
	}

	/**
	 * Sugar.
	 * @returns {number}
	 */
	function bufferlength() {
		return buffer.length;
	}

	/**
	 * Compute index of string in buffer.
	 * @param {string} string
	 * @return {number}
	 */
	function startindex(string) {
		return bufferlength() - string.length;
	}

	/**
	 * TODO: all sorts of edge cases
	 */
	function processsupercall() {
		if (methodname) {
			if (!character.match(METHODNAME)) {
				buffer += '.call';
				methodname = false;
			}
		} else if (superargs) {
			if (character.match(METHODNAME)) {
				buffer += ', ';
				superargs = false;
			}
		}
		switch (character) {
			case '(':
				character = '(this';
				superargs = true;
				break;
			case ')':
				supercall = false;
				superargs = false;
				break;
		}
	}

	/**
	 * Flush buffer to output.
	 */
	function flush() {
		output += buffer;
		output += character;
		buffer = '';
		supercall = false;
		methodname = false;
		superargs = false;
	}

	/**
	 * Process chars in one way.
	 * TODO: This ain't right :/
	 */
	function somechars() {
		var was = false;
		if(!stringmode && !commentmode) {
			if(prototype) {
				switch (character) {
					case '(':
						prencount ++;
						break;
					case ')':
						was = prencount > 0;
						prencount --;
						if(was && prencount === 0) {
							prototype = null;
						}
						break;
					case '{':
						curlcount ++;
						break;
					case '}':
						was = curlcount > 0;
						curlcount --;
						if(was && curlcount === 0) {
							prototype = null;
						}
						break;
				}
			}
		}
	}

	/**
	 * Process chars in another way.
	 */
	function morechars() {
		switch (character) {
			case ';':
				flush();
				break;
			case '=':
			case '\'':
			case '"':
				if(!supercall) {
					flush();
				}
				break;
			default:
				if (supercall) {
					processsupercall();
				}
				buffer += character;
				if (prototype && !supercall) {
					checksupercall();
				}
				if(!prototype) {
					checkextensions();
				}
				break;
		}
	}

	// iterate all characters
	while (charindex <= endindex) {
		character = input[charindex];
		somechars();
		morechars();
		charindex++;
	}

	// flush all to output
	return output + buffer;
}
969790
def web_search(self, query, start=0, limit=100, max_tries=3):
        '''
        
        '''
        tries = 0
        if isinstance(query, unicode):
            query = query.encode('utf8')
        url = self.url % dict(key=self.api_key,
                              query=urllib.quote(query.strip()),
                              num=min(10, limit - start),
                              start=start)
        logger.info("fetching: %s" % url)
        while 1:
            try:
                request = urllib2.Request(url)
                request.add_header('Accept-encoding', 'gzip')
                # We do we set this?  Remnant from pre-API version?
                request.add_header('User-Agent', USER_AGENT)
                opener = urllib2.build_opener()

                fh = opener.open(request, timeout=60)
                data = fh.read()
                if fh.headers.get('Content-Encoding') == 'gzip':
                    compressedstream = StringIO.StringIO(data)
                    fh = gzip.GzipFile(fileobj=compressedstream)
                    data = fh.read()
                return json.loads(data)
            except Exception, exc:
                logger.info(traceback.format_exc(exc))
                if tries >= max_tries:
                    sys.exit("failed %d times to fetch %s" % (max_tries, url))
                else:
                    logger.info("failed to fetch\n\t%s\nwill try "
                                "%d more times" % (url, max_tries - tries))
                    tries += 1
                    time.sleep(2 ** tries)
1002789
function queryFunction(query) {
    var term = query.term;
    var offset = query.offset || 0;
    var results = cities.filter(function(city) {
        return transformText(city).indexOf(transformText(term)) > -1;
    });
    results.sort(function(a, b) {
        a = transformText(a);
        b = transformText(b);
        var startA = (a.slice(0, term.length) === term),
            startB = (b.slice(0, term.length) === term);
        if (startA) {
            return (startB ? (a > b ? 1 : -1) : -1);
        } else {
            return (startB ? 1 : (a > b ? 1 : -1));
        }
    });
    setTimeout(query.callback({
        more: results.length > offset + 10,
        results: results.slice(offset, offset + 10)
    }), 500);
}
657409
function crawlLinks(result, $, endCallback) {

    if (! result.links){
        return endCallback();
    }

    log.debug({"url" : result.url, "step" : "analyzeHTML", "message" : "CrawlLinks"});

    async.each($('link'), function(linkTag, callback) {
        crawLink($, result, linkTag, callback);
    }, endCallback);
}
1283920
function replaceCharacter(search, replace, subject, count) {
  var i = 0, j = 0, temp = '', repl = '', sl = 0,
    fl = 0, f = [].concat(search), r = [].concat(replace),
    s = subject, ra = Object.prototype.toString.call(r) === '[object Array]',
    sa = Object.prototype.toString.call(s) === '[object Array]', s = [].concat(s);
  
  if(typeof(search) === 'object' && typeof(replace) === 'string' ) {
    temp = replace; 
    replace = new Array();
    for (i=0; i < search.length; i+=1) { 
      replace[i] = temp; 
    }
    temp = ''; 
    r = [].concat(replace); 
    ra = Object.prototype.toString.call(r) === '[object Array]';
  }
  
  if (count) {
    this.window[count] = 0;
  }

  for (i = 0, sl = s.length; i < sl; i++) {
    if (s[i] === '') {
      continue;
    }
    for (j = 0, fl = f.length; j < fl; j++) {
      temp = s[i] + '';
      repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
      s[i] = (temp)
        .split(f[j])
        .join(repl);
      if (count) {
        this.window[count] += ((temp.split(f[j])).length - 1);
      } 
    }
  }
  return sa ? s : s[0];
}
863715
function (quoteSmart) {
            var self = this, start, ch, ret, cursor = self.cursor, page = self.page;
            start = cursor.position;
            ch = page.getChar(cursor);
            switch (ch) {
            case -1:
                ret = null;
                break;
            case '<':
                ch = page.getChar(cursor);
                if (ch === -1) {
                    ret = self.makeString(start, cursor.position);
                } else if (ch === '/' || Utils.isLetter(ch)) {
                    page.ungetChar(cursor);
                    ret = self.parseTag(start);
                } else if ('!' === ch || '?' === ch) {
                    ch = page.getChar(cursor);
                    if (ch === -1) {
                        ret = self.makeString(start, cursor.position);
                    } else {
                        if ('>' === ch) {
                            ret = self.makeComment(start, cursor.position);
                        } else {
                            page.ungetChar(cursor);    // remark/tag need this char
                            // remark/tag need this char
                            if ('-' === ch) {
                                ret = self.parseComment(start, quoteSmart);
                            } else {
                                // <!DOCTYPE html>
                                // <?xml:namespace>
                                page.ungetChar(cursor);    // tag needs prior one too
                                // tag needs prior one too
                                ret = self.parseTag(start);
                            }
                        }
                    }
                } else {
                    page.ungetChar(cursor);    // see bug #1547354 <<tag> parsed as text
                    // see bug #1547354 <<tag> parsed as text
                    ret = self.parseString(start, quoteSmart);
                }
                break;
            default:
                page.ungetChar(cursor);    // string needs to see leading fore slash
                // string needs to see leading fore slash
                ret = self.parseString(start, quoteSmart);
                break;
            }
            return ret;
        }
1358970
def add_regex_start_end(pattern_function):
    """"""

    @wraps(pattern_function)
    def func_wrapper(*args, **kwargs):
        return r'^{}$'.format(pattern_function(*args, **kwargs))
    return func_wrapper
292708
function getScrapersResults (SCRAPERS, urls, htmls) {
  return Promise.all(
    SCRAPERS.map(SCRAPER => {
      return getScraperResults(SCRAPER, urls, htmls).then(results => {
        return {
          name: SCRAPER.name,
          results: results
        }
      })
    })
  )
}
58851
function startSearch() {
  iface.question('Enter search: ', function (query) {
    // Get the results of our query
    var matches = fileFinder.query(query),
        len = matches.length;

    // If no results were found
    if (len === 0) {
      console.log('No results found for: ' + query);
      startSearch();
    } else if (len === 1) {
      var item = matches[0];
    // If there is one, skip to go
      console.log('Opening: ' + item);
      fileFinder.open(item);

      // Begin the search again
      startSearch();
    } else {
    // Otherwise, list options
      console.log('');
      console.log('----------------');
      console.log('Search Results');
      console.log('----------------');
      for (i = 0; i < len; i++) {
        console.log(i + ': ' + matches[i]);
      }

      // Ask for a number
      iface.question('Which item would you like to open? ', function (numStr) {
        var num = +numStr,
            item;

        // If the number is not NaN and we were not given an empty string
        if (num === num && numStr !== '') {
          // and if it is in our result set
          if (num >= 0 && num < len) {
            // Open it
            item = matches[num];
            console.log('Opening: ' + item);
            fileFinder.open(item);
          }
        } else {
        // Otherwise, if there was a word in there so we are assuming it was 'rescan'
          // Rescan
          console.log('Rescanning...');
          fileFinder.scan();
        }

        // Begin the search again
        startSearch();
      });
    }
  });
}
871490
function lexPhrase(req, res) {
        var now    = elapse.start();
        var body   = req ? req.body : null;
        var phrase = typeof(body) === 'object' ? body.phrase : null;
        if (!phrase) {
            return res.jsonp(412, {"code":412, "message": meta.module + '|lex|EXCEPTION|invalid request body: ' + (body === null ? 'body is null' : 'phrase is null')});
        }
        body.words = api.lex(phrase);
        body.elapsedMs = elapse.stop(now).elapsed;
        res.jsonp(body);
    }
675333
function useQueries(createHistory) {
  return function () {
    var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];

    var history = createHistory(options);

    var stringifyQuery = options.stringifyQuery;
    var parseQueryString = options.parseQueryString;

    if (typeof stringifyQuery !== 'function') stringifyQuery = defaultStringifyQuery;

    if (typeof parseQueryString !== 'function') parseQueryString = defaultParseQueryString;

    function addQuery(location) {
      if (location.query == null) {
        var search = location.search;

        location.query = parseQueryString(search.substring(1));
        location[SEARCH_BASE_KEY] = { search: search, searchBase: '' };
      }

      // TODO: Instead of all the book-keeping here, this should just strip the
      // stringified query from the search.

      return location;
    }

    function appendQuery(location, query) {
      var _extends2;

      var searchBaseSpec = location[SEARCH_BASE_KEY];
      var queryString = query ? stringifyQuery(query) : '';
      if (!searchBaseSpec && !queryString) {
        return location;
      }

       false ? _warning2['default'](stringifyQuery !== defaultStringifyQuery || !isNestedObject(query), 'useQueries does not stringify nested query objects by default; ' + 'use a custom stringifyQuery function') : undefined;

      if (typeof location === 'string') location = _PathUtils.parsePath(location);

      var searchBase = undefined;
      if (searchBaseSpec && location.search === searchBaseSpec.search) {
        searchBase = searchBaseSpec.searchBase;
      } else {
        searchBase = location.search || '';
      }

      var search = searchBase;
      if (queryString) {
        search += (search ? '&' : '?') + queryString;
      }

      return _extends({}, location, (_extends2 = {
        search: search
      }, _extends2[SEARCH_BASE_KEY] = { search: search, searchBase: searchBase }, _extends2));
    }

    // Override all read methods with query-aware versions.
    function listenBefore(hook) {
      return history.listenBefore(function (location, callback) {
        _runTransitionHook2['default'](hook, addQuery(location), callback);
      });
    }

    function listen(listener) {
      return history.listen(function (location) {
        listener(addQuery(location));
      });
    }

    // Override all write methods with query-aware versions.
    function push(location) {
      history.push(appendQuery(location, location.query));
    }

    function replace(location) {
      history.replace(appendQuery(location, location.query));
    }

    function createPath(location, query) {
       false ? _warning2['default'](!query, 'the query argument to createPath is deprecated; use a location descriptor instead') : undefined;

      return history.createPath(appendQuery(location, query || location.query));
    }

    function createHref(location, query) {
       false ? _warning2['default'](!query, 'the query argument to createHref is deprecated; use a location descriptor instead') : undefined;

      return history.createHref(appendQuery(location, query || location.query));
    }

    function createLocation(location) {
      for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
        args[_key - 1] = arguments[_key];
      }

      var fullLocation = history.createLocation.apply(history, [appendQuery(location, location.query)].concat(args));
      if (location.query) {
        fullLocation.query = location.query;
      }
      return addQuery(fullLocation);
    }

    // deprecated
    function pushState(state, path, query) {
      if (typeof path === 'string') path = _PathUtils.parsePath(path);

      push(_extends({ state: state }, path, { query: query }));
    }

    // deprecated
    function replaceState(state, path, query) {
      if (typeof path === 'string') path = _PathUtils.parsePath(path);

      replace(_extends({ state: state }, path, { query: query }));
    }

    return _extends({}, history, {
      listenBefore: listenBefore,
      listen: listen,
      push: push,
      replace: replace,
      createPath: createPath,
      createHref: createHref,
      createLocation: createLocation,

      pushState: _deprecate2['default'](pushState, 'pushState is deprecated; use push instead'),
      replaceState: _deprecate2['default'](replaceState, 'replaceState is deprecated; use replace instead')
    });
  };
}
209010
static function snippet($text, $keywords, $limit, $max_length, $around = array('<b>', '</b>'))
	{
		$result = array();

		$keywords = self::normalize($keywords);
		list($pre, $post) = $around;
		$prev = array();
		$after = false;

		foreach(self::normalize_hash($text) as $word_orig => $word_norm)
		{
			$is_kw = false;
			if(in_array($word_norm, $keywords))
			{
				$prev[] = $pre.$word_orig.$post;
				$is_kw = true;
			}
			else
				$prev[] = $word_orig;

			if($is_kw)
			{
				if($after)
				{
					$result = array_merge($result, $prev);
					$prev = array();
				}
				else
				{
					$result = array_merge($result, count($prev) > $limit ? array('&#133') : array(), array_slice($prev, -$limit-1));
					$prev = array();
				}

				$after = true;
			}
			else
			{
				if($after && count($prev) >= $limit)
				{
					$after = false;
					$result = array_merge($result, $prev);
					$prev = array();
				}
			}
		}

		if($after)
			$result = array_merge($result, array('&#133'), $prev);

		return strip_text(join(' ', $result).'&#133;', $max_length);
	}
1073883
function scrape(iterator, data, params, cb) {
    var $ = artoo.$,
        scraped = [],
        loneSelector = !!data.attr || !!data.method || data.scrape ||
                       typeof data === 'string' ||
                       typeof data === 'function';

    params = params || {};

    // Transforming to selector
    var $iterator;
    if (typeof iterator === 'function')
      $iterator = $(iterator($));
    else
      $iterator = $(iterator);

    // Iteration
    $iterator.each(function(i) {
      var item = {},
          p;

      // TODO: figure iteration scope elsewhere for scrape recursivity
      if (loneSelector)
        item = (typeof data === 'object' && 'scrape' in data) ?
          scrape(
            (data.sel ? $(this).find(data.sel) : $(this))
              .find(data.scrape.iterator),
            data.scrape.data,
            data.scrape.params
          ) :
          step(data, this);
      else
        for (p in data) {
          item[p] = (typeof data[p] === 'object' && 'scrape' in data[p]) ?
            scrape(
              (data[p].sel ? $(this).find(data[p].sel) : $(this))
                .find(data[p].scrape.iterator),
              data[p].scrape.data,
              data[p].scrape.params
            ) :
            step(data[p], this);
        }

      scraped.push(item);

      // Breaking if limit i attained
      return !params.limit || i < params.limit - 1;
    });

    scraped = params.one ? scraped[0] : scraped;

    // Triggering callback
    if (typeof cb === 'function')
      cb(scraped);

    // Returning data
    return scraped;
  }