C# Class Deveel.Data.Text.PatternSearch

This is a static class that performs the operations to do a pattern search on a given column of a table.
The pattern syntax is very simple and follows that of the SQL standard.

It works as follows: The '%' character represents any sequence of characters. The '_' character represents some character.

Therefore, the pattern search Anto% will find all rows that start with the string Anto and end with any sequence of characters. The pattern A% Proven% will find all names starting with A and containing Proven somewhere in the end. The pattern _at will find all three letter words ending with at.

Note A ab% type search is faster than a %bc type search. If the start of the search pattern is unknown then the entire contents of the column need to be accessed.

显示文件 Open project: deveel/deveeldb

Public Methods

Method Description
FullPatternMatch ( string pattern, string str, char escapeChar ) : bool

Matches a pattern against a string and returns true if it matches or false otherwise.

This matches patterns that do not necessarily start with a wild card unlike the PatternMatch method.

IsWildCard ( char ch ) : bool

Returns true if the given character is a wild card (unknown).

PatternMatch ( string pattern, string expression, char escapeChar ) : bool

This is the pattern match recurrsive method.

It recurses on each wildcard expression in the pattern which makes for slightly better efficiency than a character recurse algorithm. However, patterns such as _%_a will result in many recursive calls.

Note That _%_ will be less efficient than __% and will produce the same result.

Note It requires that a wild card character is the first character in the expression.

Issue Pattern optimiser, we should optimize wild cards of type %__ to __%, or %__%_%_% to ____%. Optimised forms are identical in result and more efficient. This optimization could be performed by the client during parsing of the LIKE statement.

Hacking Issue Badly formed wild cards may result in hogging of server side resources.

Method Details

FullPatternMatch() public static method

Matches a pattern against a string and returns true if it matches or false otherwise.
This matches patterns that do not necessarily start with a wild card unlike the PatternMatch method.
public static FullPatternMatch ( string pattern, string str, char escapeChar ) : bool
pattern string
str string
escapeChar char
return bool

IsWildCard() public static method

Returns true if the given character is a wild card (unknown).
public static IsWildCard ( char ch ) : bool
ch char
return bool

PatternMatch() public static method

This is the pattern match recurrsive method.
It recurses on each wildcard expression in the pattern which makes for slightly better efficiency than a character recurse algorithm. However, patterns such as _%_a will result in many recursive calls.

Note That _%_ will be less efficient than __% and will produce the same result.

Note It requires that a wild card character is the first character in the expression.

Issue Pattern optimiser, we should optimize wild cards of type %__ to __%, or %__%_%_% to ____%. Optimised forms are identical in result and more efficient. This optimization could be performed by the client during parsing of the LIKE statement.

Hacking Issue Badly formed wild cards may result in hogging of server side resources.

public static PatternMatch ( string pattern, string expression, char escapeChar ) : bool
pattern string
expression string
escapeChar char
return bool