Alphred
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  • Download

Namespaces

  • Alphred
  • None

Classes

  • Alfred
  • AppleScript
  • Choose
  • Config
  • Date
  • Dialog
  • Filter
  • Globals
  • i18n
  • Ini
  • Keychain
  • Log
  • Notification
  • Request
  • Result
  • ScriptFilter
  • Text

Interfaces

  • ConfigKeyNotSet
  • Exception
  • FileDoesNotExist
  • InvalidKeychainAccount
  • InvalidScriptFilterArgument
  • InvalidSecurityAction
  • InvalidXMLProperty
  • PasswordExists
  • PasswordNotFound
  • PluginFunctionNotFound
  • RunningOutsideOfAlfred
  • ShouldBeBool
  • TooManyArguments
  • UnknownSecurityException
  • UseOnlyAsStatic

Class Filter

Filters arrays to match a query

Namespace: Alphred
Located at Filter.php

Methods summary

public array
# Filter( array $haystack, string $needle, string|boolean $key = false, array $options = [] )

Filters an array based on a query

Filters an array based on a query

Passing an empty query ($needle) to this method will simply return the initial array. If you have fold on, then this will fail on characters that cannot be translitered into regular ASCII, so most Asian languages.

The options to be set are: * max_results -- the maximum number of results to return (default: false) * min_score -- the minimum score to return (0-100) (default: false) * return_score -- whether or not to return the score along with the results (default: false) * fold -- whether or not to fold diacritical marks, thus making über into uber. (default: true) * match_type -- the type of filters to run. (default: MATCH_ALL) The match_type is defined as constants, and so you can call them by the flags or by the integer value. Options: Match items that start with the query 1: MATCH_STARTSWITH Match items whose capital letters start with query 2: MATCH_CAPITALS Match items with a component "word" that matches query 4: MATCH_ATOM Match items whose initials (based on atoms) start with query 8: MATCH_INITIALS_STARTSWITH Match items whose initials (based on atoms) contain query 16: MATCH_INITIALS_CONTAIN Combination of MATCH_INITIALS_STARTSWITH and MATCH_INITIALS_CONTAIN 24: MATCH_INITIALS Match items if query is a substring 32: MATCH_SUBSTRING Match items if all characters in query appear in the item in order 64: MATCH_ALLCHARS Combination of all other MATCH_* constants 127: MATCH_ALL

Parameters

$haystack
the array of items to filter
$needle
the search query to filter against
$key
the name of the key to filter on if array is associative
$options
a list of options to configure the filter

Returns

array
an array of filtered items
public boolean
# sort_by_score( array $a, array $b )

Callback function to help sort the results array

Callback function to help sort the results array

Parameters

$a
an array
$b
an array

Returns

boolean

Internal

I made this public because there was an error using filter() through the wrapper. This is a temporary measure and should be remedied.


private string
# remove_all_non_caps( string $string )

Removes all non-capital characters and non-digit characters frmo a string

Removes all non-capital characters and non-digit characters frmo a string

Parameters

$string
a string to process

Returns

string
the processed string
private string
# convert( string $string )

Converts and transliterates a string to ascii

Converts and transliterates a string to ascii

Parameters

$string
a string to transliterate

Returns

string
the transliterated string
private array
# filter_item( string $value, string $query, mixed $match_on, boolean $fold_diacritics )

Runs the filter rules

Runs the filter rules

Parameters

$value
the value string (haystack)
$query
the query string (needle)
$match_on
the search flags, so constants or integers
$fold_diacritics
whether or not to transliterate to ascii

Returns

array
an array that is score and then the rule matched

Todo

Refactor this

Magic methods summary

Alphred API documentation generated by ApiGen