\TransvisionSearch

Search class

Allows searching for data in our repositories using a fluent interface. Currently, only the regex part (definition of the search) and defining the search options are implemented. e.g.: $search = (new Search) ->setSearchTerms('Bookmark this page') ->setRegexCaseInsensitive(true) ->setRegexEntireString(false) ->setEachWord(false) ->setEntireWords(false) ->setRepository('gecko_strings') ->setSearchType('strings') ->setLocales(['en-US', 'fr']);

Summary

Methods
Properties
Constants
__construct()
setSearchTerms()
setRegexSearchTerms()
setRegexCaseInsensitive()
setRegexEntireString()
setRegexEntireWords()
setEachWord()
getRegex()
isEntireString()
isEachWord()
isEntireWords()
isCaseSensitive()
getSearchTerms()
getRegexSearchTerms()
grep()
setRepository()
getRepository()
setSearchType()
getSearchType()
getSearchTypes()
getFormSearchOptions()
getFormCheckboxes()
setLocales()
getLocale()
No public properties found
No constants found
No protected methods found
$search_terms
$regex
$regex_case
$regex_entire_string
$regex_entire_words
$each_word
$regex_search_terms
$repository
$search_type
$search_types
$form_search_options
$form_checkboxes
$locales
N/A
updateRegex()
No private properties found
N/A

Properties

$search_terms

$search_terms : string

The trimmed string searched, we keep it as the canonical reference

Type

string

$regex

$regex : string

The generated regex string updated dynamically via updateRegex()

Type

string

$regex_case

$regex_case : string

Case sensibility of the regex

Type

string

$regex_entire_string

$regex_entire_string : boolean

Only return strings that entirely match the search (case excluded)

Type

boolean

$regex_entire_words

$regex_entire_words : boolean

Only return strings where entire words match the search (case excluded)

Type

boolean

$each_word

$each_word : boolean

Set to search for each word in the query instead of using it as a whole.

Type

boolean

$regex_search_terms

$regex_search_terms : string

The search terms for the regex, these differ from $search_terms as they can be changed dynamically via setRegexSearchTerms()

Type

string

$repository

$repository : string

The repository we want to search strings in

Type

string

$search_type

$search_type : string

The type of search we will perform

Type

string

$search_types

$search_types : array

The different types of search we can perform

Type

array

$form_search_options

$form_search_options : array

The different options associated to searches

Type

array

$form_checkboxes

$form_checkboxes : array

The different checkboxes for the search Form

Type

array

$locales

$locales : array

The different locales we will use in views

Type

array

Methods

__construct()

__construct() 

We set the default values for a search

setSearchTerms()

setSearchTerms(string  $string) : $this

Store the searched string in $search_terms and in $regex_search_terms

Parameters

string $string

String we want to search for

Returns

$this

setRegexSearchTerms()

setRegexSearchTerms(string  $string) : $this

Allows setting a new searched term for the regex.

This is mostly useful when you have a multi-words search and need to loop through all the words to return results.

Parameters

string $string

The string we want to update the regex for

Returns

$this

setRegexCaseInsensitive()

setRegexCaseInsensitive(boolean  $flag) : $this

Set the regex case to be insensitive.

Parameters

boolean $flag

True is sensitive, false insensitive

Returns

$this

setRegexEntireString()

setRegexEntireString(boolean  $flag) : $this

Set the regex to only return strings that entirely match the searched string.

We cast the value to a boolean because we usually get it from a GET.

Parameters

boolean $flag

Set to True for an entire string match

Returns

$this

setRegexEntireWords()

setRegexEntireWords(boolean  $flag) : $this

Set the regex to only return strings where entire words match the searched string.

We cast the value to a boolean because we usually get it from a GET.

Parameters

boolean $flag

Set to True for an entire words match

Returns

$this

setEachWord()

setEachWord(boolean  $flag) : $this

Set to search for each word in the query instead of using it as a whole.

We cast the value to a boolean because we usually get it from a GET.

Parameters

boolean $flag

Set to True to search for each word.

Returns

$this

getRegex()

getRegex() : string

Get the regex string

Returns

string —

The regex

isEntireString()

isEntireString() : boolean

Get the state of regex_entire_string

Returns

boolean —

True if the regex searches for an entire string match

isEachWord()

isEachWord() : boolean

Get the state of each_word

Returns

boolean —

True if the search should be for each word.

isEntireWords()

isEntireWords() : boolean

Get the state of entire_words

Returns

boolean —

True if the search should be only for entire word.

isCaseSensitive()

isCaseSensitive() : boolean

Get the state of case_sensitive

Returns

boolean —

False if the search should be case sensitive

getSearchTerms()

getSearchTerms() : string

Get search terms

Returns

string —

Searched terms

getRegexSearchTerms()

getRegexSearchTerms() : string

Get search terms in regex

Returns

string —

Searched terms in regex

grep()

grep(array  $source_strings) : array

Grep data in regex

Parameters

array $source_strings

The array of strings to be filtered

Returns

array —

Return an array of filtered strings

setRepository()

setRepository(string  $repository) : $this

Set the repository we want to search strings in

Parameters

string $repository

The name of the repository

Returns

$this

getRepository()

getRepository() : string

Get the repository we are searching strings in

Returns

string —

Name of the repository

setSearchType()

setSearchType(string  $type) : $this

Set the type of search we want to perform

Parameters

string $type

The type of search we will perform

Returns

$this

getSearchType()

getSearchType() : string

Get the type of search we want to perform

Returns

string —

Type of search

getSearchTypes()

getSearchTypes() : array

Get all the types of search we can perform

Returns

array —

Types of search

getFormSearchOptions()

getFormSearchOptions() : array

Get all the options we use in the search form

Returns

array —

Form options

getFormCheckboxes()

getFormCheckboxes() : array

Get all the checkboxes we use in the search form

Returns

array —

Form checkboxes

setLocales()

setLocales(array  $locales) : $this

Set the locales we will use for the search with this structure: $this->locales = [ 'source' => 'en-US', 'target' => 'de', 'extra' => 'ar', ];

The 'extra' value is optional and used in views comparing data for 3 locales.

Parameters

array $locales

The locale codes

Returns

$this

getLocale()

getLocale(string  $type) : string

Get a locale used for searching

Parameters

string $type

The type of locale we want, can be 'source', 'target' or 'extra'.

Returns

string —

Locale code or an empty string

updateRegex()

updateRegex() : $this

Update the $regex_search_terms value every time a setter to the regex is called.

Returns

$this