Finds alternative of $name among $collection,
if nothing is found in $collection, try in $abbrevs.

@param string $search
@param array $list
@return string[] A sorted array of similar string
760772
private function findAlternatives($search, $list)
    {
        $threshold = 1e3;
        $alternatives = [];

        $collectionParts = [];
        foreach ($list as $name => $item) {
            $collectionParts[$name] = explode(':', $name);
        }

        foreach (explode(':', $search) as $i => $subname) {
            foreach ($collectionParts as $name => $parts) {
                $exists = isset($alternatives[$name]);
                if (!isset($parts[$i])) {
                    if ($exists) {
                        $alternatives[$name] += $threshold;
                    }
                    continue;
                }
                $lev = levenshtein($subname, $parts[$i]);
                if ($lev <= strlen($subname) / 3 || $subname !== '' && strpos($parts[$i], $subname) !== false) {
                    $alternatives[$name] = $exists ? $alternatives[$name] + $lev : $lev;
                }
                else if ($exists) {
                    $alternatives[$name] += $threshold;
                }
            }
        }

        foreach ($list as $name => $item) {
            $lev = levenshtein($search, $name);
            if ($lev <= strlen($search) / 3 || strpos($name, $search) !== false) {
                $alternatives[$name] = isset($alternatives[$name]) ? $alternatives[$name] - $lev : $lev;
            }
        }

        $alternatives = array_filter($alternatives, function ($lev) use ($threshold) {
            return $lev < 2 * $threshold;
        });

        ksort($alternatives);

        return array_keys($alternatives);
    }
681459
protected function fileInfoSearch($filename, $search)
    {
        $output = [];
        exec('file ' . '"' . $filename . '"', $output, $returnVar);
        if ($returnVar === 0 && !empty($output[0]) && strpos($output[0], $search) !== false) {
            return true;
        }
        return false;
    }
22509
public function search(string $search, $properties = null, array $options = null)
    {
        $matching = $this->call('search', [$search, $properties, $options]);
        $matching = array_filter($matching);

        if ($matching) {
            uksort($matching, function ($a, $b) {
                return -($a <=> $b);
            });
        }

        return $this->select(array_keys($matching));
    }
309326
private function getPropertyFilters($search = '')
    {
        $propertyFilters = [];

        if(is_string($search) && strlen(trim($search)) > 0){
            $propertyFilters[self::LABEL_URI] = $search;
        }
        if(is_array($search)){
            foreach($search as $uri => $value){
                if( is_string($uri) &&
                    (is_string($value) && strlen(trim($value)) > 0) ||
                    (is_array($value) && count($value) > 0) ) {
                    $propertyFilters[$uri] = $value;
                }
            }
        }
        return $propertyFilters;
    }
470861
protected function _getSearchDataHeader(BaseSearch $search): array
    {
        $header = $search->getOptions();

        if ($search->hasIndices()) {
            $header['index'] = $search->getIndices();
        }

        if ($search->hasTypes()) {
            $header['types'] = $search->getTypes();
        }

        // Filter options accepted in the "header"
        return \array_intersect_key($header, \array_flip(self::$HEADER_OPTIONS));
    }
1368849
static  function find($list, $where) {
        if (is_array($where)) {
            foreach ($list as $item) {
                $is_ok = true;
                foreach ($where as $key => $value) {
                    if ($item[ $key ] != $value) {
                        $is_ok = false;
                        break;
                    }
                }
                if ($is_ok) {
                    return $item;
                }
            }
        } else {
            foreach ($list as $item) {
                if ($where($item)) {
                    return $item;
                }
            }
        }
        return null;
    }
394239
function searchArray(list, value) {
  var index = list.indexOf(value);

  if (index === -1) return false;
  return value;
}
786275
public static function replaceArray($search, array $replace, $subject)
    {
        foreach ($replace as $value) {
            $subject = static::replaceFirst($search, $value, $subject);
        }

        return $subject;
    }
416332
@Action(semantics = SemanticsOf.SAFE)
    public List<ApplicationTenancy> findMatching(final String search) {
        if (search != null && search.length() > 0) {
            return findByNameOrPathMatching(search);
        }
        return Lists.newArrayList();
    }
499035
public function findByNameForAjax($search)
    {
        $resultArray = [];

        $users = $this->findByName($search);

        foreach ($users as $user) {
            $resultArray[] = [
                'id' => $user->getId(),
                'text' => $user->getFirstName().' '.$user->getLastName(),
            ];
        }

        return $resultArray;
    }
1349463
public static function replace($search, $replace, $subject)
    {
        foreach ((array)$search as $item) {
            $subject = str_replace($item, $replace, $subject);
        }
        return $subject;
    }
1054070
protected function expandPatterns(array $patterns, $search, array $replacements)
    {
        if ($replacements === []) {
            return $patterns;
        }
        $patternsWithReplacements = [];
        foreach ($patterns as $pattern) {
            foreach ($replacements as $replacement) {
                $patternsWithReplacements[] = Files::getUnixStylePath(str_replace($search, $replacement, $pattern));
            }
        }

        return $patternsWithReplacements;
    }
1212908
public function searchTexts( MW_Common_Criteria_Interface $search )
	{
		$list = array();
		$context = $this->_getContext();

		$dbm = $context->getDatabaseManager();
		$dbname = $this->_getResourceName();
		$conn = $dbm->acquire( $dbname );

		try
		{
			$level = MShop_Locale_Manager_Abstract::SITE_ALL;
			$cfgPathSearch = 'mshop/catalog/manager/index/text/default/text/search';
			$required = array( 'product' );

			$total = null;
			$results = $this->_searchItems( $conn, $search, $cfgPathSearch, '', $required, $total, $level );

			while( ( $row = $results->fetch() ) !== false ) {
				$list[ $row['prodid'] ] = $row['value'];
			}

			$dbm->release( $conn, $dbname );
		}
		catch( Exception $e )
		{
			$dbm->release( $conn, $dbname );
			throw $e;
		}

		return $list;
	}
317663
public static function replaceInArray($search = '', $replace = '', $array = false, $isKeys = true)
    {
        if (!is_array($array)) {
            return str_replace($search, $replace, $array);
        }

        $newArr = array();
        foreach ($array as $key => $value) {
            $addKey = $key;
            if ($isKeys) { //Replace keys
                $addKey = str_replace($search, $replace, $key);
            }

            // Recurse
            $newArr[$addKey] = static::replaceInArray($search, $replace, $value, $isKeys);
        }

        return $newArr;
    }
553682
function (items, query) {
        if (!config.exactMatch || !config.searchField.name) {
          return items;
        }
        var list = items;
        var match = _.findIndex(list, function (item) {
          return query.toLowerCase() === item.name.toLowerCase();
        });
        if (match !== -1) {
          list.splice(0, 0, list.splice(match, 1)[0]);
        }
        return list;
      }
97075
public function findDocuments(Search $search)
    {
        $results = $this->executeSearch($search);

        return new DocumentIterator(
            $results,
            $this->getManager(),
            $this->getScrollConfiguration($results, $search->getScroll())
        );
    }
564356
public function search(string $search, $properties = null, array $options = null)
    {
        return $this->__call('search', [$search, $properties, $options]);
    }